Gave rendering access to the tilestate instead of the meta
This commit is contained in:
parent
a1488570d9
commit
888e359f9c
Binary file not shown.
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 86 KiB |
Binary file not shown.
|
|
@ -15,6 +15,8 @@ import shootergame.init.Sounds;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.input.JoystickCallback;
|
import shootergame.input.JoystickCallback;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
|
import shootergame.menu.Menu;
|
||||||
|
import shootergame.menu.MenuNone;
|
||||||
import shootergame.world.World;
|
import shootergame.world.World;
|
||||||
import shootergame.world.chunk.ChunkEventHandler;
|
import shootergame.world.chunk.ChunkEventHandler;
|
||||||
import shootergame.world.layer.layergen.LayerGenCaves;
|
import shootergame.world.layer.layergen.LayerGenCaves;
|
||||||
|
|
@ -28,6 +30,8 @@ public class Main
|
||||||
public static World world;
|
public static World world;
|
||||||
public static AudioEngine audio;
|
public static AudioEngine audio;
|
||||||
public static Random rand = new Random();
|
public static Random rand = new Random();
|
||||||
|
public static Menu menu = new MenuNone();
|
||||||
|
public static boolean game_paused = false;
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
package shootergame.display;
|
package shootergame.display;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.entity.EntityInventory;
|
|
||||||
import shootergame.entity.player.EntityPlayer;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.inventory.Inventory;
|
import shootergame.inventory.Inventory;
|
||||||
import shootergame.items.ItemStack;
|
|
||||||
import shootergame.text.Text;
|
import shootergame.text.Text;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class DisplayRenderUI
|
public class DisplayRenderUI
|
||||||
|
|
@ -55,9 +54,11 @@ public class DisplayRenderUI
|
||||||
|
|
||||||
GlHelpers.end();
|
GlHelpers.end();
|
||||||
|
|
||||||
// Display the amount of ammo left
|
// Display the amount of ammo left, and the defence and gun level
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
|
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
|
||||||
|
TextureReference gunlevel_tex = Textures.UI_GUN_LEVEL;
|
||||||
|
TextureReference deflevel_tex = Textures.UI_DEFENCE_LEVEL;
|
||||||
GlHelpers.begin();
|
GlHelpers.begin();
|
||||||
|
|
||||||
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5);
|
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5);
|
||||||
|
|
@ -65,10 +66,25 @@ public class DisplayRenderUI
|
||||||
ammo_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -7.0);
|
ammo_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -7.0);
|
||||||
ammo_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -8.5);
|
ammo_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -8.5);
|
||||||
|
|
||||||
|
|
||||||
|
gunlevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -6.5);
|
||||||
|
gunlevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -5.0);
|
||||||
|
gunlevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -5.0);
|
||||||
|
gunlevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -6.5);
|
||||||
|
|
||||||
|
deflevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -4.5);
|
||||||
|
deflevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -3.0);
|
||||||
|
deflevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -3.0);
|
||||||
|
deflevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -4.5);
|
||||||
|
|
||||||
GlHelpers.end();
|
GlHelpers.end();
|
||||||
|
|
||||||
GlHelpers.translate(-8.5, -9, 0);
|
GlHelpers.translate(-8.5, -9, 0);
|
||||||
Text.render(Integer.toString(player.ammo), text_size);
|
Text.render(Integer.toString(player.ammo), text_size);
|
||||||
|
GlHelpers.translate(0, 2.5, 0);
|
||||||
|
Text.render(Integer.toString(player.gun_level), text_size);
|
||||||
|
GlHelpers.translate(0, 2, 0);
|
||||||
|
Text.render(Integer.toString(player.defence_level), text_size);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
|
|
||||||
// Display all the items in the players inventory
|
// Display all the items in the players inventory
|
||||||
|
|
@ -121,5 +137,8 @@ public class DisplayRenderUI
|
||||||
Text.render(item_active.item.getName(item_active.meta), text_size);
|
Text.render(item_active.item.getName(item_active.meta), text_size);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the loaded menu
|
||||||
|
Main.menu.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package shootergame.display.transparent;
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public interface ITransparentObject
|
public interface ITransparentObject
|
||||||
{
|
{
|
||||||
public boolean isOpaqueTile();
|
public boolean isOpaqueTile();
|
||||||
public void render(Vec2d pos, Camera camera, short meta);
|
public Vec2d getRenderOffset(TileState state);
|
||||||
public Vec2d getRenderOffset(short meta);
|
public void render(Vec2d pos, Camera camera, TileState state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package shootergame.display.transparent;
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec3d;
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
|
|
@ -9,13 +10,13 @@ class TransparentObject
|
||||||
double distance;
|
double distance;
|
||||||
ITransparentObject object;
|
ITransparentObject object;
|
||||||
Vec2d pos;
|
Vec2d pos;
|
||||||
short meta;
|
TileState state;
|
||||||
|
|
||||||
TransparentObject(ITransparentObject object, Camera camera, Vec2d pos, short meta) {
|
TransparentObject(ITransparentObject object, Camera camera, Vec2d pos, TileState state) {
|
||||||
Vec2d offset = object.getRenderOffset(meta);
|
Vec2d offset = object.getRenderOffset(state);
|
||||||
this.distance = camera.pos.distance(new Vec3d(offset.x + pos.x, offset.y + pos.y, 0));
|
this.distance = camera.pos.distance(new Vec3d(offset.x + pos.x, offset.y + pos.y, 0));
|
||||||
this.object = object;
|
this.object = object;
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.meta = meta;
|
this.state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shootergame.display.transparent;
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TransparentObjects
|
public class TransparentObjects
|
||||||
|
|
@ -11,9 +13,9 @@ public class TransparentObjects
|
||||||
objects = new TransparentObject[0];
|
objects = new TransparentObject[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(ITransparentObject object, Camera camera, Vec2d pos, short meta)
|
public static void register(ITransparentObject object, Camera camera, Vec2d pos, TileState state)
|
||||||
{
|
{
|
||||||
TransparentObject r_to = new TransparentObject(object, camera, pos, meta);
|
TransparentObject r_to = new TransparentObject(object, camera, pos, state);
|
||||||
TransparentObject[] objects_n = new TransparentObject[objects.length + 1];
|
TransparentObject[] objects_n = new TransparentObject[objects.length + 1];
|
||||||
boolean added = false;
|
boolean added = false;
|
||||||
int upto = 0;
|
int upto = 0;
|
||||||
|
|
@ -49,7 +51,7 @@ public class TransparentObjects
|
||||||
{
|
{
|
||||||
// Loop over the objects and render all of them
|
// Loop over the objects and render all of them
|
||||||
for(TransparentObject to : objects) {
|
for(TransparentObject to : objects) {
|
||||||
to.object.render(to.pos, camera, to.meta);
|
to.object.render(to.pos, camera, to.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,14 @@ public class Entity implements ITransparentObject
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
this.render(pos, camera);
|
this.render(pos, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRender(Vec2d pos, Camera camera)
|
public void doRender(Vec2d pos, Camera camera)
|
||||||
{
|
{
|
||||||
if(this.opaqueTile) {
|
if(this.opaqueTile) {
|
||||||
TransparentObjects.register(this, camera, pos, (short)0);
|
TransparentObjects.register(this, camera, pos, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
@ -133,8 +133,8 @@ public class Entity implements ITransparentObject
|
||||||
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
|
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
|
||||||
|
|
||||||
// Activate both tiles
|
// Activate both tiles
|
||||||
tile_front.tile.onActivated(layer, tpos, this, tile_front.meta);
|
tile_front.tile.onActivated(layer, tpos, this, tile_front);
|
||||||
tile_back.tile.onActivated(layer, tpos, this, tile_back.meta);
|
tile_back.tile.onActivated(layer, tpos, this, tile_back);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activateSteppedOnTile()
|
public void activateSteppedOnTile()
|
||||||
|
|
@ -144,8 +144,8 @@ public class Entity implements ITransparentObject
|
||||||
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
|
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0);
|
||||||
|
|
||||||
// Activate both tiles
|
// Activate both tiles
|
||||||
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front.meta);
|
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
|
||||||
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back.meta);
|
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,7 +211,7 @@ public class Entity implements ITransparentObject
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vec2d getRenderOffset(short meta) {
|
public Vec2d getRenderOffset(TileState state) {
|
||||||
return new Vec2d(0, 0);
|
return new Vec2d(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ public class EntityEventHandler implements IMainloopTask
|
||||||
@Override
|
@Override
|
||||||
public void MainLoopUpdate()
|
public void MainLoopUpdate()
|
||||||
{
|
{
|
||||||
|
if(Main.game_paused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update the world and spawn random entities
|
// Update the world and spawn random entities
|
||||||
Main.world.tickEntities();
|
Main.world.tickEntities();
|
||||||
Main.world.spawnRandomEntities();
|
Main.world.spawnRandomEntities();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.entity.particle.ParticleBlood;
|
||||||
|
import shootergame.entity.particle.ParticleBreak;
|
||||||
|
import shootergame.entity.particle.ParticleSmoke;
|
||||||
|
import shootergame.init.Sounds;
|
||||||
|
import shootergame.init.Tiles;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityExplosion extends Entity
|
||||||
|
{
|
||||||
|
private double damage;
|
||||||
|
private int radius;
|
||||||
|
|
||||||
|
public EntityExplosion(Vec2d pos, int radius, double damage)
|
||||||
|
{
|
||||||
|
this.pos = pos;
|
||||||
|
this.damage = damage;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
boolean killed_entities = false;
|
||||||
|
|
||||||
|
// Kill all the nearby entities
|
||||||
|
for(Entity e : layer.getNearbyEntities(pos, radius))
|
||||||
|
{
|
||||||
|
// Is this entity alive
|
||||||
|
if(e instanceof EntityAlive)
|
||||||
|
{
|
||||||
|
EntityAlive ea = (EntityAlive)e;
|
||||||
|
|
||||||
|
// Remove some health from the entity based on were the entity is
|
||||||
|
killed_entities = true;
|
||||||
|
double distance = e.pos.distance(pos);
|
||||||
|
|
||||||
|
if(distance == 0) {
|
||||||
|
ea.removeHealth(damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
ea.removeHealth(damage / distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over the tiles around the tnt
|
||||||
|
for(int ex=-radius;ex<radius;ex++) {
|
||||||
|
for(int ey=-radius;ey<radius;ey++)
|
||||||
|
{
|
||||||
|
// Calculate the distance from the explosion centre
|
||||||
|
double distance = Math.sqrt(ex*ex + ey*ey);
|
||||||
|
|
||||||
|
// Is the point within the distance from the explosion centre
|
||||||
|
if(distance < radius)
|
||||||
|
{
|
||||||
|
// Get the actual tile position
|
||||||
|
double px = ex + pos.x;
|
||||||
|
double py = ey + pos.y;
|
||||||
|
|
||||||
|
// Get the layer
|
||||||
|
Layer l = Main.world.getLayer();
|
||||||
|
|
||||||
|
// Calculate the blackened gradient
|
||||||
|
byte blackened_gradient = (byte)( Byte.MAX_VALUE - distance / radius * Byte.MAX_VALUE );
|
||||||
|
|
||||||
|
// Get the front and back tile
|
||||||
|
Vec2i tpos = new Vec2i(MathHelpers.floor(px), MathHelpers.floor(py));
|
||||||
|
TileState bts = l.getBackTile(tpos);
|
||||||
|
TileState fts = l.getFrontTile(tpos);
|
||||||
|
|
||||||
|
// Is this tile the same as the "empty" tile
|
||||||
|
TileState ets = l.layergen.getTileDestroyed();
|
||||||
|
if(bts.tile == ets.tile) {
|
||||||
|
if(bts.meta > blackened_gradient) blackened_gradient = bts.meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the tiles
|
||||||
|
if(!bts.tile.unbreakable) {
|
||||||
|
l.setBackTile(new TileState(ets.tile, blackened_gradient), tpos);
|
||||||
|
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!fts.tile.unbreakable) {
|
||||||
|
l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
|
||||||
|
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawn some blood if entities were killed
|
||||||
|
if(killed_entities)
|
||||||
|
l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py));
|
||||||
|
|
||||||
|
// Spawn some smoke
|
||||||
|
l.spawnEntity(new ParticleSmoke(new Vec2d(px, py)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Play the explosion sound
|
||||||
|
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, 0), 1);
|
||||||
|
|
||||||
|
// Kill the explosion entity
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package shootergame.entity;
|
package shootergame.entity;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.items.ItemStack;
|
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.util.math.random.RandomHelpers;
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,10 @@
|
||||||
package shootergame.entity;
|
package shootergame.entity;
|
||||||
|
|
||||||
import shootergame.Main;
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.particle.ParticleBlood;
|
|
||||||
import shootergame.entity.particle.ParticleBreak;
|
|
||||||
import shootergame.entity.particle.ParticleSmoke;
|
|
||||||
import shootergame.entity.particle.ParticleSpark;
|
import shootergame.entity.particle.ParticleSpark;
|
||||||
import shootergame.init.Sounds;
|
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.init.Tiles;
|
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.math.MathHelpers;
|
|
||||||
import shootergame.util.math.TileState;
|
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
|
||||||
import shootergame.util.math.vec.Vec3d;
|
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -24,8 +14,9 @@ public class EntityTnt extends EntityVertical
|
||||||
private double velocity_up;
|
private double velocity_up;
|
||||||
private int explode_time;
|
private int explode_time;
|
||||||
private int explode_radius;
|
private int explode_radius;
|
||||||
|
private double explode_damage;
|
||||||
|
|
||||||
public EntityTnt(Vec2d pos, double angle, int explode_radius) {
|
public EntityTnt(Vec2d pos, double angle, int explode_radius, double explode_damage) {
|
||||||
super(Textures.ENTITY_TNT, new Vec2d(0.5, 0.5));
|
super(Textures.ENTITY_TNT, new Vec2d(0.5, 0.5));
|
||||||
|
|
||||||
velocity_up = 0.01;
|
velocity_up = 0.01;
|
||||||
|
|
@ -34,6 +25,7 @@ public class EntityTnt extends EntityVertical
|
||||||
this.explode_radius = explode_radius;
|
this.explode_radius = explode_radius;
|
||||||
this.crossUnWalkable = true;
|
this.crossUnWalkable = true;
|
||||||
this.goThroughSolid = false;
|
this.goThroughSolid = false;
|
||||||
|
this.explode_damage = explode_damage;
|
||||||
|
|
||||||
// Set to 2.5 seconds
|
// Set to 2.5 seconds
|
||||||
this.explode_time = 250;
|
this.explode_time = 250;
|
||||||
|
|
@ -60,74 +52,8 @@ public class EntityTnt extends EntityVertical
|
||||||
explode_time -= 1;
|
explode_time -= 1;
|
||||||
if(explode_time < 0)
|
if(explode_time < 0)
|
||||||
{
|
{
|
||||||
// Loop over the tiles around the tnt
|
// Create an explosion
|
||||||
for(int ex=-explode_radius;ex<explode_radius;ex++) {
|
layer.spawnEntity(new EntityExplosion(pos, explode_radius, explode_damage));
|
||||||
for(int ey=-explode_radius;ey<explode_radius;ey++)
|
|
||||||
{
|
|
||||||
// Calculate the distance from the explosion centre
|
|
||||||
double distance = Math.sqrt(ex*ex + ey*ey);
|
|
||||||
|
|
||||||
// Is the point within the distance from the explosion centre
|
|
||||||
if(distance < explode_radius)
|
|
||||||
{
|
|
||||||
// Get the actual tile position
|
|
||||||
double px = ex + pos.x;
|
|
||||||
double py = ey + pos.y;
|
|
||||||
|
|
||||||
// Get the layer
|
|
||||||
Layer l = Main.world.getLayer();
|
|
||||||
|
|
||||||
// Calculate the blackened gradient
|
|
||||||
short blackened_gradient = (short)( Short.MAX_VALUE - distance/explode_radius*Short.MAX_VALUE );
|
|
||||||
|
|
||||||
// Get the front and back tile
|
|
||||||
Vec2i tpos = new Vec2i(MathHelpers.floor(px), MathHelpers.floor(py));
|
|
||||||
TileState bts = l.getBackTile(tpos);
|
|
||||||
TileState fts = l.getFrontTile(tpos);
|
|
||||||
|
|
||||||
// Is this tile the same as the "empty" tile
|
|
||||||
TileState ets = l.layergen.getTileDestroyed();
|
|
||||||
if(bts.tile == ets.tile) {
|
|
||||||
if(bts.meta > blackened_gradient) blackened_gradient = bts.meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the tiles
|
|
||||||
if(!bts.tile.unbreakable) {
|
|
||||||
l.setBackTile(new TileState(ets.tile, (short)blackened_gradient), tpos);
|
|
||||||
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!fts.tile.unbreakable) {
|
|
||||||
l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
|
|
||||||
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean killed_entities = false;
|
|
||||||
|
|
||||||
// Kill all the nearby entities
|
|
||||||
for(Entity e : layer.getNearbyEntities(pos, explode_radius))
|
|
||||||
{
|
|
||||||
// Is this entity alive
|
|
||||||
if(e instanceof EntityAlive)
|
|
||||||
{
|
|
||||||
// Add 1000 damage to the entity
|
|
||||||
killed_entities = true;
|
|
||||||
((EntityAlive)e).removeHealth(10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn some blood if entities were killed
|
|
||||||
if(killed_entities)
|
|
||||||
l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py));
|
|
||||||
|
|
||||||
// Spawn some smoke
|
|
||||||
l.spawnEntity(new ParticleSmoke(new Vec2d(px, py)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Play the explosion sound
|
|
||||||
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, height), 1);
|
|
||||||
|
|
||||||
// Delete the entity
|
// Delete the entity
|
||||||
kill();
|
kill();
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive
|
||||||
|
|
||||||
// Move forward towards the player
|
// Move forward towards the player
|
||||||
this.angle = Math.toDegrees(angle) + 180;
|
this.angle = Math.toDegrees(angle) + 180;
|
||||||
this.angle += noise_movement.eval(time, 0)*60;
|
this.angle += noise_movement.eval(time, 0)*80;
|
||||||
this.moveForward();
|
this.moveForward();
|
||||||
|
|
||||||
if(noise_gun_fire.eval(time, 0) > 0)
|
if(noise_gun_fire.eval(time, 0) > 0)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityZombieBomber extends EntityVertical implements EntityAlive
|
||||||
|
{
|
||||||
|
private int time = 0;
|
||||||
|
private OpenSimplexNoise noise_movement;
|
||||||
|
private double health = 100;
|
||||||
|
private double max_health = 100;
|
||||||
|
|
||||||
|
public EntityZombieBomber(Vec2d pos) {
|
||||||
|
super(Textures.ENTITY_ZOMBIE_BOMBER, new Vec2d(1, 1));
|
||||||
|
|
||||||
|
this.noise_movement = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.pos = pos;
|
||||||
|
|
||||||
|
this.goThroughSolid = false;
|
||||||
|
this.crossUnWalkable = false;
|
||||||
|
this.isSolid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void explode(Layer layer)
|
||||||
|
{
|
||||||
|
kill();
|
||||||
|
layer.spawnEntity(new EntityExplosion(pos, 6, 5000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveBackward() {
|
||||||
|
super.moveBackward(0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveForward() {
|
||||||
|
super.moveForward(0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
// Explode if the zombie is dead
|
||||||
|
if(health <= 0) {
|
||||||
|
this.explode(layer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the angle between the player and the zombie
|
||||||
|
double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y);
|
||||||
|
|
||||||
|
// Move forward towards the player
|
||||||
|
this.angle = Math.toDegrees(angle) + 180;
|
||||||
|
this.angle += noise_movement.eval(time, 0)*80;
|
||||||
|
this.moveForward();
|
||||||
|
|
||||||
|
// Explode if the zombie is in radius of the player
|
||||||
|
if(Main.player.pos.squareDistance(pos) < 3) {
|
||||||
|
this.explode(layer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase time
|
||||||
|
time += 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addHealth(double amount) {
|
||||||
|
this.health += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeHealth(double amount) {
|
||||||
|
this.health -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetHealth() {
|
||||||
|
this.health = max_health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHealth() {
|
||||||
|
this.health = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double maxHealth() {
|
||||||
|
return max_health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(double health) {
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import shootergame.display.Camera;
|
||||||
import shootergame.entity.EntityVertical;
|
import shootergame.entity.EntityVertical;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
@ -13,10 +14,18 @@ public class ParticleSmoke extends EntityVertical
|
||||||
{
|
{
|
||||||
double height = 0;
|
double height = 0;
|
||||||
double opacity = 1;
|
double opacity = 1;
|
||||||
|
double height_speed;
|
||||||
|
double disappear_speed;
|
||||||
|
|
||||||
public ParticleSmoke(Vec2d pos) {
|
public ParticleSmoke(Vec2d pos) {
|
||||||
super(Textures.PARTICLE_SMOKE_RANDOM.getTexture(), new Vec2d(1, 1));
|
super(Textures.PARTICLE_SMOKE_RANDOM.getTexture(), new Vec2d(1, 1));
|
||||||
this.pos = pos;
|
|
||||||
|
this.pos = new Vec2d(
|
||||||
|
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5 + pos.x,
|
||||||
|
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5 + pos.y);
|
||||||
|
|
||||||
|
height_speed = (rand.nextDouble() + 0.5) / 100;
|
||||||
|
disappear_speed = (rand.nextDouble() + 0.5) / 250;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -38,8 +47,8 @@ public class ParticleSmoke extends EntityVertical
|
||||||
kill();
|
kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
height += 0.001;
|
height += height_speed;
|
||||||
opacity -= 0.001;
|
opacity -= disappear_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,12 @@ import shootergame.entity.EntityBullet;
|
||||||
import shootergame.entity.EntityInventory;
|
import shootergame.entity.EntityInventory;
|
||||||
import shootergame.entity.EntityItem;
|
import shootergame.entity.EntityItem;
|
||||||
import shootergame.entity.EntityVertical;
|
import shootergame.entity.EntityVertical;
|
||||||
|
import shootergame.init.Items;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.inventory.Inventory;
|
import shootergame.inventory.Inventory;
|
||||||
import shootergame.items.ItemStack;
|
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.util.math.MathHelpers;
|
import shootergame.util.math.MathHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
|
|
@ -41,6 +42,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
||||||
|
|
||||||
public int ammo = 1000;
|
public int ammo = 1000;
|
||||||
|
|
||||||
|
public int defence_level = 0;
|
||||||
|
public int gun_level = 0;
|
||||||
|
|
||||||
private static final Vec2d size = new Vec2d(1, 1);
|
private static final Vec2d size = new Vec2d(1, 1);
|
||||||
|
|
||||||
public EntityPlayer() {
|
public EntityPlayer() {
|
||||||
|
|
@ -60,9 +64,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
||||||
@Override
|
@Override
|
||||||
public void tick(Chunk chunk, Layer layer)
|
public void tick(Chunk chunk, Layer layer)
|
||||||
{
|
{
|
||||||
|
// Handle player deaths
|
||||||
// Player deaths
|
if(health <= 0)
|
||||||
if(health < 0)
|
|
||||||
{
|
{
|
||||||
if(Cheats.god_mode) {
|
if(Cheats.god_mode) {
|
||||||
this.resetHealth();
|
this.resetHealth();
|
||||||
|
|
@ -162,7 +165,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
||||||
if(dead || in_animation) return;
|
if(dead || in_animation) return;
|
||||||
|
|
||||||
bullet_frequency += 1;
|
bullet_frequency += 1;
|
||||||
bullet_frequency %= 10;
|
bullet_frequency %= 10 - gun_level*2;
|
||||||
|
|
||||||
// Is there enough ammo and are the bullets at the right frequency
|
// Is there enough ammo and are the bullets at the right frequency
|
||||||
if(bullet_frequency == 0 && ammo > 0)
|
if(bullet_frequency == 0 && ammo > 0)
|
||||||
|
|
@ -193,8 +196,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHealth(double amount) {
|
public void removeHealth(double amount) {
|
||||||
|
amount = amount * amount / (amount + defence_level*2);
|
||||||
health -= amount;
|
health -= amount;
|
||||||
if(health < 0) health = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@ public class Textures
|
||||||
public static final TextureReference UI_ITEM_SLOTS = texmap.getTextureReference(0, 12, 13, 15);
|
public static final TextureReference UI_ITEM_SLOTS = texmap.getTextureReference(0, 12, 13, 15);
|
||||||
public static final TextureReference UI_ACTIVE_SLOT = texmap.getTextureReference(12, 14, 13, 15);
|
public static final TextureReference UI_ACTIVE_SLOT = texmap.getTextureReference(12, 14, 13, 15);
|
||||||
|
|
||||||
|
public static final TextureReference UI_DEFENCE_LEVEL = texmap.getTextureReference(0, 1, 15, 16);
|
||||||
|
public static final TextureReference UI_GUN_LEVEL = texmap.getTextureReference(1, 2, 15, 16);
|
||||||
|
|
||||||
public static final TextureReference ITEM_HEALTH_POTION = texmap.getTextureReference(0, 1, 5, 6);
|
public static final TextureReference ITEM_HEALTH_POTION = texmap.getTextureReference(0, 1, 5, 6);
|
||||||
public static final TextureReference ITEM_AMMO_BOX = texmap.getTextureReference(1, 2, 5, 6);
|
public static final TextureReference ITEM_AMMO_BOX = texmap.getTextureReference(1, 2, 5, 6);
|
||||||
public static final TextureReference ITEM_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5);
|
public static final TextureReference ITEM_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5);
|
||||||
|
|
@ -79,6 +82,14 @@ public class Textures
|
||||||
texmap.getTextureReference(3, 4, 3, 4)
|
texmap.getTextureReference(3, 4, 3, 4)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Zombie Bomber
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE_BOMBER = new AnimationReference(10,
|
||||||
|
texmap.getTextureReference(2, 3, 15, 16),
|
||||||
|
texmap.getTextureReference(3, 4, 15, 16),
|
||||||
|
texmap.getTextureReference(4, 5, 15, 16),
|
||||||
|
texmap.getTextureReference(5, 6, 15, 16)
|
||||||
|
);
|
||||||
|
|
||||||
// Water
|
// Water
|
||||||
public static final TextureReference TILE_WATER = new AnimationReference(10,
|
public static final TextureReference TILE_WATER = new AnimationReference(10,
|
||||||
texmap.getTextureReference(0, 1, 8, 9),
|
texmap.getTextureReference(0, 1, 8, 9),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import org.lwjgl.glfw.GLFWJoystickCallbackI;
|
||||||
|
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
|
import shootergame.menu.MenuNone;
|
||||||
|
import shootergame.menu.MenuPause;
|
||||||
import shootergame.util.math.MathHelpers;
|
import shootergame.util.math.MathHelpers;
|
||||||
|
|
||||||
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
|
|
@ -22,6 +24,8 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
|
|
||||||
private static boolean hotbar_l = false;
|
private static boolean hotbar_l = false;
|
||||||
private static boolean hotbar_r = false;
|
private static boolean hotbar_r = false;
|
||||||
|
|
||||||
|
private static boolean startButton_last = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(int jid, int event)
|
public void invoke(int jid, int event)
|
||||||
|
|
@ -146,91 +150,116 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
dpad_down = buttons.get(14) == 1 || buttons.get(17) == 1 || dpad_down;
|
dpad_down = buttons.get(14) == 1 || buttons.get(17) == 1 || dpad_down;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the left stick moved into a position (movement stick)
|
// Only check for these input commands if the game isn't paused
|
||||||
if(left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3)
|
if(!Main.game_paused)
|
||||||
{
|
{
|
||||||
// Get the the angle
|
// Is the left stick moved into a position (movement stick)
|
||||||
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
|
if(left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3)
|
||||||
|
|
||||||
// Move the player in the left sticks angle
|
|
||||||
Main.player.moveTowards(angle);
|
|
||||||
|
|
||||||
// Set the players moving to true
|
|
||||||
Main.player.moving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the players moving to false
|
|
||||||
else Main.player.moving = false;
|
|
||||||
|
|
||||||
// Is the right x axis stick moved into a position (camera stick)
|
|
||||||
if(right_x > 0.3 || right_x < -0.3) {
|
|
||||||
Main.player.angle += right_x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gun trigger
|
|
||||||
if(right_trigger > 0.3) {
|
|
||||||
Main.player.fireBullet(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Item trigger
|
|
||||||
if(left_trigger > 0.3) {
|
|
||||||
if(!activateItem_last)
|
|
||||||
{
|
{
|
||||||
activateItem_last = true;
|
// Get the the angle
|
||||||
Main.player.activateItem();
|
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
|
||||||
|
|
||||||
|
// Move the player in the left sticks angle
|
||||||
|
Main.player.moveTowards(angle);
|
||||||
|
|
||||||
|
// Set the players moving to true
|
||||||
|
Main.player.moving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the players moving to false
|
||||||
|
else Main.player.moving = false;
|
||||||
|
|
||||||
|
// Is the right x axis stick moved into a position (camera stick)
|
||||||
|
if(right_x > 0.3 || right_x < -0.3) {
|
||||||
|
Main.player.angle += right_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gun trigger
|
||||||
|
if(right_trigger > 0.3) {
|
||||||
|
Main.player.fireBullet(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Item trigger
|
||||||
|
if(left_trigger > 0.3) {
|
||||||
|
if(!activateItem_last)
|
||||||
|
{
|
||||||
|
activateItem_last = true;
|
||||||
|
Main.player.activateItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
activateItem_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_left) {
|
||||||
|
if(!hotbar_l) {
|
||||||
|
hotbar_l = true;
|
||||||
|
Main.player.inventory_hand -= 1;
|
||||||
|
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(hotbar_l) {
|
||||||
|
hotbar_l = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_right) {
|
||||||
|
if(!hotbar_r) {
|
||||||
|
hotbar_r = true;
|
||||||
|
Main.player.inventory_hand += 1;
|
||||||
|
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(hotbar_r) {
|
||||||
|
hotbar_r = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate tile
|
||||||
|
if(button_x) {
|
||||||
|
if(!activateTile_last) {
|
||||||
|
Main.player.activateTile();
|
||||||
|
activateTile_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(activateTile_last) {
|
||||||
|
activateTile_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop item
|
||||||
|
if(button_b) {
|
||||||
|
if(!dropItem_last) {
|
||||||
|
Main.player.dropItem();
|
||||||
|
dropItem_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(dropItem_last) {
|
||||||
|
dropItem_last = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
// Pause and unpause the game
|
||||||
activateItem_last = false;
|
if(button_start) {
|
||||||
}
|
if(!startButton_last) {
|
||||||
|
startButton_last = true;
|
||||||
if(shoulder_left) {
|
|
||||||
if(!hotbar_l) {
|
if(Main.game_paused) {
|
||||||
hotbar_l = true;
|
Main.menu = new MenuNone();
|
||||||
Main.player.inventory_hand -= 1;
|
Main.game_paused = false;
|
||||||
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Main.menu = new MenuPause();
|
||||||
|
Main.game_paused = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(hotbar_l) {
|
else if(startButton_last) {
|
||||||
hotbar_l = false;
|
startButton_last = false;
|
||||||
}
|
|
||||||
|
|
||||||
if(shoulder_right) {
|
|
||||||
if(!hotbar_r) {
|
|
||||||
hotbar_r = true;
|
|
||||||
Main.player.inventory_hand += 1;
|
|
||||||
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(hotbar_r) {
|
|
||||||
hotbar_r = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activate tile
|
|
||||||
if(button_x) {
|
|
||||||
if(!activateTile_last) {
|
|
||||||
Main.player.activateTile();
|
|
||||||
activateTile_last = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(activateTile_last) {
|
|
||||||
activateTile_last = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop item
|
|
||||||
if(button_b) {
|
|
||||||
if(!dropItem_last) {
|
|
||||||
Main.player.dropItem();
|
|
||||||
dropItem_last = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(dropItem_last) {
|
|
||||||
dropItem_last = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
package shootergame.input;
|
package shootergame.input;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
|
import shootergame.menu.MenuNone;
|
||||||
|
import shootergame.menu.MenuPause;
|
||||||
|
|
||||||
public class KeyCallback implements GLFWKeyCallbackI
|
public class KeyCallback implements GLFWKeyCallbackI
|
||||||
{
|
{
|
||||||
|
private boolean itemUse_last = false;
|
||||||
|
private boolean itemDrop_last = false;
|
||||||
|
private boolean esc_last = false;
|
||||||
|
private boolean action_last = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, int key, int scancode, int action, int mods)
|
public void invoke(long window, int key, int scancode, int action, int mods)
|
||||||
|
|
@ -20,24 +21,103 @@ public class KeyCallback implements GLFWKeyCallbackI
|
||||||
|
|
||||||
boolean pressed = ! ( action == GLFW_RELEASE );
|
boolean pressed = ! ( action == GLFW_RELEASE );
|
||||||
|
|
||||||
if(key == GLFW_KEY_W) {
|
if(!Main.game_paused && !Main.player.dead && !Main.player.in_animation)
|
||||||
Main.player.MOVE_FORWARD = pressed;
|
{
|
||||||
|
if(key == GLFW_KEY_W) {
|
||||||
|
Main.player.MOVE_FORWARD = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_S) {
|
||||||
|
Main.player.MOVE_BACKWARD = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_A) {
|
||||||
|
Main.player.MOVE_LEFT = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_D) {
|
||||||
|
Main.player.MOVE_RIGHT = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_ENTER) {
|
||||||
|
Main.player.GUN = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_1 && pressed) {
|
||||||
|
Main.player.inventory_hand = 0;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_2 && pressed) {
|
||||||
|
Main.player.inventory_hand = 1;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_3 && pressed) {
|
||||||
|
Main.player.inventory_hand = 2;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_4 && pressed) {
|
||||||
|
Main.player.inventory_hand = 3;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_5 && pressed) {
|
||||||
|
Main.player.inventory_hand = 4;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_6 && pressed) {
|
||||||
|
Main.player.inventory_hand = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_RIGHT_SHIFT) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!itemUse_last) {
|
||||||
|
itemUse_last = true;
|
||||||
|
Main.player.activateItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(itemUse_last) {
|
||||||
|
itemUse_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_E) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!action_last) {
|
||||||
|
action_last = true;
|
||||||
|
Main.player.activateTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action_last) {
|
||||||
|
action_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_Q) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!itemDrop_last) {
|
||||||
|
itemDrop_last = true;
|
||||||
|
Main.player.dropItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(itemDrop_last) {
|
||||||
|
itemDrop_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == GLFW_KEY_S) {
|
if(key == GLFW_KEY_ESCAPE) {
|
||||||
Main.player.MOVE_BACKWARD = pressed;
|
if(pressed) {
|
||||||
}
|
if(!esc_last) {
|
||||||
|
esc_last = true;
|
||||||
if(key == GLFW_KEY_A) {
|
|
||||||
Main.player.MOVE_LEFT = pressed;
|
if(Main.game_paused) {
|
||||||
}
|
Main.game_paused = false;
|
||||||
|
Main.menu = new MenuNone();
|
||||||
if(key == GLFW_KEY_D) {
|
}
|
||||||
Main.player.MOVE_RIGHT = pressed;
|
|
||||||
}
|
else {
|
||||||
|
Main.game_paused = true;
|
||||||
if(key == GLFW_KEY_ENTER) {
|
Main.menu = new MenuPause();
|
||||||
Main.player.GUN = pressed;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(esc_last) {
|
||||||
|
esc_last = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package shootergame.inventory;
|
package shootergame.inventory;
|
||||||
|
|
||||||
import shootergame.items.ItemStack;
|
import shootergame.util.math.ItemStack;
|
||||||
|
|
||||||
public interface IInventory
|
public interface IInventory
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package shootergame.inventory;
|
package shootergame.inventory;
|
||||||
|
|
||||||
import shootergame.items.ItemStack;
|
import shootergame.util.math.ItemStack;
|
||||||
|
|
||||||
public class Inventory implements IInventory
|
public class Inventory implements IInventory
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import shootergame.entity.EntityInventory;
|
||||||
import shootergame.inventory.Inventory;
|
import shootergame.inventory.Inventory;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.items;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.player.EntityPlayer;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package shootergame.items;
|
package shootergame.items;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -15,10 +17,12 @@ public class ItemDefenceUpgrade extends Item
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
||||||
super.onAction(stack, layer, chunk, entity);
|
{
|
||||||
|
if(Main.player.defence_level < stack.meta) {
|
||||||
|
super.onAction(stack, layer, chunk, entity);
|
||||||
|
Main.player.defence_level = stack.meta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package shootergame.items;
|
package shootergame.items;
|
||||||
|
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
package shootergame.items;
|
package shootergame.items;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
public class ItemGunUpgrade extends Item
|
public class ItemGunUpgrade extends Item
|
||||||
{
|
{
|
||||||
|
|
@ -11,6 +16,15 @@ public class ItemGunUpgrade extends Item
|
||||||
this.texture = Textures.ITEM_GUN_UPGRADE;
|
this.texture = Textures.ITEM_GUN_UPGRADE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
||||||
|
{
|
||||||
|
if(Main.player.gun_level < stack.meta) {
|
||||||
|
super.onAction(stack, layer, chunk, entity);
|
||||||
|
Main.player.gun_level = stack.meta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName(short meta) {
|
public String getName(short meta) {
|
||||||
return "Gun Upgrade level "+meta;
|
return "Gun Upgrade level "+meta;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.items;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityAlive;
|
import shootergame.entity.EntityAlive;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.items;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityTnt;
|
import shootergame.entity.EntityTnt;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.ItemStack;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ public class ItemTnt extends Item
|
||||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||||
super.onAction(stack, layer, chunk, entity);
|
super.onAction(stack, layer, chunk, entity);
|
||||||
|
|
||||||
layer.spawnEntity(new EntityTnt(entity.pos.copy(), entity.angle, stack.meta));
|
layer.spawnEntity(new EntityTnt(entity.pos.copy(), entity.angle, stack.meta, 5000));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package shootergame.menu;
|
||||||
|
|
||||||
|
public abstract class Menu
|
||||||
|
{
|
||||||
|
public boolean doGameloop = false;
|
||||||
|
|
||||||
|
public abstract void render();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package shootergame.menu;
|
||||||
|
|
||||||
|
public class MenuNone extends Menu
|
||||||
|
{
|
||||||
|
public MenuNone() {
|
||||||
|
this.doGameloop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package shootergame.menu;
|
||||||
|
|
||||||
|
import shootergame.text.Text;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class MenuPause extends Menu
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void render()
|
||||||
|
{
|
||||||
|
// Render the screen darkening of the gameplay
|
||||||
|
GlHelpers.disableTexture2d();
|
||||||
|
GlHelpers.color4(0, 0, 0, 0.5);
|
||||||
|
GlHelpers.begin();
|
||||||
|
GlHelpers.vertex2(-10, -10);
|
||||||
|
GlHelpers.vertex2(-10, 10);
|
||||||
|
GlHelpers.vertex2(10, 10);
|
||||||
|
GlHelpers.vertex2(10, -10);
|
||||||
|
GlHelpers.end();
|
||||||
|
GlHelpers.color4(1, 1, 1, 1);
|
||||||
|
GlHelpers.enableTexture2d();
|
||||||
|
|
||||||
|
// Render some text to say the game is paused
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(-2, 1, 0);
|
||||||
|
Text.render("Game Paused", new Vec2d(1, 0.4));
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -29,17 +29,17 @@ public class Tile implements ITransparentObject
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRender(Vec2d pos, Camera camera, short meta)
|
public void doRender(Vec2d pos, Camera camera, TileState state)
|
||||||
{
|
{
|
||||||
if(this.opaqueTile) {
|
if(this.opaqueTile) {
|
||||||
TransparentObjects.register(this, camera, pos, meta);
|
TransparentObjects.register(this, camera, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
this.render(pos, camera, meta);
|
this.render(pos, camera, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,18 +48,18 @@ public class Tile implements ITransparentObject
|
||||||
return this.opaqueTile;
|
return this.opaqueTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta) {
|
public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vec2d getRenderOffset(short meta) {
|
public Vec2d getRenderOffset(TileState ts) {
|
||||||
return new Vec2d(0.5, 0.5);
|
return new Vec2d(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileState getDefaultState() {
|
public TileState getDefaultState() {
|
||||||
return new TileState(this, (short)0);
|
return new TileState(this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivated(Layer layer, Vec2i tpos, Entity entity, short meta) {
|
public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityItem;
|
import shootergame.entity.EntityItem;
|
||||||
import shootergame.init.Items;
|
import shootergame.init.Items;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.items.ItemStack;
|
import shootergame.util.math.ItemStack;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.random.RandomHelpers;
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
@ -32,13 +33,13 @@ public class TileChest extends TileVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivated(Layer layer, Vec2i tpos, Entity entity, short meta) {
|
public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
|
||||||
super.onActivated(layer, tpos, entity, meta);
|
super.onActivated(layer, tpos, entity, state);
|
||||||
|
|
||||||
Chunk chunk = layer.getChunk(tpos);
|
Chunk chunk = layer.getChunk(tpos);
|
||||||
Random rand = Main.rand;
|
Random rand = Main.rand;
|
||||||
|
|
||||||
if(meta == CHEST_CAVES)
|
if(state.meta == CHEST_CAVES)
|
||||||
{
|
{
|
||||||
// Ammo
|
// Ammo
|
||||||
spawnItem(chunk, tpos, new ItemStack(Items.AMMO, RandomHelpers.randrange(rand, 100), (short)1));
|
spawnItem(chunk, tpos, new ItemStack(Items.AMMO, RandomHelpers.randrange(rand, 100), (short)1));
|
||||||
|
|
@ -47,7 +48,7 @@ public class TileChest extends TileVertical
|
||||||
spawnItem(chunk, tpos, new ItemStack(Items.TNT, RandomHelpers.randrange(rand, 2), (short)10));
|
spawnItem(chunk, tpos, new ItemStack(Items.TNT, RandomHelpers.randrange(rand, 2), (short)10));
|
||||||
|
|
||||||
// Health potions
|
// Health potions
|
||||||
spawnItem(chunk, tpos, new ItemStack(Items.HEALTH_POTION, RandomHelpers.randrange(rand, 10), (short)20));
|
spawnItem(chunk, tpos, new ItemStack(Items.HEALTH_POTION, RandomHelpers.randrange(rand, 4), (short)50));
|
||||||
|
|
||||||
// Gun upgrade
|
// Gun upgrade
|
||||||
if(RandomHelpers.randrange(rand, 5) == 0) {
|
if(RandomHelpers.randrange(rand, 5) == 0) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileDirt extends TileFlat
|
public class TileDirt extends TileFlat
|
||||||
|
|
@ -13,9 +14,9 @@ public class TileDirt extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.color4(1, 1, 1, (Short.MAX_VALUE - (double)meta) / Short.MAX_VALUE);
|
GlHelpers.color4(1, 1, 1, (Byte.MAX_VALUE - (double)state.meta) / Byte.MAX_VALUE);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.color4(1, 1, 1, 1);
|
GlHelpers.color4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import shootergame.display.Camera;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.IHasTexture;
|
import shootergame.util.gl.texture.IHasTexture;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileFlat extends Tile implements IHasTexture
|
public class TileFlat extends Tile implements IHasTexture
|
||||||
|
|
@ -16,10 +17,10 @@ public class TileFlat extends Tile implements IHasTexture
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta)
|
public void render(Vec2d pos, Camera camera, TileState state)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
|
|
||||||
// Render the tile
|
// Render the tile
|
||||||
GlHelpers.begin();
|
GlHelpers.begin();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import shootergame.Main;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.player.EntityPlayer;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
@ -21,10 +22,10 @@ public class TileLadderUp extends TileVertical
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivated(Layer layer, Vec2i pos, Entity entity, short meta)
|
public void onActivated(Layer layer, Vec2i pos, Entity entity, TileState state)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.onActivated(layer, pos, entity, meta);
|
super.onActivated(layer, pos, entity, state);
|
||||||
|
|
||||||
// Is the entity the player
|
// Is the entity the player
|
||||||
if(entity == Main.player)
|
if(entity == Main.player)
|
||||||
|
|
@ -56,7 +57,7 @@ public class TileLadderUp extends TileVertical
|
||||||
if(player.height >= 6 && movingPlayer == 0)
|
if(player.height >= 6 && movingPlayer == 0)
|
||||||
{
|
{
|
||||||
movingPlayer = 1;
|
movingPlayer = 1;
|
||||||
Main.world.setLayerID(meta);
|
Main.world.setLayerID(state.meta);
|
||||||
player.height = -1;
|
player.height = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileLava extends TileFlat
|
public class TileLava extends TileFlat
|
||||||
|
|
@ -15,10 +16,10 @@ public class TileLava extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
GlHelpers.translate(0, 0, 0.001);
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileLavaFlow extends TileFlat
|
public class TileLavaFlow extends TileFlat
|
||||||
|
|
@ -13,10 +14,10 @@ public class TileLavaFlow extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
GlHelpers.translate(0, 0, 0.001);
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ public class TilePortalDown extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivated(Layer layer, Vec2i pos, Entity entity, short meta)
|
public void onActivated(Layer layer, Vec2i pos, Entity entity, TileState state)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.onActivated(layer, pos, entity, meta);
|
super.onActivated(layer, pos, entity, state);
|
||||||
|
|
||||||
// Is the entity the player
|
// Is the entity the player
|
||||||
if(entity == Main.player)
|
if(entity == Main.player)
|
||||||
|
|
@ -67,7 +67,7 @@ public class TilePortalDown extends TileFlat
|
||||||
Layer layer = Main.world.getLayer();
|
Layer layer = Main.world.getLayer();
|
||||||
TileState ets = layer.layergen.getTileDestroyed();
|
TileState ets = layer.layergen.getTileDestroyed();
|
||||||
if(layer.getBackTile(pos).tile != ets.tile) {
|
if(layer.getBackTile(pos).tile != ets.tile) {
|
||||||
layer.setBackTile(new TileState(ets.tile, (short)0), pos);
|
layer.setBackTile(ets, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit out of this function if there is an empty space under the player
|
// Exit out of this function if there is an empty space under the player
|
||||||
|
|
@ -85,7 +85,7 @@ public class TilePortalDown extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
layer.setBackTile(new TileState(ets.tile, (short)0), check_pos);
|
layer.setBackTile(new TileState(ets.tile, 0), check_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ public class TilePortalDown extends TileFlat
|
||||||
if(player.height < -1 && movingPlayer == 0)
|
if(player.height < -1 && movingPlayer == 0)
|
||||||
{
|
{
|
||||||
movingPlayer = 1;
|
movingPlayer = 1;
|
||||||
Main.world.setLayerID(meta);
|
Main.world.setLayerID(state.meta);
|
||||||
player.height = 6;
|
player.height = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileStone extends TileFlat
|
public class TileStone extends TileFlat
|
||||||
|
|
@ -13,9 +14,9 @@ public class TileStone extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.color4(1, 1, 1, (Short.MAX_VALUE - (double)meta) / Short.MAX_VALUE);
|
GlHelpers.color4(1, 1, 1, (Byte.MAX_VALUE - (double)state.meta) / Byte.MAX_VALUE);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.color4(1, 1, 1, 1);
|
GlHelpers.color4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import shootergame.display.Camera;
|
||||||
import shootergame.util.gl.VerticalRender;
|
import shootergame.util.gl.VerticalRender;
|
||||||
import shootergame.util.gl.texture.IHasTexture;
|
import shootergame.util.gl.texture.IHasTexture;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileVertical extends Tile implements IHasTexture
|
public class TileVertical extends Tile implements IHasTexture
|
||||||
|
|
@ -20,8 +21,8 @@ public class TileVertical extends Tile implements IHasTexture
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
VerticalRender.render(pos, camera, tex, size);
|
VerticalRender.render(pos, camera, tex, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import shootergame.entity.Entity;
|
||||||
import shootergame.entity.particle.ParticleWater;
|
import shootergame.entity.particle.ParticleWater;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
|
|
@ -19,18 +20,18 @@ public class TileWater extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
GlHelpers.translate(0, 0, 0.001);
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta)
|
public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.onWalkedOn(chunk, layer, pos, entity, meta);
|
super.onWalkedOn(chunk, layer, pos, entity, state);
|
||||||
|
|
||||||
// Spawn some water particles
|
// Spawn some water particles
|
||||||
for(int i=0;i<4;i++) {
|
for(int i=0;i<4;i++) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class TileWaterFlow extends TileFlat
|
public class TileWaterFlow extends TileFlat
|
||||||
|
|
@ -13,10 +14,10 @@ public class TileWaterFlow extends TileFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera, short meta) {
|
public void render(Vec2d pos, Camera camera, TileState state) {
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
GlHelpers.translate(0, 0, 0.001);
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
super.render(pos, camera, meta);
|
super.render(pos, camera, state);
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package shootergame.items;
|
package shootergame.util.math;
|
||||||
|
|
||||||
import shootergame.init.Items;
|
import shootergame.init.Items;
|
||||||
|
import shootergame.items.Item;
|
||||||
|
|
||||||
public class ItemStack
|
public class ItemStack
|
||||||
{
|
{
|
||||||
|
|
@ -2,20 +2,42 @@ package shootergame.util.math;
|
||||||
|
|
||||||
import shootergame.init.Tiles;
|
import shootergame.init.Tiles;
|
||||||
import shootergame.tiles.Tile;
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.vec.Vec3i;
|
||||||
|
|
||||||
public class TileState
|
public class TileState
|
||||||
{
|
{
|
||||||
public static final TileState EMPTY = new TileState(Tiles.VOID, (short)0);
|
public static final TileState EMPTY = new TileState(Tiles.VOID, 0);
|
||||||
|
|
||||||
public Tile tile;
|
public Tile tile;
|
||||||
public short meta;
|
public byte meta;
|
||||||
|
public Vec3i light = new Vec3i(0, 0, 0);
|
||||||
|
|
||||||
public TileState(Tile tile, short meta) {
|
public TileState(Tile tile, byte meta) {
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
this.meta = meta;
|
this.meta = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileState(Tile tile, int meta) {
|
||||||
|
this(tile, (byte)meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileState withLightLevel(Vec3i light) {
|
||||||
|
TileState ts = new TileState(tile, meta);
|
||||||
|
ts.light = light;
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileState withLightLevel(int r, int g, int b) {
|
||||||
|
TileState ts = new TileState(tile, meta);
|
||||||
|
ts.light = new Vec3i(r, g, b);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
public TileState withMeta(short meta) {
|
public TileState withMeta(short meta) {
|
||||||
return new TileState(tile, meta);
|
return new TileState(tile, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileState withMeta(int meta) {
|
||||||
|
return this.withMeta((short)meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.world;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.world.chunk.ChunkEventHandler;
|
import shootergame.world.chunk.ChunkEventHandler;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,11 @@ public class Chunk
|
||||||
|
|
||||||
private Tile tiles_back[] = new Tile[CHUNK_INDEX];
|
private Tile tiles_back[] = new Tile[CHUNK_INDEX];
|
||||||
private Tile tiles_front[] = new Tile[CHUNK_INDEX];
|
private Tile tiles_front[] = new Tile[CHUNK_INDEX];
|
||||||
private short tiles_front_meta[] = new short[CHUNK_INDEX];
|
private byte tiles_front_meta[] = new byte[CHUNK_INDEX];
|
||||||
private short tiles_back_meta[] = new short[CHUNK_INDEX];
|
private byte tiles_back_meta[] = new byte[CHUNK_INDEX];
|
||||||
|
private byte tiles_lighting_r[] = new byte[CHUNK_INDEX];
|
||||||
|
private byte tiles_lighting_g[] = new byte[CHUNK_INDEX];
|
||||||
|
private byte tiles_lighting_b[] = new byte[CHUNK_INDEX];
|
||||||
public ArrayList<Entity> entities = new ArrayList<Entity>();
|
public ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
private Layer layer;
|
private Layer layer;
|
||||||
private Vec2i c_pos;
|
private Vec2i c_pos;
|
||||||
|
|
@ -43,6 +46,11 @@ public class Chunk
|
||||||
// Make all these tiles void
|
// Make all these tiles void
|
||||||
tiles_back[i] = Tiles.VOID;
|
tiles_back[i] = Tiles.VOID;
|
||||||
tiles_front[i] = Tiles.VOID;
|
tiles_front[i] = Tiles.VOID;
|
||||||
|
tiles_back_meta[i] = 0;
|
||||||
|
tiles_front_meta[i] = 0;
|
||||||
|
tiles_lighting_b[i] = 0;
|
||||||
|
tiles_lighting_g[i] = 0;
|
||||||
|
tiles_lighting_r[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,8 +63,10 @@ public class Chunk
|
||||||
Vec2i t_pos = Vec2i.fromId(CHUNK_SIZE, i);
|
Vec2i t_pos = Vec2i.fromId(CHUNK_SIZE, i);
|
||||||
|
|
||||||
// Render the tiles
|
// Render the tiles
|
||||||
tiles_back[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tiles_back_meta[i]);
|
TileState tsb = getBackTile(i);
|
||||||
tiles_front[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tiles_front_meta[i]);
|
TileState tsf = getFrontTile(i);
|
||||||
|
tiles_back[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tsb);
|
||||||
|
tiles_front[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera, tsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render all the entities
|
// Render all the entities
|
||||||
|
|
@ -126,6 +136,11 @@ public class Chunk
|
||||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
int id = cpos.getId(CHUNK_SIZE);
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
setBackTile(tile, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackTile(TileState tile, int id)
|
||||||
|
{
|
||||||
// Set the back tile
|
// Set the back tile
|
||||||
this.tiles_back[id] = tile.tile;
|
this.tiles_back[id] = tile.tile;
|
||||||
this.tiles_back_meta[id] = tile.meta;
|
this.tiles_back_meta[id] = tile.meta;
|
||||||
|
|
@ -139,6 +154,11 @@ public class Chunk
|
||||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
int id = cpos.getId(CHUNK_SIZE);
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
setFrontTile(tile, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrontTile(TileState tile, int id)
|
||||||
|
{
|
||||||
// Set the front tile
|
// Set the front tile
|
||||||
this.tiles_front[id] = tile.tile;
|
this.tiles_front[id] = tile.tile;
|
||||||
this.tiles_front_meta[id] = tile.meta;
|
this.tiles_front_meta[id] = tile.meta;
|
||||||
|
|
@ -152,8 +172,17 @@ public class Chunk
|
||||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
int id = cpos.getId(CHUNK_SIZE);
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
return getBackTile(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileState getBackTile(int id)
|
||||||
|
{
|
||||||
// Send back the back tile
|
// Send back the back tile
|
||||||
return new TileState(this.tiles_back[id], this.tiles_back_meta[id]);
|
TileState ts = new TileState(this.tiles_back[id], this.tiles_back_meta[id]);
|
||||||
|
ts.light.x = this.tiles_lighting_r[id];
|
||||||
|
ts.light.y = this.tiles_lighting_g[id];
|
||||||
|
ts.light.z = this.tiles_lighting_b[id];
|
||||||
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileState getFrontTile(Vec2i pos)
|
public TileState getFrontTile(Vec2i pos)
|
||||||
|
|
@ -164,8 +193,17 @@ public class Chunk
|
||||||
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
int id = cpos.getId(CHUNK_SIZE);
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
return getFrontTile(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileState getFrontTile(int id)
|
||||||
|
{
|
||||||
// Send back the front tile
|
// Send back the front tile
|
||||||
return new TileState(this.tiles_front[id], this.tiles_front_meta[id]);
|
TileState ts = new TileState(this.tiles_front[id], this.tiles_front_meta[id]);
|
||||||
|
ts.light.x = this.tiles_lighting_r[id];
|
||||||
|
ts.light.y = this.tiles_lighting_g[id];
|
||||||
|
ts.light.z = this.tiles_lighting_b[id];
|
||||||
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void breakBackTile(Vec2i pos)
|
public void breakBackTile(Vec2i pos)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import java.util.Random;
|
||||||
import shootergame.util.math.TileState;
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.map.IMap2D;
|
import shootergame.util.math.map.IMap2D;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
import shootergame.util.math.vec.Vec3i;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -13,6 +15,7 @@ public abstract class LayerGen implements IMap2D<Chunk>
|
||||||
public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos);
|
public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos);
|
||||||
public abstract void spawnEntities(Layer layer, Random rand);
|
public abstract void spawnEntities(Layer layer, Random rand);
|
||||||
public abstract TileState getTileDestroyed();
|
public abstract TileState getTileDestroyed();
|
||||||
|
public abstract Vec3i getLightLevel();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Chunk getEmpty(Vec2i pos) {
|
public Chunk getEmpty(Vec2i pos) {
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,15 @@ import java.util.Random;
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityZombie;
|
import shootergame.entity.EntityZombie;
|
||||||
|
import shootergame.entity.EntityZombieBomber;
|
||||||
import shootergame.init.Tiles;
|
import shootergame.init.Tiles;
|
||||||
import shootergame.util.math.TileState;
|
import shootergame.util.math.TileState;
|
||||||
import shootergame.util.math.random.OpenSimplexNoise;
|
import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
import shootergame.util.math.random.RandomHelpers;
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
import shootergame.util.math.vec.Vec3i;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -60,7 +63,10 @@ public class LayerGenCaves extends LayerGen
|
||||||
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
|
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
|
||||||
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
|
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
|
||||||
|
|
||||||
chunk.setFrontTile(Tiles.TILE_CHEST.getDefaultState(), chest_pos);
|
// Only place a chest here if the tile is clear
|
||||||
|
if(chunk.getBackTile(chest_pos).tile == getTileDestroyed().tile) {
|
||||||
|
chunk.setFrontTile(Tiles.TILE_CHEST.getDefaultState(), chest_pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -78,11 +84,28 @@ public class LayerGenCaves extends LayerGen
|
||||||
zombie.pos.squareDistance(Main.player.pos) > 32)
|
zombie.pos.squareDistance(Main.player.pos) > 32)
|
||||||
layer.spawnEntity(zombie);
|
layer.spawnEntity(zombie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rand.nextDouble() > 0.98)
|
||||||
|
{
|
||||||
|
Entity zombie = new EntityZombieBomber(new Vec2d(
|
||||||
|
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128),
|
||||||
|
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128)));
|
||||||
|
|
||||||
|
if(layer.getBackTile(new Vec2i((int)zombie.pos.x,
|
||||||
|
(int)zombie.pos.y)).tile == getTileDestroyed().tile &&
|
||||||
|
zombie.pos.squareDistance(Main.player.pos) > 32)
|
||||||
|
layer.spawnEntity(zombie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileState getTileDestroyed() {
|
public TileState getTileDestroyed() {
|
||||||
return Tiles.STONE.getDefaultState();
|
return Tiles.STONE.getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec3i getLightLevel() {
|
||||||
|
return new Vec3i(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
import shootergame.util.math.random.RandomHelpers;
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
import shootergame.util.math.vec.Vec3i;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
|
@ -86,5 +88,8 @@ public class LayerGenEarth extends LayerGen
|
||||||
return Tiles.DIRT.getDefaultState();
|
return Tiles.DIRT.getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vec3i getLightLevel() {
|
||||||
|
return new Vec3i(200, 200, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue