Merge branch 'main' of github.com:Wil-Ro/gamejam2024

This commit is contained in:
James 2024-04-20 16:52:52 +01:00
commit 953736e7bc
4 changed files with 30 additions and 10 deletions

View file

@ -29,6 +29,17 @@ public class Die extends Actor {
shape = new Rectangle(); shape = new Rectangle();
} }
public Die(float x, float y, float width, float height) {
int[] pips = {4, 6, 5, 1, 2, 3};
for (int i = 0; i < faces.length; i++) {
faces[i] = new Face(pips[i]);
faces[i].setPosition(x, y);
faces[i].setSize(width, height);
}
shape = new Rectangle(x, y, width, height);
}
public void setPosition(float x, float y){ public void setPosition(float x, float y){
shape.setX(x); shape.setX(x);
shape.setY(y); shape.setY(y);

View file

@ -8,17 +8,19 @@ 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.Random;
public class Face extends Actor{ public class Face extends Actor{
private Rectangle shape; private Rectangle shape = new Rectangle();
private final List<Pip> pips = new ArrayList<>(); private final List<Pip> pips = new ArrayList<>();
private static Texture blankFaceSprite; private static Texture blankFaceSprite;
private static Texture pipSprite; private static Texture pipSprite;
public Face(int pipCount) { public Face(int pipCount) {
addPipsForValue(pipCount); addPipsForValue(pipCount);
} }
@ -53,7 +55,9 @@ public class Face extends Actor{
private final Vector2 location; private final Vector2 location;
public Pip(float x, float y) { public Pip(float x, float y) {
location = new Vector2(x, y); Random rand = new Random();
int range = 2;
location = new Vector2(x + rand.nextInt(-range, range + 1), y+ rand.nextInt(-range, range + 1));
} }
public float getX() { public float getX() {
@ -77,18 +81,19 @@ public class Face extends Actor{
shape.setSize(w, h); shape.setSize(w, h);
} }
public void setBlankFaceSprite(Texture sprite){ public static void setBlankFaceSprite(Texture sprite){
blankFaceSprite = sprite; blankFaceSprite = sprite;
} }
public void setPipSprite(Texture sprite){ public static void setPipSprite(Texture sprite){
pipSprite = sprite; pipSprite = sprite;
} }
public Vector2 getPipLocationFromPercentage(Vector2 percentages) public Vector2 getPipLocationFromPercentage(Vector2 percentages)
{ {
Vector2 position = new Vector2(shape.x + (shape.width*percentages.x/100f) + (float)pipSprite.getWidth()/2, Vector2 position = new Vector2(
shape.y + shape.width*percentages.y/100f + (float)pipSprite.getHeight()/2); shape.x + (shape.width*percentages.x/100f) - (float)pipSprite.getWidth()/2,
shape.y + shape.width*percentages.y/100f - (float)pipSprite.getHeight()/2);
return position; return position;
} }

View file

@ -33,8 +33,11 @@ public class Game extends ApplicationAdapter {
font = new BitmapFont(); font = new BitmapFont();
img = new Texture("badlogic.jpg"); img = new Texture("badlogic.jpg");
for (int i = 0; i < 5; i++) { Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
dice.add(new Die()); Face.setPipSprite(new Texture("pip.png"));
for (int i = 1; i <= 5; i++) {
dice.add(new Die((i*80), 20, 64, 64));
} }
} }
@ -77,8 +80,7 @@ public class Game extends ApplicationAdapter {
//TODO debug //TODO debug
int x = 100; int x = 100;
for (Die die : dice) { for (Die die : dice) {
batch.setColor(Color.WHITE); die.render(batch);
font.draw(batch, String.valueOf(die.getFaceValue()), x += 50, 100);
} }
//----- //-----

View file

@ -11,6 +11,8 @@ public class DesktopLauncher {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setForegroundFPS(60); config.setForegroundFPS(60);
config.setTitle("GameJam"); config.setTitle("GameJam");
config.setWindowedMode(800, 480);
config.setResizable(false);
new Lwjgl3Application(new Game(), config); new Lwjgl3Application(new Game(), config);
} }