add falling pips woo
This commit is contained in:
parent
37ec466241
commit
8d664684da
4 changed files with 43 additions and 8 deletions
|
@ -7,7 +7,8 @@ import java.util.Random;
|
|||
|
||||
public class Die extends Actor {
|
||||
|
||||
private Transform transform;
|
||||
private final Game game;
|
||||
private final Transform transform;
|
||||
|
||||
/*
|
||||
0
|
||||
|
@ -22,7 +23,9 @@ public class Die extends Actor {
|
|||
|
||||
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);
|
||||
|
||||
int[] pips = {4, 6, 5, 1, 2, 3};
|
||||
|
@ -64,6 +67,8 @@ public class Die extends Actor {
|
|||
if (pips.isEmpty()) continue;
|
||||
Face.Pip decayed = pips.get(random.nextInt(pips.size()));
|
||||
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;
|
||||
}
|
||||
|
||||
public static Texture getPipSprite() {
|
||||
return pipSprite;
|
||||
}
|
||||
|
||||
public static void setBlankFaceSprite(Texture sprite){
|
||||
blankFaceSprite = sprite;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.monjaro.gamejam.main;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
|
@ -11,16 +12,22 @@ public class FallingPip extends Actor {
|
|||
private final Vector2 velocity;
|
||||
private final float rotationalVelocity;
|
||||
|
||||
public FallingPip(Transform transform) {
|
||||
private final boolean onTop;
|
||||
|
||||
public FallingPip(Transform transform, boolean onTop) {
|
||||
Random random = new Random();
|
||||
|
||||
this.transform = transform;
|
||||
velocity = new Vector2(-1 + random.nextFloat() * 2, random.nextFloat() * 2);
|
||||
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;
|
||||
|
@ -28,7 +35,16 @@ public class FallingPip extends Actor {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ public class Game extends ApplicationAdapter {
|
|||
|
||||
private Round round;
|
||||
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 SegmentUI segUi;
|
||||
|
@ -66,7 +68,7 @@ public class Game extends ApplicationAdapter {
|
|||
|
||||
float divide = Gdx.graphics.getWidth() / 6f;
|
||||
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();
|
||||
|
@ -75,6 +77,8 @@ public class Game extends ApplicationAdapter {
|
|||
|
||||
public void tick() {
|
||||
processInput();
|
||||
|
||||
fallingPips.forEach(Actor::tick);
|
||||
}
|
||||
|
||||
public void processInput() {
|
||||
|
@ -149,16 +153,18 @@ public class Game extends ApplicationAdapter {
|
|||
ScreenUtils.clear(0, 0, 0, 1);
|
||||
batch.begin();
|
||||
|
||||
//TODO debug
|
||||
for (FallingPip pip : fallingPips) if (!pip.isOnTop()) pip.render(batch);
|
||||
|
||||
for (Die die : dice) {
|
||||
die.render(batch);
|
||||
}
|
||||
|
||||
for (FallingPip pip : fallingPips) if (pip.isOnTop()) pip.render(batch); //on top
|
||||
|
||||
int y = Gdx.graphics.getHeight() / 3 * 2 - 25;
|
||||
for (Decay decay : round.getDecays()) {
|
||||
font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20);
|
||||
}
|
||||
//-----
|
||||
|
||||
ui.render(batch);
|
||||
|
||||
|
@ -249,4 +255,8 @@ public class Game extends ApplicationAdapter {
|
|||
return Collections.unmodifiableList(shope);
|
||||
}
|
||||
|
||||
public void addFallingPip(FallingPip pip) {
|
||||
fallingPips.add(pip);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue