modify game loop
This commit is contained in:
parent
8e6527afa0
commit
2a38a68285
4 changed files with 29 additions and 14 deletions
|
@ -1,9 +1,11 @@
|
||||||
package com.monjaro.gamejam;
|
package com.monjaro.gamejam;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
public abstract class Actor {
|
public abstract class Actor {
|
||||||
|
|
||||||
public abstract void tick();
|
public abstract void tick();
|
||||||
|
|
||||||
public abstract void render();
|
public abstract void render(SpriteBatch batch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.monjaro.gamejam;
|
|
||||||
|
|
||||||
public class Dice {
|
|
||||||
static Texture faces;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.monjaro.gamejam;
|
package com.monjaro.gamejam;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
public class Die extends Actor {
|
public class Die extends Actor {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,7 +24,7 @@ public class Die extends Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render(SpriteBatch batch) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,21 @@ import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
|
import jdk.vm.ci.hotspot.JFR;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class Game extends ApplicationAdapter {
|
public class Game extends ApplicationAdapter {
|
||||||
|
|
||||||
|
private final Set<Actor> actors = new HashSet<>();
|
||||||
|
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
private Texture img;
|
private Texture img;
|
||||||
|
|
||||||
private static int TICKS_PER_SECOND;
|
private final static int TICKS_PER_SECOND = 60;
|
||||||
private double tickProgress = 0;
|
private double tickProgress = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,20 +29,22 @@ public class Game extends ApplicationAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
actors.forEach(Actor::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
Gdx.graphics.getDeltaTime();
|
tickProgress += Gdx.graphics.getDeltaTime() / TICKS_PER_SECOND;
|
||||||
while (tickProgress >= 1) { //tick as many times as needed
|
while (tickProgress >= 1) { //tick as many times as needed
|
||||||
tick();
|
tick();
|
||||||
tickProgress--;
|
tickProgress--;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenUtils.clear(1, 0, 0, 1);
|
ScreenUtils.clear(0, 0, 0, 1);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
batch.draw(img, 0, 0);
|
|
||||||
|
actors.forEach(a -> a.render(batch));
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,4 +54,12 @@ public class Game extends ApplicationAdapter {
|
||||||
img.dispose();
|
img.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addActor(Actor actor) {
|
||||||
|
actors.add(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeActor(Actor actor) {
|
||||||
|
actors.remove(actor);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue