Merge branch 'main' of github.com:Wil-Ro/gamejam2024
This commit is contained in:
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 |
BIN
assets/pip.png
BIN
assets/pip.png
Binary file not shown.
Before Width: | Height: | Size: 908 B After Width: | Height: | Size: 977 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,14 +1,13 @@
|
||||||
package com.monjaro.gamejam;
|
package com.monjaro.gamejam;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Die extends Actor {
|
public class Die extends Actor {
|
||||||
|
|
||||||
private final Rectangle shape;
|
private Transform transform;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0
|
0
|
||||||
|
@ -19,26 +18,27 @@ public class Die extends Actor {
|
||||||
private int faceIndex = 3;
|
private int faceIndex = 3;
|
||||||
private boolean locked = false;
|
private boolean locked = false;
|
||||||
|
|
||||||
|
private static Texture lockedSprite;
|
||||||
|
|
||||||
private final Random random = new Random(); //TODO use central random
|
private final Random random = new Random(); //TODO use central random
|
||||||
|
|
||||||
|
|
||||||
public Die(float x, float y, float width, float height) {
|
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};
|
int[] pips = {4, 6, 5, 1, 2, 3};
|
||||||
for (int i = 0; i < faces.length; i++) {
|
for (int i = 0; i < faces.length; i++) {
|
||||||
faces[i] = new Face(pips[i]);
|
faces[i] = new Face(pips[i], transform);
|
||||||
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);
|
transform.setX(x);
|
||||||
shape.setY(y);
|
transform.setY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(float w, float h){
|
public void setSize(float w, float h){
|
||||||
shape.setSize(w, h);
|
transform.setSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,6 +55,10 @@ public class Die extends Actor {
|
||||||
faceIndex = random.nextInt(6);
|
faceIndex = random.nextInt(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLockedSprite(Texture sprite){
|
||||||
|
lockedSprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
public void decay() { //remove a pip from all faces of this die
|
public void decay() { //remove a pip from all faces of this die
|
||||||
for (Face face : faces) {
|
for (Face face : faces) {
|
||||||
List<Face.Pip> pips = face.getPips();
|
List<Face.Pip> pips = face.getPips();
|
||||||
|
@ -80,6 +84,18 @@ public class Die extends Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked(boolean locked) {
|
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;
|
this.locked = locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.monjaro.gamejam;
|
package com.monjaro.gamejam;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
@ -12,23 +13,23 @@ import java.util.Random;
|
||||||
|
|
||||||
public class Face extends Actor{
|
public class Face extends Actor{
|
||||||
|
|
||||||
private final Rectangle shape = new Rectangle();
|
private Transform transform;
|
||||||
|
|
||||||
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, Transform transform) {
|
||||||
public Face(int pipCount) {
|
|
||||||
addPipsForValue(pipCount);
|
addPipsForValue(pipCount);
|
||||||
|
this.transform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
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}, {25, 25}, {-25, 25}, {25, -25}, {-25, 0}, {25, 0}};
|
||||||
|
|
||||||
if (value % 2 == 1) {
|
if (value % 2 == 1) {
|
||||||
pips.add(new Pip(50, 50));
|
pips.add(new Pip(0, 0));
|
||||||
value--;
|
value--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +73,12 @@ public class Face extends Actor{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(float x, float y){
|
public void setPosition(float x, float y){
|
||||||
shape.setX(x);
|
transform.setX(x);
|
||||||
shape.setY(y);
|
transform.setY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(float w, float h){
|
public void setSize(float w, float h){
|
||||||
shape.setSize(w, h);
|
transform.setSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBlankFaceSprite(Texture sprite){
|
public static void setBlankFaceSprite(Texture sprite){
|
||||||
|
@ -88,13 +89,15 @@ public class Face extends Actor{
|
||||||
pipSprite = sprite;
|
pipSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getPipLocationFromPercentage(Vector2 percentages)
|
public Vector2 calculatePipLocation(Vector2 percentages) {
|
||||||
{
|
double radians = Math.toRadians(transform.rotation);
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
|
@ -104,9 +107,14 @@ public class Face extends Actor{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(SpriteBatch batch) {
|
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){
|
for(Pip pip : pips){
|
||||||
Vector2 position = getPipLocationFromPercentage(pip.getVectorLocation());
|
Vector2 position = calculatePipLocation(pip.getVectorLocation());
|
||||||
batch.draw(pipSprite,
|
batch.draw(pipSprite,
|
||||||
position.x,
|
position.x,
|
||||||
position.y);
|
position.y);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.Input;
|
||||||
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.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
import com.monjaro.gamejam.segment.DualSegment;
|
import com.monjaro.gamejam.segment.DualSegment;
|
||||||
import com.monjaro.gamejam.segment.KinSegment;
|
import com.monjaro.gamejam.segment.KinSegment;
|
||||||
|
@ -39,9 +40,12 @@ public class Game extends ApplicationAdapter {
|
||||||
|
|
||||||
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
|
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
|
||||||
Face.setPipSprite(new Texture("pip.png"));
|
Face.setPipSprite(new Texture("pip.png"));
|
||||||
|
Die.setLockedSprite(new Texture("locked_die_border.png"));
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
Vector2 dieSize = new Vector2();
|
||||||
dice.add(new Die((i*80), 20, 64, 64));
|
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++) {
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
|
23
core/src/com/monjaro/gamejam/Transform.java
Normal file
23
core/src/com/monjaro/gamejam/Transform.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ 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.setWindowedMode(480, 800);
|
||||||
config.setResizable(false);
|
config.setResizable(false);
|
||||||
new Lwjgl3Application(new Game(), config);
|
new Lwjgl3Application(new Game(), config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue