2024-04-20 12:58:06 +01:00
|
|
|
package com.monjaro.gamejam;
|
|
|
|
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
2024-04-20 14:40:06 +01:00
|
|
|
import com.badlogic.gdx.Gdx;
|
2024-04-20 15:45:42 +01:00
|
|
|
import com.badlogic.gdx.graphics.Color;
|
2024-04-20 12:58:06 +01:00
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
2024-04-20 15:45:42 +01:00
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
2024-04-20 12:58:06 +01:00
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
|
|
import com.badlogic.gdx.utils.ScreenUtils;
|
2024-04-20 14:56:13 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
2024-04-20 12:58:06 +01:00
|
|
|
|
|
|
|
public class Game extends ApplicationAdapter {
|
2024-04-20 14:40:06 +01:00
|
|
|
|
2024-04-20 14:56:13 +01:00
|
|
|
private final Set<Actor> actors = new HashSet<>();
|
|
|
|
|
2024-04-20 15:45:42 +01:00
|
|
|
private final List<Die> dice = new ArrayList<>();
|
|
|
|
|
2024-04-20 14:40:06 +01:00
|
|
|
private SpriteBatch batch;
|
2024-04-20 15:45:42 +01:00
|
|
|
private BitmapFont font;
|
2024-04-20 14:40:06 +01:00
|
|
|
private Texture img;
|
|
|
|
|
2024-04-20 14:56:13 +01:00
|
|
|
private final static int TICKS_PER_SECOND = 60;
|
2024-04-20 14:40:06 +01:00
|
|
|
private double tickProgress = 0;
|
|
|
|
|
2024-04-20 12:58:06 +01:00
|
|
|
@Override
|
2024-04-20 14:40:06 +01:00
|
|
|
public void create() {
|
2024-04-20 12:58:06 +01:00
|
|
|
batch = new SpriteBatch();
|
2024-04-20 15:45:42 +01:00
|
|
|
font = new BitmapFont();
|
2024-04-20 12:58:06 +01:00
|
|
|
img = new Texture("badlogic.jpg");
|
2024-04-20 15:45:42 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
dice.add(new Die());
|
|
|
|
}
|
2024-04-20 12:58:06 +01:00
|
|
|
}
|
|
|
|
|
2024-04-20 14:40:06 +01:00
|
|
|
public void tick() {
|
2024-04-20 14:56:13 +01:00
|
|
|
actors.forEach(Actor::tick);
|
2024-04-20 16:01:31 +01:00
|
|
|
|
|
|
|
dice.forEach(Die::roll);
|
2024-04-20 14:40:06 +01:00
|
|
|
}
|
|
|
|
|
2024-04-20 12:58:06 +01:00
|
|
|
@Override
|
2024-04-20 14:40:06 +01:00
|
|
|
public void render() {
|
2024-04-20 16:01:31 +01:00
|
|
|
tickProgress += Gdx.graphics.getDeltaTime() * TICKS_PER_SECOND;
|
2024-04-20 14:40:06 +01:00
|
|
|
while (tickProgress >= 1) { //tick as many times as needed
|
|
|
|
tick();
|
|
|
|
tickProgress--;
|
|
|
|
}
|
|
|
|
|
2024-04-20 14:56:13 +01:00
|
|
|
ScreenUtils.clear(0, 0, 0, 1);
|
2024-04-20 12:58:06 +01:00
|
|
|
batch.begin();
|
2024-04-20 14:56:13 +01:00
|
|
|
|
|
|
|
actors.forEach(a -> a.render(batch));
|
|
|
|
|
2024-04-20 15:45:42 +01:00
|
|
|
//TODO debug
|
|
|
|
int x = 100;
|
|
|
|
for (Die die : dice) {
|
|
|
|
batch.setColor(Color.WHITE);
|
|
|
|
font.draw(batch, String.valueOf(die.getFaceValue()), x += 50, 100);
|
|
|
|
}
|
|
|
|
//-----
|
|
|
|
|
2024-04-20 12:58:06 +01:00
|
|
|
batch.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-04-20 14:40:06 +01:00
|
|
|
public void dispose() {
|
2024-04-20 12:58:06 +01:00
|
|
|
batch.dispose();
|
|
|
|
img.dispose();
|
|
|
|
}
|
2024-04-20 14:40:06 +01:00
|
|
|
|
2024-04-20 14:56:13 +01:00
|
|
|
private void addActor(Actor actor) {
|
|
|
|
actors.add(actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeActor(Actor actor) {
|
|
|
|
actors.remove(actor);
|
|
|
|
}
|
|
|
|
|
2024-04-20 12:58:06 +01:00
|
|
|
}
|