This commit is contained in:
Rosia E Evans 2024-04-20 15:07:13 +01:00
commit beb88e80be
4 changed files with 48 additions and 21 deletions

View file

@ -1,10 +1,11 @@
package com.monjaro.gamejam; package com.monjaro.gamejam;
import com.badlogic.gdx.math.Shape2D;
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);
} }

View file

@ -1,6 +1,8 @@
package com.monjaro.gamejam; package com.monjaro.gamejam;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Die extends Actor { public class Die extends Actor {
@ -35,10 +37,9 @@ public class Die extends Actor {
} }
@Override @Override
public void render() { public void render(SpriteBatch batch) {
for (Face face : faces){ for (Face face : faces) {
face.render(); face.render(batch);
} }
} }
} }

View file

@ -1,26 +1,33 @@
package com.monjaro.gamejam; package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Face extends Actor{ public class Face extends Actor{
private Rectangle shape; private Rectangle shape;
private int pips; private final List<Pip> pips = new ArrayList<>();
public Face(int pips) { public Face(int pipCount) {
this.pips = pips; //ro adds pips here
} }
public int getPips() { public int getValue() {
return pips; return pips.size();
} }
public void setPips(int pips) { public List<Pip> getPips() {
this.pips = pips; return Collections.unmodifiableList(pips);
} }
private static class Pip { public void removePip(Pip pip) {
pips.remove(pip);
}
public static class Pip {
private final double x, y; private final double x, y;
@ -54,7 +61,7 @@ public class Face extends Actor{
} }
@Override @Override
public void render() { public void render(SpriteBatch batch) {
} }

View file

@ -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);
}
} }