Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
9ba5125c15
4 changed files with 75 additions and 6 deletions
|
@ -7,7 +7,8 @@ import java.util.Random;
|
||||||
|
|
||||||
public class Die extends Actor {
|
public class Die extends Actor {
|
||||||
|
|
||||||
private Transform transform;
|
private final Game game;
|
||||||
|
private final Transform transform;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0
|
0
|
||||||
|
@ -22,7 +23,9 @@ public class Die extends Actor {
|
||||||
|
|
||||||
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(Game game, float x, float y, float width, float height) {
|
||||||
|
this.game = game;
|
||||||
|
|
||||||
transform = new Transform(x, y, width, height);
|
transform = new Transform(x, y, width, height);
|
||||||
|
|
||||||
int[] pips = {4, 6, 5, 1, 2, 3};
|
int[] pips = {4, 6, 5, 1, 2, 3};
|
||||||
|
@ -64,6 +67,8 @@ public class Die extends Actor {
|
||||||
if (pips.isEmpty()) continue;
|
if (pips.isEmpty()) continue;
|
||||||
Face.Pip decayed = pips.get(random.nextInt(pips.size()));
|
Face.Pip decayed = pips.get(random.nextInt(pips.size()));
|
||||||
face.removePip(decayed);
|
face.removePip(decayed);
|
||||||
|
|
||||||
|
game.addFallingPip(new FallingPip(new Transform(transform.getX(), transform.getY(), 0, 0), face.equals(getFace())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,10 @@ public class Face extends Actor{
|
||||||
this.transform = transform;
|
this.transform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Texture getPipSprite() {
|
||||||
|
return pipSprite;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setBlankFaceSprite(Texture sprite){
|
public static void setBlankFaceSprite(Texture sprite){
|
||||||
blankFaceSprite = sprite;
|
blankFaceSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
50
core/src/com/monjaro/gamejam/main/FallingPip.java
Normal file
50
core/src/com/monjaro/gamejam/main/FallingPip.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package com.monjaro.gamejam.main;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FallingPip extends Actor {
|
||||||
|
|
||||||
|
private final Transform transform;
|
||||||
|
private final Vector2 velocity;
|
||||||
|
private final float rotationalVelocity;
|
||||||
|
|
||||||
|
private final boolean onTop;
|
||||||
|
|
||||||
|
public FallingPip(Transform transform, boolean onTop) {
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
this.transform = transform;
|
||||||
|
velocity = new Vector2(5 * (-0.5f + random.nextFloat()), 2 + random.nextFloat() * 3);
|
||||||
|
rotationalVelocity = 40 * (-0.5f + random.nextFloat());
|
||||||
|
|
||||||
|
this.onTop = onTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
velocity.y -= 9.81 / 60; //gravity
|
||||||
|
|
||||||
|
transform.x += velocity.x;
|
||||||
|
transform.y += velocity.y;
|
||||||
|
transform.rotation += rotationalVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(SpriteBatch batch) {
|
||||||
|
Texture sprite = Face.getPipSprite();
|
||||||
|
batch.draw(sprite, transform.x, transform.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOffScreen() {
|
||||||
|
return transform.y <= 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOnTop() {
|
||||||
|
return onTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -29,7 +29,9 @@ public class Game extends ApplicationAdapter {
|
||||||
|
|
||||||
private Round round;
|
private Round round;
|
||||||
private int roundNumber = 0;
|
private int roundNumber = 0;
|
||||||
private List<Face> shope = new ArrayList<>();
|
private final List<Face> shope = new ArrayList<>();
|
||||||
|
|
||||||
|
private final List<FallingPip> fallingPips = new ArrayList<>();
|
||||||
|
|
||||||
private UI ui;
|
private UI ui;
|
||||||
private SegmentUI segUi;
|
private SegmentUI segUi;
|
||||||
|
@ -71,7 +73,7 @@ public class Game extends ApplicationAdapter {
|
||||||
|
|
||||||
float divide = Gdx.graphics.getWidth() / 6f;
|
float divide = Gdx.graphics.getWidth() / 6f;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
dice.add(new Die(divide * (i + 1), 350, 64, 64));
|
dice.add(new Die(this, divide * (i + 1), 350, 64, 64));
|
||||||
}
|
}
|
||||||
|
|
||||||
reroll();
|
reroll();
|
||||||
|
@ -80,6 +82,8 @@ public class Game extends ApplicationAdapter {
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
processInput();
|
processInput();
|
||||||
|
|
||||||
|
fallingPips.forEach(Actor::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processInput() {
|
public void processInput() {
|
||||||
|
@ -156,16 +160,18 @@ public class Game extends ApplicationAdapter {
|
||||||
ScreenUtils.clear(0, 0, 0, 1);
|
ScreenUtils.clear(0, 0, 0, 1);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
|
||||||
//TODO debug
|
for (FallingPip pip : fallingPips) if (!pip.isOnTop()) pip.render(batch);
|
||||||
|
|
||||||
for (Die die : dice) {
|
for (Die die : dice) {
|
||||||
die.render(batch);
|
die.render(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (FallingPip pip : fallingPips) if (pip.isOnTop()) pip.render(batch); //on top
|
||||||
|
|
||||||
int y = Gdx.graphics.getHeight() / 3 * 2 - 25;
|
int y = Gdx.graphics.getHeight() / 3 * 2 - 25;
|
||||||
for (Decay decay : round.getDecays()) {
|
for (Decay decay : round.getDecays()) {
|
||||||
font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20);
|
font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20);
|
||||||
}
|
}
|
||||||
//-----
|
|
||||||
|
|
||||||
ui.render(batch);
|
ui.render(batch);
|
||||||
|
|
||||||
|
@ -258,4 +264,8 @@ public class Game extends ApplicationAdapter {
|
||||||
return Collections.unmodifiableList(shope);
|
return Collections.unmodifiableList(shope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFallingPip(FallingPip pip) {
|
||||||
|
fallingPips.add(pip);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue