Added respawning and a death screen
This commit is contained in:
parent
ace02dbddf
commit
40a0c6474d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -236,7 +236,7 @@ public class Entity implements ITransparentObject
|
|||
|
||||
@Override
|
||||
public void MainLoopUpdate() {
|
||||
if(!Main.game_paused) {
|
||||
if(Main.menu.doGameloop) {
|
||||
moveTowards(Math.toRadians(angle) + 180, a[0]/100.0);
|
||||
a[0] -= a[0] / 100.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ public class EntityEventHandler implements IMainloopTask
|
|||
@Override
|
||||
public void MainLoopUpdate()
|
||||
{
|
||||
if(Main.game_paused) {
|
||||
Main.menu.update();
|
||||
if(!Main.menu.doGameloop) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package shootergame.entity.player;
|
||||
|
||||
import mainloop.task.IMainloopTask;
|
||||
import shootergame.Main;
|
||||
import shootergame.cheats.Cheats;
|
||||
import shootergame.display.Camera;
|
||||
|
|
@ -12,6 +13,7 @@ import shootergame.entity.EntityItem;
|
|||
import shootergame.entity.EntityVertical;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.inventory.Inventory;
|
||||
import shootergame.menu.MenuDeath;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.ItemStack;
|
||||
|
|
@ -71,6 +73,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
@Override
|
||||
public void tick(Chunk chunk, Layer layer)
|
||||
{
|
||||
if(dead) return;
|
||||
|
||||
// Handle player deaths
|
||||
if(health <= 0)
|
||||
{
|
||||
|
|
@ -81,6 +85,24 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
|||
else {
|
||||
dead = true;
|
||||
health = 0;
|
||||
|
||||
Main.mainloop.register(new IMainloopTask() {
|
||||
|
||||
@Override
|
||||
public void MainLoopUpdate() {
|
||||
Main.menu = new MenuDeath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean MainLoopRepeat() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean MainLoopDelay(long millis) {
|
||||
return millis > 5000;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import shootergame.world.layer.layergen.LayerGenLavaCaves;
|
|||
|
||||
public class Layers
|
||||
{
|
||||
private static final ArrayList<Layer> id_layers = new ArrayList<Layer>();
|
||||
private static ArrayList<Layer> id_layers = new ArrayList<Layer>();
|
||||
|
||||
public static void init(long seed)
|
||||
{
|
||||
|
|
@ -22,6 +22,7 @@ public class Layers
|
|||
LAVA_CAVES = new Layer(new Random(seed), new LayerGenLavaCaves(), 2);
|
||||
|
||||
// Setup all the id-able layers
|
||||
id_layers = new ArrayList<Layer>();
|
||||
id_layers.add(EARTH);
|
||||
id_layers.add(CAVES);
|
||||
id_layers.add(LAVA_CAVES);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package shootergame.input.types;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.menu.Menu;
|
||||
import shootergame.menu.MenuDeath;
|
||||
|
||||
public class InputDeath implements Input
|
||||
{
|
||||
|
||||
@Override
|
||||
public void move(boolean state, double angle) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(boolean state) {
|
||||
Menu menu = Main.menu;
|
||||
if(menu instanceof MenuDeath) {
|
||||
MenuDeath menu_d = (MenuDeath) menu;
|
||||
menu_d.resetting = state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateTile(boolean state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void camera(boolean state, double amount) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemAction(boolean state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemDrop(boolean state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(boolean state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hotbarGoto(boolean state, int pos) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hotbarShift(boolean state, int amount) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package shootergame.input.types;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.menu.Menu;
|
||||
import shootergame.menu.MenuDeath;
|
||||
import shootergame.menu.MenuGame;
|
||||
import shootergame.menu.MenuGamePause;
|
||||
|
||||
public class InputGamePause implements Input
|
||||
{
|
||||
|
|
@ -12,6 +15,11 @@ public class InputGamePause implements Input
|
|||
|
||||
@Override
|
||||
public void fire(boolean state) {
|
||||
Menu menu = Main.menu;
|
||||
if(menu instanceof MenuGamePause) {
|
||||
MenuGamePause menu_gp = (MenuGamePause) menu;
|
||||
menu_gp.resetting = state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,4 +9,7 @@ public abstract class Menu
|
|||
public Input input;
|
||||
|
||||
public abstract void render();
|
||||
|
||||
public void update() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package shootergame.menu;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.init.Layers;
|
||||
import shootergame.input.types.InputDeath;
|
||||
import shootergame.input.types.InputGamePause;
|
||||
import shootergame.text.Text;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class MenuDeath extends Menu
|
||||
{
|
||||
|
||||
public boolean resetting = false;
|
||||
private MenuRespawn menu_restart = new MenuRespawn();
|
||||
|
||||
public MenuDeath() {
|
||||
this.doGameloop = false;
|
||||
this.doGameRender = true;
|
||||
this.input = new InputDeath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render()
|
||||
{
|
||||
// Render the screen darkening of the gameplay
|
||||
GlHelpers.disableTexture2d();
|
||||
GlHelpers.color4(0, 0, 0, 0.5);
|
||||
GlHelpers.begin();
|
||||
GlHelpers.vertex3(-10, -10, 0);
|
||||
GlHelpers.vertex3(-10, 10, 0);
|
||||
GlHelpers.vertex3(10, 10, 0);
|
||||
GlHelpers.vertex3(10, -10, 0);
|
||||
GlHelpers.end();
|
||||
GlHelpers.color4(1, 1, 1, 1);
|
||||
GlHelpers.enableTexture2d();
|
||||
|
||||
// Render some text to say the player is dead
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate2(0, 4);
|
||||
Text.renderCenter("You Died", new Vec2d(1, 1));
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
this.menu_restart.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
this.menu_restart.update(resetting);
|
||||
resetting = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,9 @@ import shootergame.util.math.vec.Vec2d;
|
|||
|
||||
public class MenuGamePause extends Menu
|
||||
{
|
||||
public boolean resetting;
|
||||
private MenuRespawn menu_restart = new MenuRespawn();
|
||||
|
||||
public MenuGamePause() {
|
||||
this.doGameloop = false;
|
||||
this.doGameRender = true;
|
||||
|
|
@ -30,9 +33,18 @@ public class MenuGamePause extends Menu
|
|||
|
||||
// Render some text to say the game is paused
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate3(-2.5, 1, 0);
|
||||
Text.render("Game Paused", new Vec2d(1, 1));
|
||||
GlHelpers.translate2(0, 4);
|
||||
Text.renderCenter("Game Paused", new Vec2d(1, 1));
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
menu_restart.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
menu_restart.update(resetting);
|
||||
resetting = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package shootergame.menu;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.init.Layers;
|
||||
import shootergame.text.Text;
|
||||
import shootergame.time.GameTimer;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
class MenuRespawn
|
||||
{
|
||||
private int reset_progress = 0;
|
||||
private static final Random rand = new Random();
|
||||
|
||||
void update(boolean resetting)
|
||||
{
|
||||
if(resetting) {
|
||||
this.reset_progress += 10;
|
||||
} else if(this.reset_progress > 0) {
|
||||
this.reset_progress -= 5;
|
||||
}
|
||||
|
||||
if(this.reset_progress >= 1000)
|
||||
{
|
||||
// Reset the world and the player
|
||||
Layers.init(rand.nextLong());
|
||||
Main.player = new EntityPlayer();
|
||||
Main.menu = new MenuGame();
|
||||
Main.game_paused = false;
|
||||
GameTimer.resetTime();
|
||||
}
|
||||
}
|
||||
|
||||
void render()
|
||||
{
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate2(0, 2.5);
|
||||
Text.renderCenter("Press and hold fire to respawn", new Vec2d(0.5, 0.5));
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
double p = reset_progress/1000.0*8;
|
||||
GlHelpers.disableTexture2d();
|
||||
GlHelpers.color4(1, 1, 0, 1);
|
||||
GlHelpers.begin();
|
||||
{
|
||||
GlHelpers.vertex2(-4.0, -3.2);
|
||||
GlHelpers.vertex2(-4+p, -3.2);
|
||||
GlHelpers.vertex2(-4+p, -3.0);
|
||||
GlHelpers.vertex2(-4.0, -3.0);
|
||||
}
|
||||
GlHelpers.end();
|
||||
GlHelpers.color3(0, 0, 0);
|
||||
GlHelpers.enableTexture2d();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package shootergame.text;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
|
|
@ -90,6 +91,14 @@ public class Text
|
|||
public static final TextureReference CHAR_L_THEN = Textures.texmap.getTextureReference(14, 15, 10, 11);
|
||||
public static final TextureReference CHAR_G_THEN = Textures.texmap.getTextureReference(15, 16, 10, 11);
|
||||
|
||||
public static void renderCenter(String text, Vec2d size) {
|
||||
int w = Main.window.getWidth();
|
||||
int h = Main.window.getHeight();
|
||||
double aspect_ratio = ((double)w) / ((double)h);
|
||||
GlHelpers.translate2(0 - ((text.length() - 2) * size.x / 2 / aspect_ratio), 0);
|
||||
Text.render(text, size);
|
||||
}
|
||||
|
||||
public static void render(String text, Vec2d size)
|
||||
{
|
||||
// Get the bytes from the string
|
||||
|
|
|
|||
|
|
@ -24,8 +24,12 @@ public class GameTimer implements IMainloopTask
|
|||
|
||||
@Override
|
||||
public void MainLoopUpdate() {
|
||||
if(!Main.game_paused) {
|
||||
if(Main.menu.doGameloop) {
|
||||
time += 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetTime() {
|
||||
time = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.Random;
|
|||
import shootergame.Main;
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityZombie;
|
||||
import shootergame.entity.EntityZombieArmored;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.time.GameTimer;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
|
|
@ -32,6 +33,10 @@ public class LayerGenEarth extends LayerGen
|
|||
// Get the noise generator
|
||||
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
|
||||
|
||||
if(c_pos.x == 0 && c_pos.y == 0) {
|
||||
chunk.spawnEntity(new EntityZombieArmored(new Vec2d(0, 0)));
|
||||
}
|
||||
|
||||
// Loop over the layer dimensions and create land
|
||||
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
||||
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
||||
|
|
|
|||
Loading…
Reference in New Issue