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

This commit is contained in:
James 2024-04-21 00:29:23 +01:00
commit 98c09014ad
10 changed files with 81 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 908 B

After

Width:  |  Height:  |  Size: 977 B

Binary file not shown.

Binary file not shown.

View file

@ -1,14 +1,13 @@
package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import java.util.List;
import java.util.Random;
public class Die extends Actor {
private final Rectangle shape;
private Transform transform;
/*
0
@ -19,26 +18,27 @@ public class Die extends Actor {
private int faceIndex = 3;
private boolean locked = false;
private static Texture lockedSprite;
private final Random random = new Random(); //TODO use central random
public Die(float x, float y, float width, float height) {
transform = new Transform(x, y, width, 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);
faces[i] = new Face(pips[i], transform);
}
shape = new Rectangle(x, y, width, height);
}
public void setPosition(float x, float y){
shape.setX(x);
shape.setY(y);
transform.setX(x);
transform.setY(y);
}
public void setSize(float w, float h){
shape.setSize(w, h);
transform.setSize(w, h);
}
@Override
@ -55,6 +55,10 @@ public class Die extends Actor {
faceIndex = random.nextInt(6);
}
public static void setLockedSprite(Texture sprite){
lockedSprite = sprite;
}
public void decay() { //remove a pip from all faces of this die
for (Face face : faces) {
List<Face.Pip> pips = face.getPips();
@ -80,6 +84,18 @@ public class Die extends Actor {
}
public void setLocked(boolean locked) {
if (locked != this.locked)
{
if (locked) {
transform.y += 64;
transform.rotation = 20;
}
else{
transform.y -= 64;
transform.rotation = 0;
}
} // terrible
this.locked = locked;
}

View file

@ -1,6 +1,7 @@
package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@ -12,23 +13,23 @@ import java.util.Random;
public class Face extends Actor{
private final Rectangle shape = new Rectangle();
private Transform transform;
private final List<Pip> pips = new ArrayList<>();
private static Texture blankFaceSprite;
private static Texture pipSprite;
public Face(int pipCount) {
public Face(int pipCount, Transform transform) {
addPipsForValue(pipCount);
this.transform = transform;
}
private void addPipsForValue(int value){
int[][] positions = {{25, 25}, {75, 75}, {25, 75}, {75, 25}, {25, 50}, {75, 50}};
int[][] positions = {{-25, -25}, {25, 25}, {-25, 25}, {25, -25}, {-25, 0}, {25, 0}};
if (value % 2 == 1) {
pips.add(new Pip(50, 50));
pips.add(new Pip(0, 0));
value--;
}
@ -72,12 +73,12 @@ public class Face extends Actor{
}
public void setPosition(float x, float y){
shape.setX(x);
shape.setY(y);
transform.setX(x);
transform.setY(y);
}
public void setSize(float w, float h){
shape.setSize(w, h);
transform.setSize(w, h);
}
public static void setBlankFaceSprite(Texture sprite){
@ -88,13 +89,15 @@ public class Face extends Actor{
pipSprite = sprite;
}
public Vector2 getPipLocationFromPercentage(Vector2 percentages)
{
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);
public Vector2 calculatePipLocation(Vector2 percentages) {
double radians = Math.toRadians(transform.rotation);
return position;
float x = (float) (percentages.x * Math.cos(radians) - percentages.y * Math.sin(radians));
float y = (float) (percentages.x * Math.sin(radians) + percentages.y * Math.cos(radians));
return new Vector2(
transform.x + transform.width*x/100f - (float)pipSprite.getWidth()/2,
transform.y + transform.height*y/100f - (float)pipSprite.getHeight()/2);
}
@Override
@ -104,9 +107,14 @@ public class Face extends Actor{
@Override
public void render(SpriteBatch batch) {
batch.draw(blankFaceSprite, shape.x, shape.y, shape.width, shape.height);
Sprite face = new Sprite(blankFaceSprite);
face.setOrigin(face.getWidth()/2, face.getHeight()/2);
face.rotate(transform.getRotation());
face.setPosition(transform.x-face.getWidth()/2, transform.y-face.getHeight()/2);
face.draw(batch);
for(Pip pip : pips){
Vector2 position = getPipLocationFromPercentage(pip.getVectorLocation());
Vector2 position = calculatePipLocation(pip.getVectorLocation());
batch.draw(pipSprite,
position.x,
position.y);

View file

@ -6,6 +6,7 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ScreenUtils;
import com.monjaro.gamejam.segment.DualSegment;
import com.monjaro.gamejam.segment.KinSegment;
@ -39,9 +40,12 @@ public class Game extends ApplicationAdapter {
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
Face.setPipSprite(new Texture("pip.png"));
Die.setLockedSprite(new Texture("locked_die_border.png"));
for (int i = 1; i <= 5; i++) {
dice.add(new Die((i*80), 20, 64, 64));
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));
}
for (int i = 1; i <= 5; i++) {

View file

@ -0,0 +1,23 @@
package com.monjaro.gamejam;
import com.badlogic.gdx.math.Rectangle;
public class Transform extends Rectangle {
float rotation;
public Transform(float x, float y, float width, float height){
super(x, y, width, height);
}
public Transform(){
super();
}
public float getRotation() {
return rotation;
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
}

View file

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