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 16:15:42 +01:00
|
|
|
import com.badlogic.gdx.Input;
|
2024-04-20 12:58:06 +01:00
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
2024-04-21 00:29:18 +01:00
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
2024-04-20 12:58:06 +01:00
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
2024-04-21 00:24:27 +01:00
|
|
|
import com.badlogic.gdx.math.Vector2;
|
2024-04-20 12:58:06 +01:00
|
|
|
import com.badlogic.gdx.utils.ScreenUtils;
|
2024-04-20 20:22:57 +01:00
|
|
|
import com.monjaro.gamejam.segment.DualSegment;
|
|
|
|
import com.monjaro.gamejam.segment.KinSegment;
|
|
|
|
import com.monjaro.gamejam.segment.Segment;
|
2024-04-20 14:56:13 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2024-04-20 12:58:06 +01:00
|
|
|
|
|
|
|
public class Game extends ApplicationAdapter {
|
2024-04-20 14:40:06 +01:00
|
|
|
|
2024-04-20 15:45:42 +01:00
|
|
|
private final List<Die> dice = new ArrayList<>();
|
2024-04-20 20:22:57 +01:00
|
|
|
private final List<Segment> segments = new ArrayList<>();
|
2024-04-20 15:45:42 +01:00
|
|
|
|
2024-04-20 14:40:06 +01:00
|
|
|
private SpriteBatch batch;
|
2024-04-21 00:29:18 +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-21 00:29:18 +01:00
|
|
|
font = new BitmapFont();
|
|
|
|
font.getData().markupEnabled = true;
|
2024-04-20 12:58:06 +01:00
|
|
|
img = new Texture("badlogic.jpg");
|
2024-04-20 15:45:42 +01:00
|
|
|
|
2024-04-20 16:38:07 +01:00
|
|
|
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
|
|
|
|
Face.setPipSprite(new Texture("pip.png"));
|
2024-04-21 00:24:27 +01:00
|
|
|
Die.setLockedSprite(new Texture("locked_die_border.png"));
|
2024-04-20 16:38:07 +01:00
|
|
|
|
2024-04-21 00:24:27 +01:00
|
|
|
Vector2 dieSize = new Vector2();
|
|
|
|
float divide = Gdx.graphics.getWidth() / 6f;
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
dice.add(new Die(divide * (i + 1), 350, 64, 64));
|
2024-04-20 15:45:42 +01:00
|
|
|
}
|
2024-04-20 20:22:57 +01:00
|
|
|
|
|
|
|
for (int i = 1; i <= 5; i++) {
|
|
|
|
segments.add(new KinSegment(i));
|
|
|
|
}
|
|
|
|
segments.add(new DualSegment(false));
|
|
|
|
segments.add(new DualSegment(true));
|
2024-04-20 12:58:06 +01:00
|
|
|
}
|
|
|
|
|
2024-04-20 14:40:06 +01:00
|
|
|
public void tick() {
|
2024-04-20 16:15:42 +01:00
|
|
|
processInput();
|
|
|
|
}
|
2024-04-20 16:01:31 +01:00
|
|
|
|
2024-04-20 16:15:42 +01:00
|
|
|
public void processInput() {
|
|
|
|
Input input = Gdx.input;
|
|
|
|
|
2024-04-20 16:59:47 +01:00
|
|
|
if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked
|
|
|
|
dice.stream().filter(d -> !d.isLocked()).forEach(Die::roll);
|
2024-04-20 20:22:57 +01:00
|
|
|
|
|
|
|
System.out.println("=".repeat(100));
|
|
|
|
for (Segment segment : segments) {
|
|
|
|
System.out.println(segment.getName() + ": " + segment.isDestroyedBy(dice));
|
|
|
|
}
|
2024-04-20 16:15:42 +01:00
|
|
|
}
|
2024-04-20 16:34:16 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode
|
|
|
|
Die die = dice.get(i); //die iterator is looking at
|
|
|
|
int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard
|
|
|
|
|
|
|
|
if (input.isKeyJustPressed(keyCode)) { //if key corresponding to die has been pressed
|
|
|
|
die.setLocked(!die.isLocked()); //flip lock state
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2024-04-20 15:45:42 +01:00
|
|
|
//TODO debug
|
|
|
|
for (Die die : dice) {
|
2024-04-20 16:38:07 +01:00
|
|
|
die.render(batch);
|
2024-04-20 15:45:42 +01:00
|
|
|
}
|
2024-04-21 00:29:18 +01:00
|
|
|
|
|
|
|
int x = 50;
|
|
|
|
for (Segment segment : segments) {
|
|
|
|
String prefix = "[#9E65A8]";
|
|
|
|
if (segment.isDestroyed()) prefix = "[#EBE5EC]";
|
|
|
|
else if (segment.isDestroyedBy(dice)) prefix = "[#528154]";
|
|
|
|
|
|
|
|
font.draw(batch, prefix + segment.getName(), x += 75, Gdx.graphics.getHeight() - 100);
|
|
|
|
}
|
2024-04-20 15:45:42 +01:00
|
|
|
//-----
|
|
|
|
|
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 12:58:06 +01:00
|
|
|
}
|