This commit is contained in:
Rosia E Evans 2024-04-20 16:16:41 +01:00
commit d06da44e56
3 changed files with 33 additions and 5 deletions

View file

@ -60,4 +60,12 @@ public class Die extends Actor {
} }
} }
public Face getFace() {
return faces[faceIndex];
}
public int getFaceValue() {
return getFace().getValue();
}
} }

View file

@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Vector2;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Vector;
public class Face extends Actor{ public class Face extends Actor{
@ -26,7 +26,7 @@ public class Face extends Actor{
private void addPipsForValue(int value){ private void addPipsForValue(int value){
int[][] positions = {{25, 25}, {75, 75}, {25, 75}, {75, 25}, {25, 50}, {75, 50}}; int[][] positions = {{25, 25}, {75, 75}, {25, 75}, {75, 25}, {25, 50}, {75, 50}};
if (value%2 == 0) { if (value % 2 == 1) {
pips.add(new Pip(50, 50)); pips.add(new Pip(50, 50));
value--; value--;
} }
@ -89,6 +89,8 @@ public class Face extends Actor{
{ {
Vector2 position = new Vector2(shape.x + (shape.width*percentages.x/100f) + (float)pipSprite.getWidth()/2, Vector2 position = new Vector2(shape.x + (shape.width*percentages.x/100f) + (float)pipSprite.getWidth()/2,
shape.y + shape.width*percentages.y/100f + (float)pipSprite.getHeight()/2); shape.y + shape.width*percentages.y/100f + (float)pipSprite.getHeight()/2);
return position;
} }
@Override @Override

View file

@ -2,10 +2,11 @@ package com.monjaro.gamejam;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
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.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -16,26 +17,35 @@ public class Game extends ApplicationAdapter {
private final Set<Actor> actors = new HashSet<>(); private final Set<Actor> actors = new HashSet<>();
private final List<Die> dice = new ArrayList<>();
private SpriteBatch batch; private SpriteBatch batch;
private BitmapFont font;
private Texture img; private Texture img;
private final static int TICKS_PER_SECOND = 60; private final static int TICKS_PER_SECOND = 60;
private double tickProgress = 0; private double tickProgress = 0;
@Override @Override
public void create() { public void create() {
batch = new SpriteBatch(); batch = new SpriteBatch();
font = new BitmapFont();
img = new Texture("badlogic.jpg"); img = new Texture("badlogic.jpg");
for (int i = 0; i < 5; i++) {
dice.add(new Die());
}
} }
public void tick() { public void tick() {
actors.forEach(Actor::tick); actors.forEach(Actor::tick);
dice.forEach(Die::roll);
} }
@Override @Override
public void render() { public void render() {
tickProgress += Gdx.graphics.getDeltaTime() / TICKS_PER_SECOND; 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--;
@ -46,6 +56,14 @@ public class Game extends ApplicationAdapter {
actors.forEach(a -> a.render(batch)); actors.forEach(a -> a.render(batch));
//TODO debug
int x = 100;
for (Die die : dice) {
batch.setColor(Color.WHITE);
font.draw(batch, String.valueOf(die.getFaceValue()), x += 50, 100);
}
//-----
batch.end(); batch.end();
} }