WarpPI/core/src/main/java/it/cavallium/warppi/extra/mario/MarioGame.java

263 lines
17 KiB
Java

package it.cavallium.warppi.extra.mario;
public class MarioGame {
private final PlayerEntity player;
private final int currentWorld;
private final MarioWorld[] worlds;
private boolean canMove;
public MarioGame() {
player = new PlayerEntity(1, 0, 5);
currentWorld = 0;
worlds = new MarioWorld[] { new MarioWorld(new int[] { 1, 6 }, 100, 20, new byte[][] { new byte[] { 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0 }, new byte[] { 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 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0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0 } }, new MarioEvent[] {
}, new MarioEntity[] {
}) };
playAgain();
}
private void playAgain() {
canMove = false;
final MarioWorld w = getCurrentWorld();
w.reset();
player.setPosition(w.getSpawnPointX(), w.getSpawnPointY(), true);
canMove = true;
}
public MarioBlock getBlockAt(int x, int y) {
return worlds[currentWorld].getBlockAt(x, y);
}
public MarioBlock getBlockAt(double x, double y) {
return getBlockAt((int) x, (int) y);
}
public void move(float dt, double deltaX, double deltaY) {
final double curX = player.getX();
final double curY = player.getY();
final double futureX = curX + deltaX;
final double futureY = curY + deltaY;
@SuppressWarnings("unused")
final boolean forward = futureX >= curX;
@SuppressWarnings("unused")
final boolean up = futureY >= curY;
player.move(dt, futureX - curX, futureY - curY);
}
public MarioWorld getCurrentWorld() {
return worlds[currentWorld];
}
public void gameTick(float dt, boolean upPressed, boolean downPressed, boolean leftPressed, boolean rightPressed,
boolean jumpPressed, boolean runPressed) {
checkOnGround(getPlayer(), dt);
checkCollisionTop(getPlayer(), dt);
checkCollisionLeft(getPlayer(), dt);
checkCollisionRight(getPlayer(), dt);
if (canMove) {
move(dt, (rightPressed ? 1 : 0) - (leftPressed ? 1 : 0), jumpPressed ? 1 : 0);
}
getPlayer().gameTick(dt);
final MarioWorld w = getCurrentWorld();
for (final MarioEntity e : w.getEntities()) {
checkOnGround(e, dt);
checkCollisionTop(e, dt);
checkCollisionLeft(e, dt);
checkCollisionRight(e, dt);
e.gameTick(dt);
}
}
@SuppressWarnings("unused")
private int nearest(double val, int a, int b) {
final double aa = Math.abs(val - a);
final double ab = Math.abs(val - b);
if (aa < ab) {
return (int) aa;
} else {
return (int) ab;
}
}
private void checkOnGround(MarioEntity e, float dt) {
if (e.subjectToGravity) {
final int xA = (int) Math.floor(e.getX());
final int xB = (int) Math.ceil(e.getX());
final int y0 = (int) Math.ceil(e.getY());
final int y1 = (int) Math.ceil(e.getY() + e.computeFutureDY(dt));
boolean onGround = false;
if (y1 < y0) {
for (int y = y0; y >= y1; y--) {
for (int x = xA; x <= xB; x++) {
final byte b = getCurrentWorld().getBlockIdAt(x, y - 1);
if (MarioBlock.isSolid(b)) {
onGround = true;
if (e.forceY < 0) {
e.setOnGround(true);
e.forceY = 0;
e.setPosition(e.getX(), y, true);
}
break;
}
}
}
} else {
for (int x = xA; x <= xB; x++) {
final byte b = getCurrentWorld().getBlockIdAt(x, y0 - 1);
if (MarioBlock.isSolid(b)) {
onGround = true;
if (e.forceY < 0) {
e.setOnGround(true);
e.forceY = 0;
e.setPosition(e.getX(), y0, true);
}
}
}
}
if (!onGround) {
e.setOnGround(false);
}
}
}
private void checkCollisionTop(MarioEntity e, float dt) {
if (e.subjectToGravity) {
final int xA = (int) Math.floor(e.getX());
final int xB = (int) Math.ceil(e.getX());
final int y0 = (int) Math.ceil(e.getY());
final int y1 = (int) Math.ceil(e.getY() + e.computeFutureDY(dt));
boolean collisionUp = false;
if (y1 > y0) {
for (int y = y0; y <= y1; y++) {
for (int x = xA; x <= xB; x++) {
final byte b = getCurrentWorld().getBlockIdAt(x, y + 1);
if (MarioBlock.isSolid(b)) {
collisionUp = true;
if (e.forceY > 0) {
e.forceY = 0;
e.setPosition(e.getX(), y);
e.collisionUp = true;
}
break;
}
}
}
} else {
for (int x = xA; x <= xB; x++) {
final byte b = getCurrentWorld().getBlockIdAt(x, y0 + 1);
if (MarioBlock.isSolid(b)) {
collisionUp = true;
if (e.forceY > 0) {
e.forceY = 0;
e.setPosition(e.getX(), y0);
e.collisionUp = true;
}
}
}
}
if (!collisionUp) {
e.collisionUp = false;
}
}
}
private void checkCollisionRight(MarioEntity e, float dt) {
if (e.subjectToGravity) {
final int yA = (int) Math.floor(e.getY());
final int yB = (int) Math.ceil(e.getY());
final int x0 = (int) Math.floor(e.getX());
final double x1double = e.getX() + e.computeFutureDX(dt);
final int x1 = (int) Math.floor(x1double);
boolean collisionRight = false;
if (x1 > x0) {
for (int x = x0; x <= x1; x++) {
for (int y = yA; y <= yB; y++) {
final byte b = getCurrentWorld().getBlockIdAt(x + 1, y);
if (MarioBlock.isSolid(b)) {
collisionRight = true;
if (e.forceX > 0 && x1double >= x) {
e.forceX = 0;
e.setPosition(x, e.getY());
e.collisionRight = true;
}
break;
}
}
}
} else {
for (int y = yA; y <= yB; y++) {
final byte b = getCurrentWorld().getBlockIdAt(x0 + 1, y);
if (MarioBlock.isSolid(b)) {
collisionRight = true;
if (e.forceX > 0 && x1double >= x0) {
e.forceX = 0;
e.setPosition(x0, e.getY());
e.collisionRight = true;
}
}
}
}
if (!collisionRight) {
e.collisionRight = false;
}
}
}
private void checkCollisionLeft(MarioEntity e, float dt) {
if (e.subjectToGravity) {
final int yA = (int) Math.floor(e.getY());
final int yB = (int) Math.ceil(e.getY());
final int x0 = (int) Math.ceil(e.getX());
final double x1double = e.getX() + e.computeFutureDX(dt);
final int x1 = (int) Math.ceil(x1double);
boolean collisionLeft = false;
if (x1 <= 0) {
if (e.forceX <= 0) {
e.forceX = 0;
e.setPosition(0, e.getY());
}
e.collisionLeft = true;
} else {
if (x1 < x0) {
for (int x = x0; x >= x1; x--) {
for (int y = yA; y <= yB; y++) {
final byte b = getCurrentWorld().getBlockIdAt(x - 1, y);
if (MarioBlock.isSolid(b)) {
collisionLeft = true;
if (e.forceX < 0 && x1double <= x) {
e.forceX = 0;
e.setPosition(x, e.getY());
e.collisionLeft = true;
}
break;
}
}
}
} else {
for (int y = yA; y <= yB; y++) {
final byte b = getCurrentWorld().getBlockIdAt(x0 - 1, y);
if (MarioBlock.isSolid(b)) {
collisionLeft = true;
if (e.forceX < 0 && x1double <= x0) {
e.forceX = 0;
e.setPosition(x0, e.getY());
e.collisionLeft = true;
}
}
}
}
}
if (!collisionLeft) {
e.collisionLeft = false;
}
}
}
public PlayerEntity getPlayer() {
return player;
}
}