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;
import com.badlogic.gdx.math.Shape2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public abstract class Actor {
public abstract void tick();
public abstract void render();
public abstract void render(SpriteBatch batch);
}

View file

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

View file

@ -1,26 +1,33 @@
package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Face extends Actor{
private Rectangle shape;
private int pips;
private final List<Pip> pips = new ArrayList<>();
public Face(int pips) {
this.pips = pips;
public Face(int pipCount) {
//ro adds pips here
}
public int getPips() {
return pips;
public int getValue() {
return pips.size();
}
public void setPips(int pips) {
this.pips = pips;
public List<Pip> getPips() {
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;
@ -54,7 +61,7 @@ public class Face extends Actor{
}
@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.g2d.SpriteBatch;
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 {
private final Set<Actor> actors = new HashSet<>();
private SpriteBatch batch;
private Texture img;
private static int TICKS_PER_SECOND;
private final static int TICKS_PER_SECOND = 60;
private double tickProgress = 0;
@Override
@ -21,20 +29,22 @@ public class Game extends ApplicationAdapter {
}
public void tick() {
actors.forEach(Actor::tick);
}
@Override
public void render() {
Gdx.graphics.getDeltaTime();
tickProgress += Gdx.graphics.getDeltaTime() / TICKS_PER_SECOND;
while (tickProgress >= 1) { //tick as many times as needed
tick();
tickProgress--;
}
ScreenUtils.clear(1, 0, 0, 1);
ScreenUtils.clear(0, 0, 0, 1);
batch.begin();
batch.draw(img, 0, 0);
actors.forEach(a -> a.render(batch));
batch.end();
}
@ -44,4 +54,12 @@ public class Game extends ApplicationAdapter {
img.dispose();
}
private void addActor(Actor actor) {
actors.add(actor);
}
private void removeActor(Actor actor) {
actors.remove(actor);
}
}