2017-01-22 13:46:38 +01:00
|
|
|
package org.warp.picalculator.gui.screens;
|
2016-09-02 20:32:37 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2017-10-17 22:49:21 +02:00
|
|
|
import org.warp.picalculator.StaticVars;
|
2018-06-30 18:46:53 +02:00
|
|
|
import org.warp.picalculator.device.HardwareDevice;
|
2016-09-19 18:48:27 +02:00
|
|
|
import org.warp.picalculator.device.Keyboard;
|
2018-04-01 01:01:57 +02:00
|
|
|
import org.warp.picalculator.extra.mario.MarioGame;
|
|
|
|
import org.warp.picalculator.extra.mario.MarioWorld;
|
2017-09-24 18:47:30 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.Skin;
|
2016-09-02 20:32:37 +02:00
|
|
|
|
|
|
|
public class MarioScreen extends Screen {
|
|
|
|
|
2018-04-01 01:01:57 +02:00
|
|
|
private MarioGame g;
|
2018-05-12 21:18:29 +02:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
private static Skin skin;
|
|
|
|
private static Skin groundskin;
|
2018-04-01 17:09:42 +02:00
|
|
|
private static BinaryFont gpuTest2;
|
|
|
|
private static BinaryFont gpuTest1;
|
2018-04-01 17:11:56 +02:00
|
|
|
private static boolean gpuTest12;
|
2018-04-01 17:09:42 +02:00
|
|
|
private static Skin gpuTest3;
|
|
|
|
private int gpuTestNum = 0;
|
|
|
|
private float gpuTestElapsed = 0;
|
2018-05-12 21:18:29 +02:00
|
|
|
private final int gpuTestMax = 21;
|
|
|
|
private final String[] gpuCharTest1 = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "ò" };
|
2018-04-01 17:09:42 +02:00
|
|
|
private int gpuCharTest1Num = 0;
|
|
|
|
private float gpuCharTestt1Elapsed = 0;
|
2016-09-02 20:32:37 +02:00
|
|
|
private boolean errored;
|
2018-04-01 01:01:57 +02:00
|
|
|
// public float[] marioPos = new float[] { 30, 0 };
|
|
|
|
// public float[] marioForces = new float[] { 0, 0 };
|
|
|
|
// public float jumptime = 0;
|
|
|
|
// public boolean walking = false;
|
|
|
|
// public boolean running = false;
|
|
|
|
// public boolean jumping = false;
|
|
|
|
// public boolean flipped = false;
|
|
|
|
// public boolean onGround = true;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-09-02 20:32:37 +02:00
|
|
|
public MarioScreen() {
|
|
|
|
super();
|
2016-11-25 22:40:43 +01:00
|
|
|
canBeInHistory = false;
|
2016-09-02 20:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-17 00:09:40 +01:00
|
|
|
public void initialized() {
|
2016-09-02 20:32:37 +02:00
|
|
|
try {
|
2018-05-12 21:18:29 +02:00
|
|
|
if (skin == null) {
|
2018-06-30 18:46:53 +02:00
|
|
|
skin = HardwareDevice.INSTANCE.getDisplayManager().engine.loadSkin("marioskin.png");
|
2018-05-12 21:18:29 +02:00
|
|
|
}
|
|
|
|
if (groundskin == null) {
|
2018-06-30 18:46:53 +02:00
|
|
|
groundskin = HardwareDevice.INSTANCE.getDisplayManager().engine.loadSkin("marioground.png");
|
2018-05-12 21:18:29 +02:00
|
|
|
}
|
|
|
|
if (gpuTest2 == null) {
|
2017-09-24 18:47:30 +02:00
|
|
|
try {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest2 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadFont("gputest2");
|
2018-05-12 21:18:29 +02:00
|
|
|
} catch (final Exception ex) {}
|
|
|
|
}
|
|
|
|
if (gpuTest1 == null) {
|
2017-11-19 22:58:37 +01:00
|
|
|
try {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest1 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadFont("gputest12");
|
2018-04-01 17:11:56 +02:00
|
|
|
gpuTest12 = true;
|
2018-05-12 21:18:29 +02:00
|
|
|
} catch (final Exception ex) {
|
2018-04-01 17:11:56 +02:00
|
|
|
gpuTest12 = false;
|
|
|
|
try {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest1 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadFont("gputest1");
|
2018-05-12 21:18:29 +02:00
|
|
|
} catch (final Exception ex2) {}
|
2018-04-01 17:11:56 +02:00
|
|
|
}
|
2018-05-12 21:18:29 +02:00
|
|
|
}
|
|
|
|
if (gpuTest3 == null) {
|
2017-09-24 18:47:30 +02:00
|
|
|
try {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest3 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadSkin("font_gputest3.png");
|
2018-08-29 00:07:45 +02:00
|
|
|
} catch (final Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2018-05-12 21:18:29 +02:00
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
} catch (final IOException e) {
|
2016-09-02 20:32:37 +02:00
|
|
|
e.printStackTrace();
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2016-09-02 20:32:37 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-09-02 20:32:37 +02:00
|
|
|
@Override
|
|
|
|
public void created() throws InterruptedException {
|
|
|
|
if (!errored) {
|
2018-04-01 01:01:57 +02:00
|
|
|
g = new MarioGame();
|
2016-09-02 20:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeRender(float dt) {
|
|
|
|
if (!errored) {
|
2017-01-31 22:29:49 +01:00
|
|
|
final boolean rightPressed = Keyboard.isKeyDown(2, 5);
|
|
|
|
final boolean leftPressed = Keyboard.isKeyDown(2, 3);
|
|
|
|
final boolean jumpPressed = Keyboard.isKeyDown(2, 1);
|
2018-04-01 01:01:57 +02:00
|
|
|
final boolean upPressed = false, downPressed = false, runPressed = false;
|
|
|
|
g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed);
|
2016-11-25 22:40:43 +01:00
|
|
|
|
2018-04-01 17:09:42 +02:00
|
|
|
gpuTestElapsed += dt;
|
|
|
|
while (gpuTestElapsed >= 0.04) {
|
|
|
|
gpuTestNum = (gpuTestNum + 1) % gpuTestMax;
|
|
|
|
gpuTestElapsed -= 0.04;
|
2017-11-19 22:58:37 +01:00
|
|
|
}
|
2018-04-01 17:09:42 +02:00
|
|
|
gpuCharTestt1Elapsed += dt;
|
|
|
|
while (gpuCharTestt1Elapsed >= 1.5) {
|
|
|
|
gpuCharTest1Num = (gpuCharTest1Num + 1) % gpuCharTest1.length;
|
|
|
|
gpuCharTestt1Elapsed -= 1.5;
|
2017-11-19 22:58:37 +01:00
|
|
|
}
|
2018-05-12 21:18:29 +02:00
|
|
|
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glClearColor(0xff000000);
|
2016-09-02 20:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render() {
|
|
|
|
if (errored) {
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringLeft(0, 20, "ERROR");
|
2016-09-02 20:32:37 +02:00
|
|
|
} else {
|
2018-04-01 01:01:57 +02:00
|
|
|
if (groundskin != null) {
|
2018-05-12 21:18:29 +02:00
|
|
|
final double playerX = g.getPlayer().getX();
|
|
|
|
final double playerY = g.getPlayer().getY();
|
2018-06-30 18:46:53 +02:00
|
|
|
groundskin.use(HardwareDevice.INSTANCE.getDisplayManager().engine);
|
2018-05-12 21:18:29 +02:00
|
|
|
final MarioWorld w = g.getCurrentWorld();
|
|
|
|
final int width = w.getWidth();
|
|
|
|
final int height = w.getHeight();
|
2018-06-30 18:46:53 +02:00
|
|
|
final float screenX = HardwareDevice.INSTANCE.getDisplayManager().engine.getWidth() / 2f - 8f;
|
|
|
|
final float screenY = HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() / 2f - 8f;
|
2018-05-12 21:18:29 +02:00
|
|
|
final float shiftX = -8 + 16 * (float) playerX;
|
|
|
|
final float shiftY = -8 + 16 * (height - (float) playerY);
|
2018-04-01 16:49:54 +02:00
|
|
|
int blue = -1;
|
2018-04-01 01:01:57 +02:00
|
|
|
for (int ix = 0; ix < width; ix++) {
|
|
|
|
for (int iy = 0; iy < height; iy++) {
|
2018-05-12 21:18:29 +02:00
|
|
|
final double distX = Math.abs(playerX - ix);
|
|
|
|
final double distY = Math.abs(playerY - iy - 1.5d);
|
|
|
|
if ((distX * distX + distY * distY / 2d) < 25d) {
|
|
|
|
final byte b = w.getBlockIdAt(ix, iy);
|
2018-04-01 16:49:54 +02:00
|
|
|
if (b == 0) {
|
|
|
|
if (blue != 1) {
|
|
|
|
blue = 1;
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xff9290ff);
|
2018-04-01 16:49:54 +02:00
|
|
|
}
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glFillColor(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16);
|
2018-04-01 16:49:54 +02:00
|
|
|
} else {
|
|
|
|
if (blue != 0) {
|
|
|
|
blue = 0;
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xffffffff);
|
2018-04-01 16:49:54 +02:00
|
|
|
}
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glFillRect(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16, 0, 0, 16, 16);
|
2018-04-01 16:49:54 +02:00
|
|
|
}
|
2018-04-01 01:01:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 16:49:54 +02:00
|
|
|
if (blue != 0) {
|
|
|
|
blue = 0;
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xffffffff);
|
2018-04-01 16:49:54 +02:00
|
|
|
}
|
2018-04-01 01:01:57 +02:00
|
|
|
|
|
|
|
//DRAW MARIO
|
2018-06-30 18:46:53 +02:00
|
|
|
skin.use(HardwareDevice.INSTANCE.getDisplayManager().engine);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glFillRect(screenX - (g.getPlayer().flipped ? 3 : 0), screenY, 35, 27, 35 * (g.getPlayer().marioSkinPos[0] + (g.getPlayer().flipped ? 2 : 1)), 27 * g.getPlayer().marioSkinPos[1], 35 * (g.getPlayer().flipped ? -1 : 1), 27);
|
2018-04-01 01:01:57 +02:00
|
|
|
// PIDisplay.renderer.glDrawSkin(getPosX() - 18, 25 + getPosY(), 35 * (marioSkinPos[0] + (flipped ? 2 : 1)), 27 * marioSkinPos[1], 35 * (marioSkinPos[0] + (flipped ? 1 : 2)), 27 * (marioSkinPos[1] + 1), true);
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2018-04-01 17:09:42 +02:00
|
|
|
// GPU PERFORMANCE TEST
|
|
|
|
if (gpuTest1 != null) {
|
2018-06-30 18:46:53 +02:00
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor3f(1, 1, 1);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glFillColor(HardwareDevice.INSTANCE.getDisplayManager().engine.getWidth() - (gpuTest12 ? 512 : 256), HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() / 2 - (gpuTest12 ? 256 : 128), gpuTest12 ? 512 : 256, gpuTest12 ? 512 : 256);
|
|
|
|
gpuTest1.use(HardwareDevice.INSTANCE.getDisplayManager().engine);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor3f(0, 0, 0);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(HardwareDevice.INSTANCE.getDisplayManager().engine.getWidth(), HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() / 2 - (gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]);
|
2017-11-19 22:58:37 +01:00
|
|
|
}
|
2018-04-01 17:09:42 +02:00
|
|
|
if (gpuTest3 != null) {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest3.use(HardwareDevice.INSTANCE.getDisplayManager().engine);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor4f(1, 1, 1, 0.7f);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glFillRect(0, StaticVars.screenSize[1] - 128, 224, 128, gpuTestNum * 224, 0, 224, 128);
|
2017-11-19 22:58:37 +01:00
|
|
|
}
|
2018-04-01 17:09:42 +02:00
|
|
|
if (gpuTest2 != null) {
|
2018-06-30 18:46:53 +02:00
|
|
|
gpuTest2.use(HardwareDevice.INSTANCE.getDisplayManager().engine);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFF000000);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "A");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFF800000);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "B");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFFeea28e);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "C");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFFee7255);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "D");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFFeac0b0);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "E");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFFf3d8ce);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "F");
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glColor(0xFFffede7);
|
|
|
|
HardwareDevice.INSTANCE.getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], HardwareDevice.INSTANCE.getDisplayManager().engine.getHeight() - gpuTest2.getCharacterHeight(), "G");
|
2017-09-24 18:47:30 +02:00
|
|
|
}
|
2016-09-02 20:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean mustBeRefreshed() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|