Added items, started working on break particles
This commit is contained in:
parent
bb13aaa09f
commit
44a6cedf3a
Binary file not shown.
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
|
@ -2,8 +2,12 @@ package shootergame.display;
|
|||
|
||||
import shootergame.Main;
|
||||
import shootergame.audio.AudioSources;
|
||||
import shootergame.entity.EntityInventory;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.inventory.IInventory;
|
||||
import shootergame.inventory.Inventory;
|
||||
import shootergame.items.ItemStack;
|
||||
import shootergame.text.Text;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
|
|
@ -31,8 +35,6 @@ public class DisplayRenderUI
|
|||
Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size);
|
||||
GlHelpers.translate(0, -0.5, 0);
|
||||
Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, text_size);
|
||||
GlHelpers.translate(0, -0.5, 0);
|
||||
Text.render("AL Sound Source: "+AudioSources.upto, text_size);
|
||||
GlHelpers.color3(1, 1, 1);
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
|
|
@ -43,22 +45,72 @@ public class DisplayRenderUI
|
|||
TextureReference health_bg = Textures.UI_HEALTH_BG;
|
||||
GlHelpers.begin();
|
||||
|
||||
health_bg.texCoord(0, 0); GlHelpers.vertex2(-2.5, -9.0);
|
||||
health_bg.texCoord(0, 1); GlHelpers.vertex2(-2.5, -9.5);
|
||||
health_bg.texCoord(1, 1); GlHelpers.vertex2(2.5, -9.5);
|
||||
health_bg.texCoord(1, 0); GlHelpers.vertex2(2.5, -9.0);
|
||||
health_bg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
|
||||
health_bg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
|
||||
health_bg.texCoord(1, 0); GlHelpers.vertex2(3.2, -9.0);
|
||||
health_bg.texCoord(1, 1); GlHelpers.vertex2(3.2, -8.0);
|
||||
|
||||
health_fg.texCoord(0, 0); GlHelpers.vertex2(-2.5, -9.0);
|
||||
health_fg.texCoord(0, 1); GlHelpers.vertex2(-2.5, -9.5);
|
||||
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(2.5-a*5, -9.5);
|
||||
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(2.5-a*5, -9.0);
|
||||
health_fg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
|
||||
health_fg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
|
||||
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(3.2-a*6.4, -9.0);
|
||||
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(3.2-a*6.4, -8.0);
|
||||
|
||||
GlHelpers.end();
|
||||
|
||||
// Display the amount of ammo left
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate(-9.5, -9.5, 0);
|
||||
Text.render("Ammo: "+player.ammo, text_size);
|
||||
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
|
||||
GlHelpers.begin();
|
||||
|
||||
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5);
|
||||
ammo_tex.texCoord(0, 0); GlHelpers.vertex2(-9.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);
|
||||
|
||||
GlHelpers.end();
|
||||
|
||||
GlHelpers.translate(-8.5, -9, 0);
|
||||
Text.render(Integer.toString(player.ammo), text_size);
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
// Display all the items in the players inventory
|
||||
TextureReference slots_tex = Textures.UI_ITEM_SLOTS;
|
||||
GlHelpers.begin();
|
||||
|
||||
slots_tex.texCoord(0, 1); GlHelpers.vertex2(9.5, -9.4);
|
||||
slots_tex.texCoord(0, 0); GlHelpers.vertex2(9.5, -7.6);
|
||||
slots_tex.texCoord(1, 0); GlHelpers.vertex2(3.5, -7.6);
|
||||
slots_tex.texCoord(1, 1); GlHelpers.vertex2(3.5, -9.4);
|
||||
|
||||
GlHelpers.end();
|
||||
|
||||
// Render the players active slot
|
||||
TextureReference hotbar_slot_tex = Textures.UI_ACTIVE_SLOT;
|
||||
GlHelpers.begin();
|
||||
|
||||
hotbar_slot_tex.texCoord(0, 1); GlHelpers.vertex2(4.55 + player.inventory_hand, -9.45);
|
||||
hotbar_slot_tex.texCoord(0, 0); GlHelpers.vertex2(4.55 + player.inventory_hand, -7.55);
|
||||
hotbar_slot_tex.texCoord(1, 0); GlHelpers.vertex2(3.45 + player.inventory_hand, -7.55);
|
||||
hotbar_slot_tex.texCoord(1, 1); GlHelpers.vertex2(3.45 + player.inventory_hand, -9.45);
|
||||
|
||||
GlHelpers.end();
|
||||
|
||||
// Render the players inventory
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
Inventory player_inv = ((EntityInventory)player).getInventory();
|
||||
ItemStack player_item = player_inv.getItem(i);
|
||||
|
||||
if(!player_item.isEmpty())
|
||||
{
|
||||
player_item.item.render(new Vec2d(3.5 + i, -9.2), new Vec2d(1, 1.5));
|
||||
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate(3.8 + i, -9.2, 0);
|
||||
Text.render(Integer.toString(player_item.count), text_size);
|
||||
GlHelpers.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package shootergame.display.transparent;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.tiles.TileBlackened;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec3d;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package shootergame.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.display.Camera;
|
||||
|
|
@ -30,6 +31,7 @@ public class Entity implements ITransparentObject
|
|||
private TileState tile_back;
|
||||
public boolean crossUnWalkable = true;
|
||||
public boolean goThroughSolid = true;
|
||||
protected static final Random rand = new Random();
|
||||
|
||||
public Entity(Vec2d pos, double angle)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package shootergame.entity;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.entity.particle.ParticleBlood;
|
||||
import shootergame.init.Sounds;
|
||||
|
|
@ -20,14 +21,12 @@ import shootergame.world.layer.Layer;
|
|||
public class EntityBullet extends EntityParticle
|
||||
{
|
||||
private int time = 0;
|
||||
private Random rand;
|
||||
private Entity parent;
|
||||
|
||||
public EntityBullet(Random rand, Vec2d pos, Entity parent, double angle) {
|
||||
public EntityBullet(Vec2d pos, Entity parent, double angle) {
|
||||
super(0.2, 0.4);
|
||||
|
||||
// Store some specified values
|
||||
this.rand = rand;
|
||||
this.pos = pos;
|
||||
this.angle = angle;
|
||||
this.parent = parent;
|
||||
|
|
@ -56,12 +55,22 @@ public class EntityBullet extends EntityParticle
|
|||
if(tile_f.tile.tileSolid) {
|
||||
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tile.tileHitbox)
|
||||
{
|
||||
// Break the block
|
||||
if(RandomHelpers.randrange(rand, 5) == 0) {
|
||||
chunk.breakFrontTile(tpos);
|
||||
}
|
||||
|
||||
// Delete the bullet
|
||||
kill();
|
||||
}
|
||||
} if(tile_b.tile.tileSolid) {
|
||||
if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tile.tileHitbox)
|
||||
{
|
||||
// Break the block
|
||||
if(RandomHelpers.randrange(rand, 5) == 0) {
|
||||
chunk.breakBackTile(tpos);
|
||||
}
|
||||
|
||||
// Delete the bullet
|
||||
kill();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package shootergame.entity;
|
||||
|
||||
public interface EntityInventory {
|
||||
import shootergame.inventory.Inventory;
|
||||
|
||||
public interface EntityInventory
|
||||
{
|
||||
public Inventory getInventory();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package shootergame.entity;
|
||||
|
||||
import shootergame.inventory.Inventory;
|
||||
import shootergame.items.ItemStack;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class EntityItem extends EntityVertical
|
||||
{
|
||||
private ItemStack stack;
|
||||
|
||||
public EntityItem(Vec2d pos, ItemStack stack) {
|
||||
super(stack.item.texture, 1);
|
||||
|
||||
this.opaqueTile = true;
|
||||
this.pos = pos;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Chunk chunk, Layer layer) {
|
||||
super.tick(chunk, layer);
|
||||
|
||||
for(Entity e : layer.getNearbyEntities(pos, 1))
|
||||
{
|
||||
if(e instanceof EntityInventory)
|
||||
{
|
||||
// Pick the stack up if its an inventory
|
||||
stack.item.onPickedUp(stack, layer, chunk, e);
|
||||
|
||||
// Kill this entity if the stack is empty
|
||||
if(stack.isEmpty()) {
|
||||
kill();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import shootergame.entity.particle.ParticleSpark;
|
|||
import shootergame.init.Sounds;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.tiles.TileBlackened;
|
||||
import shootergame.tiles.TileStone;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
|
|
@ -27,8 +26,6 @@ public class EntityTnt extends EntityVertical
|
|||
private int explode_time;
|
||||
private int explode_radius;
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
public EntityTnt(Vec2d pos, double angle, int explode_radius) {
|
||||
super(Textures.ENTITY_TNT, 0.5);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ public class EntityVertical extends Entity
|
|||
private TextureReference tex;
|
||||
private double height;
|
||||
|
||||
public EntityVertical() {
|
||||
}
|
||||
|
||||
public EntityVertical(TextureReference tex, double height) {
|
||||
this.height = height;
|
||||
this.tex = tex;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import shootergame.world.layer.Layer;
|
|||
|
||||
public class EntityZombie extends EntityVertical implements EntityAlive
|
||||
{
|
||||
private Random rand;
|
||||
private OpenSimplexNoise noise_movement;
|
||||
private OpenSimplexNoise noise_gun_fire;
|
||||
private OpenSimplexNoise noise_gun_angle;
|
||||
|
|
@ -23,7 +22,6 @@ public class EntityZombie extends EntityVertical implements EntityAlive
|
|||
|
||||
public EntityZombie() {
|
||||
super(Textures.ENTITY_ZOMBIE, 1);
|
||||
rand = new Random();
|
||||
noise_movement = new OpenSimplexNoise(rand.nextLong());
|
||||
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
|
||||
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
|
||||
|
|
@ -60,7 +58,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive
|
|||
angle_gun += noise_gun_angle.eval(time, 0)*20;
|
||||
|
||||
// Fire the gun
|
||||
layer.spawnEntity(new EntityBullet(rand, pos.copy(), this, angle_gun));
|
||||
layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package shootergame.entity.particle;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.entity.EntityParticle;
|
||||
import shootergame.entity.EntityVertical;
|
||||
import shootergame.util.gl.texture.IHasTexture;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class EntityBreak extends EntityVertical
|
||||
{
|
||||
private static TextureReference getTexture(TileState ts)
|
||||
{
|
||||
if(ts.tile instanceof IHasTexture)
|
||||
{
|
||||
TextureReference tex = ((IHasTexture)ts.tile).getTexture();
|
||||
return tex;
|
||||
}
|
||||
|
||||
else {
|
||||
return TextureReference.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public EntityBreak(Vec2d pos, TileState ts) {
|
||||
super(getTexture(ts), 1);
|
||||
this.opaqueTile = ts.tile.opaqueTile;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Chunk chunk, Layer layer) {
|
||||
super.tick(chunk, layer);
|
||||
|
||||
// Kill the particle if the player can't see it to reduce lag
|
||||
if(Main.player.pos.squareDistance(pos) > 32) this.kill();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,14 @@ import shootergame.display.Camera;
|
|||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityAlive;
|
||||
import shootergame.entity.EntityBullet;
|
||||
import shootergame.entity.EntityInventory;
|
||||
import shootergame.entity.EntityTnt;
|
||||
import shootergame.entity.EntityVertical;
|
||||
import shootergame.init.Items;
|
||||
import shootergame.init.Sounds;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.inventory.Inventory;
|
||||
import shootergame.items.ItemStack;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
|
|
@ -21,7 +25,7 @@ import shootergame.util.math.vec.Vec3d;
|
|||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class EntityPlayer extends EntityVertical implements EntityAlive
|
||||
public class EntityPlayer extends EntityVertical implements EntityAlive, EntityInventory
|
||||
{
|
||||
public boolean MOVE_FORWARD = false;
|
||||
public boolean MOVE_BACKWARD = false;
|
||||
|
|
@ -39,9 +43,14 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
public boolean dead = false;
|
||||
public boolean in_animation = false;
|
||||
|
||||
private Inventory inventory;
|
||||
public int inventory_hand = 0;
|
||||
|
||||
public int ammo = 1000;
|
||||
|
||||
public EntityPlayer() {
|
||||
super(TextureReference.EMPTY, 0);
|
||||
|
||||
this.angle = 45;
|
||||
rand = new Random();
|
||||
|
||||
|
|
@ -50,6 +59,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
isSolid = true;
|
||||
goThroughSolid = false;
|
||||
crossUnWalkable = false;
|
||||
|
||||
inventory = new Inventory(6);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,7 +84,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
super.tick(chunk, layer);
|
||||
|
||||
// Regen some of the players health
|
||||
this.addHealth(0.1);
|
||||
//this.addHealth(0.1);
|
||||
|
||||
// Rotate left
|
||||
if(MOVE_LEFT) {
|
||||
|
|
@ -163,23 +174,30 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
ammo -= 1;
|
||||
|
||||
// Summon bullets at this angle relative to the player
|
||||
Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle));
|
||||
Main.world.getLayer().spawnEntity(new EntityBullet(pos.copy(), this, angle + this.angle));
|
||||
}
|
||||
}
|
||||
|
||||
public void throwTnt(double angle) {
|
||||
public void activateItem() {
|
||||
if(dead || in_animation) return;
|
||||
Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10));
|
||||
|
||||
ItemStack is = inventory.getItem(inventory_hand);
|
||||
|
||||
if(!is.isEmpty()) {
|
||||
is.item.onAction(is, Main.world.getLayer(), chunk, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHealth(double amount) {
|
||||
if(health < health_max) health += amount;
|
||||
health += amount;
|
||||
if(health > health_max) health = health_max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHealth(double amount) {
|
||||
health -= amount;
|
||||
if(health < 0) health = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -206,4 +224,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
public void setHealth(double health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package shootergame.init;
|
||||
|
||||
import shootergame.items.Item;
|
||||
import shootergame.items.ItemAmmo;
|
||||
import shootergame.items.ItemDefenceUpgrade;
|
||||
import shootergame.items.ItemEmpty;
|
||||
import shootergame.items.ItemGunUpgrade;
|
||||
import shootergame.items.ItemHealthPotion;
|
||||
|
||||
public class Items
|
||||
{
|
||||
public static final Item AMMO = new ItemAmmo("ammo");
|
||||
public static final Item DEFENCE_UPGRADE = new ItemDefenceUpgrade("defence_upgrade");
|
||||
public static final Item GUN_UPGRADE = new ItemGunUpgrade("gun_upgrade");
|
||||
public static final Item HEALTH_POTION = new ItemHealthPotion("health_potion");
|
||||
public static final Item EMPTY = new ItemEmpty("empty");
|
||||
}
|
||||
|
|
@ -36,9 +36,17 @@ public class Textures
|
|||
public static final TextureReference TILE_PORTAL = texmap.getTextureReference(3, 4, 5, 6);
|
||||
public static final TextureReference TILE_WALL = texmap.getTextureReference(2, 3, 5, 6);
|
||||
public static final TextureReference TILE_LADDER_UP = texmap.getTextureReference(16, 17, 0, 16);
|
||||
public static final TextureReference TILE_CHEST = texmap.getTextureReference(2, 3, 4, 5);
|
||||
|
||||
public static final TextureReference UI_HEALTH_FG = texmap.getTextureReference(0, 16, 11, 12);
|
||||
public static final TextureReference UI_HEALTH_BG = texmap.getTextureReference(0, 16, 12, 13);
|
||||
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 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_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5);
|
||||
public static final TextureReference ITEM_DEFENCE_UPGRADE = texmap.getTextureReference(1, 2, 4, 5);
|
||||
|
||||
// Fire
|
||||
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package shootergame.init;
|
||||
|
||||
import shootergame.tiles.Tile;
|
||||
import shootergame.tiles.TileBlackened;
|
||||
import shootergame.tiles.TileChest;
|
||||
import shootergame.tiles.TileDirt;
|
||||
import shootergame.tiles.TileFire;
|
||||
import shootergame.tiles.TileGrass;
|
||||
|
|
@ -33,9 +33,9 @@ public class Tiles
|
|||
public static final Tile WATER = new TileWater("water");
|
||||
public static final Tile LAVA_FLOW = new TileLavaFlow("lava_flow");
|
||||
public static final Tile WATER_FLOW = new TileWaterFlow("water_flow");
|
||||
public static final Tile BLACKENED = new TileBlackened("blackened");
|
||||
public static final Tile LADDER = new TileLadder("ladder");
|
||||
public static final Tile PORTAL_DOWN = new TilePortalDown("portal_down");
|
||||
public static final Tile WALL = new TileWall("wall");
|
||||
public static final Tile LADDER_UP = new TileLadderUp("ladder_up");
|
||||
public static final Tile TILE_CHEST = new TileChest("chest");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,18 @@ import org.lwjgl.glfw.GLFWJoystickCallbackI;
|
|||
|
||||
import mainloop.task.IMainloopTask;
|
||||
import shootergame.Main;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
|
||||
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||
{
|
||||
public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback();
|
||||
private ArrayList<Integer> connections = new ArrayList<Integer>();
|
||||
|
||||
private static boolean throwTnt_last = false;
|
||||
private static boolean activate_last = false;
|
||||
private static boolean activateItem_last = false;
|
||||
private static boolean activateTile_last = false;
|
||||
|
||||
private static boolean hotbar_l = false;
|
||||
private static boolean hotbar_r = false;
|
||||
|
||||
@Override
|
||||
public void invoke(int jid, int event)
|
||||
|
|
@ -167,45 +171,53 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
|||
Main.player.fireBullet(0);
|
||||
}
|
||||
|
||||
// Tnt trigger
|
||||
// Item trigger
|
||||
if(left_trigger > 0.3) {
|
||||
if(!throwTnt_last)
|
||||
if(!activateItem_last)
|
||||
{
|
||||
throwTnt_last = true;
|
||||
Main.player.throwTnt(0);
|
||||
activateItem_last = true;
|
||||
Main.player.activateItem();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
throwTnt_last = false;
|
||||
activateItem_last = false;
|
||||
}
|
||||
|
||||
if(dpad_up) {
|
||||
Main.player.fireBullet(0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if(dpad_down) {
|
||||
Main.player.fireBullet(180);
|
||||
else if(hotbar_l) {
|
||||
hotbar_l = false;
|
||||
}
|
||||
|
||||
if(dpad_left) {
|
||||
Main.player.fireBullet(270);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if(dpad_right) {
|
||||
Main.player.fireBullet(90);
|
||||
else if(hotbar_r) {
|
||||
hotbar_r = false;
|
||||
}
|
||||
|
||||
// Activate block
|
||||
// Activate tile
|
||||
if(button_x) {
|
||||
if(!activate_last) {
|
||||
if(!activateTile_last) {
|
||||
Main.player.activateTile();
|
||||
activate_last = true;
|
||||
activateTile_last = true;
|
||||
}
|
||||
}
|
||||
|
||||
else if(activate_last) {
|
||||
activate_last = false;
|
||||
else if(activateTile_last) {
|
||||
activateTile_last = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package shootergame.inventory;
|
||||
|
||||
import shootergame.items.ItemStack;
|
||||
|
||||
public interface IInventory
|
||||
{
|
||||
public ItemStack getItem(int slot);
|
||||
public int getSlotCount();
|
||||
public void setItem(ItemStack stack, int slot);
|
||||
public ItemStack removeItem(int slot);
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package shootergame.inventory;
|
||||
|
||||
import shootergame.items.ItemStack;
|
||||
|
||||
public class Inventory implements IInventory
|
||||
{
|
||||
protected ItemStack[] items;
|
||||
|
||||
public Inventory(int size)
|
||||
{
|
||||
items = new ItemStack[size];
|
||||
|
||||
for(int i=0;i<size;i++) {
|
||||
items[i] = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot)
|
||||
{
|
||||
if(items[slot].isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
else {
|
||||
return items[slot];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(ItemStack stack, int slot) {
|
||||
items[slot] = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int slot) {
|
||||
ItemStack stack = items[slot];
|
||||
items[slot] = ItemStack.EMPTY;
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityInventory;
|
||||
import shootergame.inventory.Inventory;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class Item
|
||||
{
|
||||
public TextureReference texture;
|
||||
public String id;
|
||||
|
||||
public Item(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void render(Vec2d pos, Vec2d size)
|
||||
{
|
||||
GlHelpers.begin();
|
||||
|
||||
texture.texCoord(0, 1); GlHelpers.vertex3(pos.x+size.x , pos.y , 0);
|
||||
texture.texCoord(0, 0); GlHelpers.vertex3(pos.x+size.x , pos.y+size.y , 0);
|
||||
texture.texCoord(1, 0); GlHelpers.vertex3(pos.x , pos.y+size.y , 0);
|
||||
texture.texCoord(1, 1); GlHelpers.vertex3(pos.x , pos.y , 0);
|
||||
|
||||
GlHelpers.end();
|
||||
}
|
||||
|
||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||
stack.count -= 1;
|
||||
}
|
||||
|
||||
public String getName(short meta) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getLore(short meta) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
||||
{
|
||||
// Update the stacks count
|
||||
if(stack.isEmpty()) return;
|
||||
|
||||
// Does the entity have an inventory
|
||||
if(entity instanceof EntityInventory)
|
||||
{
|
||||
// Get the entities inventory
|
||||
Inventory entity_i = ((EntityInventory) entity).getInventory();
|
||||
|
||||
// Loop over the inventory
|
||||
for(int i=0;i<entity_i.getSlotCount();i++)
|
||||
{
|
||||
// Is this item the same as the picked up item
|
||||
ItemStack i_stack = entity_i.getItem(i);
|
||||
if(stack.stackEquals(i_stack))
|
||||
{
|
||||
// Move the stack count to the inventory slot
|
||||
i_stack.count += stack.count;
|
||||
stack.count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Is this item stack empty
|
||||
if(i_stack.isEmpty())
|
||||
{
|
||||
// Send the entity stack to the inventory stack
|
||||
entity_i.setItem(stack.copy(), i);
|
||||
stack.count = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class ItemAmmo extends Item
|
||||
{
|
||||
|
||||
public ItemAmmo(String id) {
|
||||
super(id);
|
||||
|
||||
this.texture = Textures.ITEM_AMMO_BOX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
||||
{
|
||||
// Is this entity a player
|
||||
if(entity instanceof EntityPlayer)
|
||||
{
|
||||
// Add the ammo to the players inventory
|
||||
EntityPlayer ep = (EntityPlayer)entity;
|
||||
ep.ammo += stack.count;
|
||||
stack.count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(short meta) {
|
||||
return "Ammo";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class ItemDefenceUpgrade extends Item
|
||||
{
|
||||
|
||||
public ItemDefenceUpgrade(String id) {
|
||||
super(id);
|
||||
|
||||
this.texture = Textures.ITEM_DEFENCE_UPGRADE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||
super.onAction(stack, layer, chunk, entity);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLore(short meta) {
|
||||
return "Upgrade the defence to level " + meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(short meta) {
|
||||
return "Defence Upgrade";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class ItemEmpty extends Item
|
||||
{
|
||||
|
||||
public ItemEmpty(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Vec2d pos, Vec2d size) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.init.Textures;
|
||||
|
||||
public class ItemGunUpgrade extends Item
|
||||
{
|
||||
|
||||
public ItemGunUpgrade(String id) {
|
||||
super(id);
|
||||
|
||||
this.texture = Textures.ITEM_GUN_UPGRADE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLore(short meta) {
|
||||
return "Upgrade the gun to level " + meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(short meta) {
|
||||
return "Gun Upgrade";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityAlive;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class ItemHealthPotion extends Item
|
||||
{
|
||||
|
||||
public ItemHealthPotion(String id) {
|
||||
super(id);
|
||||
|
||||
this.texture = Textures.ITEM_HEALTH_POTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(short meta) {
|
||||
return "Health Potion";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLore(short meta) {
|
||||
return "Restores " + Short.toString(meta) + " health points";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction(ItemStack stack, Layer layer, Chunk chunk, Entity entity) {
|
||||
super.onAction(stack, layer, chunk, entity);
|
||||
|
||||
// Is the entity alive
|
||||
if(entity instanceof EntityAlive)
|
||||
{
|
||||
// Cast to alive entity
|
||||
EntityAlive entity_a = (EntityAlive)entity;
|
||||
|
||||
// Heal the entity
|
||||
entity_a.addHealth(stack.meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package shootergame.items;
|
||||
|
||||
import shootergame.init.Items;
|
||||
|
||||
public class ItemStack
|
||||
{
|
||||
public short meta;
|
||||
public Item item;
|
||||
public int count;
|
||||
|
||||
public static final ItemStack EMPTY = new ItemStack(Items.EMPTY, 0, (short)0);
|
||||
|
||||
public ItemStack(Item item, int count, short meta) {
|
||||
this.item = item;
|
||||
this.count = count;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public ItemStack copy() {
|
||||
return new ItemStack(item, count, meta);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
if(count < 1) return true;
|
||||
if(this == EMPTY) return true;
|
||||
if(item == null) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean stackEquals(ItemStack other) {
|
||||
if(other.item != item) return false;
|
||||
if(other.meta != meta) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileBlackened extends Tile
|
||||
{
|
||||
|
||||
public TileBlackened(String id) {
|
||||
super(id);
|
||||
//this.opaqueTile = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Vec2d pos, Camera camera, short meta)
|
||||
{
|
||||
// Call super
|
||||
super.render(pos, camera, meta);
|
||||
|
||||
// Set the colour
|
||||
GlHelpers.color4(0, 0, 0, ((double)meta) / Short.MAX_VALUE);
|
||||
|
||||
// Draw the tile
|
||||
GlHelpers.begin();
|
||||
GlHelpers.vertex3(pos.x+0, pos.y+0, 0.001);
|
||||
GlHelpers.vertex3(pos.x+1, pos.y+0, 0.001);
|
||||
GlHelpers.vertex3(pos.x+1, pos.y+1, 0.001);
|
||||
GlHelpers.vertex3(pos.x+0, pos.y+1, 0.001);
|
||||
GlHelpers.end();
|
||||
|
||||
// Reset the colour
|
||||
GlHelpers.color4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityItem;
|
||||
import shootergame.init.Items;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.items.ItemStack;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class TileChest extends TileVertical
|
||||
{
|
||||
|
||||
public TileChest(String id) {
|
||||
super(id, Textures.TILE_CHEST, 1);
|
||||
|
||||
this.tileSolid = true;
|
||||
this.opaqueTile = true;
|
||||
this.tileHitbox = 0.4;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivated(Chunk chunk, Layer layer, Vec2i tpos, Entity entity, short meta) {
|
||||
super.onActivated(chunk, layer, tpos, entity, meta);
|
||||
|
||||
layer.spawnEntity(new EntityItem(new Vec2d(tpos.x, tpos.y), new ItemStack(Items.HEALTH_POTION, 1, (short)20)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,12 +3,13 @@ package shootergame.tiles;
|
|||
import shootergame.display.Camera;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.IHasTexture;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.util.math.vec.Vec3d;
|
||||
|
||||
public class TileFlat extends Tile
|
||||
public class TileFlat extends Tile implements IHasTexture
|
||||
{
|
||||
private TextureReference tex;
|
||||
|
||||
|
|
@ -31,4 +32,9 @@ public class TileFlat extends Tile
|
|||
tex.texCoord(1, 0); GlHelpers.vertex3(pos.x+0, pos.y+1, 0);
|
||||
GlHelpers.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureReference getTexture() {
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import shootergame.util.math.TileState;
|
|||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.chunk.ChunkEventHandler;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
||||
public class TilePortalDown extends TileFlat
|
||||
|
|
@ -51,23 +52,13 @@ public class TilePortalDown extends TileFlat
|
|||
player.height -= 0.02;
|
||||
}
|
||||
|
||||
if(movingPlayer == 1) {
|
||||
if(movingPlayer == 2) {
|
||||
player.height -= 0.04;
|
||||
}
|
||||
|
||||
if(player.height < -1 && movingPlayer == 0)
|
||||
{
|
||||
movingPlayer = 1;
|
||||
Main.world.setLayerID(meta);
|
||||
player.height = 6;
|
||||
}
|
||||
|
||||
if(player.height < 0 && movingPlayer == 1)
|
||||
if(ChunkEventHandler.loaded && movingPlayer == 1)
|
||||
{
|
||||
movingPlayer = 2;
|
||||
player.height = 0;
|
||||
player.moving = false;
|
||||
player.in_animation = false;
|
||||
|
||||
Vec2i check_poses[] = {
|
||||
new Vec2i( 1, 0),
|
||||
|
|
@ -103,11 +94,26 @@ public class TilePortalDown extends TileFlat
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(player.height < -1 && movingPlayer == 0)
|
||||
{
|
||||
movingPlayer = 1;
|
||||
Main.world.setLayerID(meta);
|
||||
player.height = 6;
|
||||
}
|
||||
|
||||
if(player.height < 0 && movingPlayer == 2)
|
||||
{
|
||||
movingPlayer = 3;
|
||||
player.height = 0;
|
||||
player.moving = false;
|
||||
player.in_animation = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean MainLoopRepeat() {
|
||||
return movingPlayer != 2;
|
||||
return movingPlayer != 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@ import shootergame.display.Camera;
|
|||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.VerticalRender;
|
||||
import shootergame.util.gl.texture.IHasTexture;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
|
||||
public class TileVertical extends Tile
|
||||
public class TileVertical extends Tile implements IHasTexture
|
||||
{
|
||||
private TextureReference tex;
|
||||
private int h;
|
||||
|
|
@ -28,4 +29,9 @@ public class TileVertical extends Tile
|
|||
VerticalRender.render(pos, camera, tex, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureReference getTexture() {
|
||||
return tex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package shootergame.util.gl.texture;
|
||||
|
||||
public interface IHasTexture
|
||||
{
|
||||
public TextureReference getTexture();
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ public abstract class TextureReference
|
|||
private int end_x;
|
||||
private int end_y;
|
||||
|
||||
public static final TextureReference EMPTY = new TextureReferenceEmpty();
|
||||
|
||||
TextureReference() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package shootergame.util.gl.texture;
|
||||
|
||||
class TextureReferenceEmpty extends TextureReference
|
||||
{
|
||||
|
||||
public TextureReferenceEmpty() {
|
||||
super(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void texCoord(double x, double y) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ public class MathHelpers
|
|||
|
||||
// Return and calculate the new positions
|
||||
return new Vec2d(
|
||||
p_distance * Math.sin(angle - p_angle),
|
||||
p_distance * Math.cos(angle - p_angle));
|
||||
p_distance * Math.sin(angle + p_angle),
|
||||
p_distance * Math.cos(angle + p_angle));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Random;
|
||||
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.world.chunk.ChunkEventHandler;
|
||||
import shootergame.world.layer.Layer;
|
||||
import shootergame.world.layer.layergen.LayerGen;
|
||||
|
||||
|
|
@ -47,6 +48,7 @@ public class World
|
|||
public void setLayerID(int id) {
|
||||
layer_id = id;
|
||||
layer = layers.get(layer_id);
|
||||
ChunkEventHandler.loaded = false;
|
||||
}
|
||||
|
||||
public Layer getLayer() {
|
||||
|
|
|
|||
|
|
@ -169,6 +169,24 @@ public class Chunk
|
|||
return new TileState(this.tiles_front[id], this.tiles_front_meta[id]);
|
||||
}
|
||||
|
||||
public void breakBackTile(Vec2i pos)
|
||||
{
|
||||
TileState ts = getBackTile(pos);
|
||||
|
||||
if(!ts.tile.unbreakable) {
|
||||
setBackTile(layer.layergen.getTileDestroyed(), pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void breakFrontTile(Vec2i pos)
|
||||
{
|
||||
TileState ts = getFrontTile(pos);
|
||||
|
||||
if(!ts.tile.unbreakable) {
|
||||
setFrontTile(Tiles.VOID.getDefaultState(), pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void killEntity(Entity e) {
|
||||
entities.remove(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import shootergame.world.layer.Layer;
|
|||
public class ChunkEventHandler implements IMainloopTask
|
||||
{
|
||||
public static final ChunkEventHandler CHUNK_EVENT_HANDLER = new ChunkEventHandler();
|
||||
public static boolean loaded = false;
|
||||
|
||||
@Override
|
||||
public boolean MainLoopDelay(long millis) {
|
||||
|
|
@ -29,6 +30,7 @@ public class ChunkEventHandler implements IMainloopTask
|
|||
{
|
||||
// Get the layer
|
||||
Layer layer = Main.world.getLayer();
|
||||
loaded = true;
|
||||
|
||||
// Loop over all the chunks in this layer
|
||||
for(Map2DElement<Chunk> ce : layer.chunks)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.Random;
|
|||
import shootergame.Main;
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.tiles.Tile;
|
||||
import shootergame.util.math.MathHelpers;
|
||||
import shootergame.util.math.TileState;
|
||||
|
|
@ -66,6 +67,14 @@ public class Layer
|
|||
this.layergen.spawnEntities(this, rand);
|
||||
}
|
||||
|
||||
public Chunk getChunk(Vec2i pos) {
|
||||
return chunks.get(getChunkPosFromPos(pos));
|
||||
}
|
||||
|
||||
public Chunk getChunk(Vec2d pos) {
|
||||
return chunks.get(getChunkPosFromPos(pos));
|
||||
}
|
||||
|
||||
public void setBackTile(TileState tile, Vec2i pos)
|
||||
{
|
||||
// Get the chunk pos
|
||||
|
|
@ -93,6 +102,14 @@ public class Layer
|
|||
return chunks.get(c_pos).getBackTile(pos);
|
||||
}
|
||||
|
||||
public void breakBackTile(Vec2i pos) {
|
||||
getChunk(pos).breakBackTile(pos);
|
||||
}
|
||||
|
||||
public void breakFrontTile(Vec2i pos) {
|
||||
getChunk(pos).breakFrontTile(pos);
|
||||
}
|
||||
|
||||
private Vec2i getChunkPosFromPos(Vec2i pos) {
|
||||
return this.getChunkPosFromPos(new Vec2d(pos.x, pos.y));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,17 @@ import java.util.Random;
|
|||
|
||||
import org.lwjgl.stb.STBPerlin;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.entity.Entity;
|
||||
import shootergame.entity.EntityItem;
|
||||
import shootergame.entity.EntityZombie;
|
||||
import shootergame.init.Items;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.items.ItemStack;
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.random.OpenSimplexNoise;
|
||||
import shootergame.util.math.random.RandomHelpers;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
import shootergame.world.layer.Layer;
|
||||
|
|
@ -47,19 +54,35 @@ public class LayerGenCaves extends LayerGen
|
|||
else {
|
||||
chunk.setBackTile(Tiles.WALL.getDefaultState(), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(portal) {
|
||||
chunk.setFrontTile(new TileState(Tiles.LADDER_UP, (short)0), portal_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vec2i chest_pos = new Vec2i(
|
||||
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
|
||||
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
|
||||
|
||||
chunk.setFrontTile(Tiles.TILE_CHEST.getDefaultState(), chest_pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEntities(Layer layer, Random rand)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
if(rand.nextDouble() > 0.95)
|
||||
{
|
||||
Entity zombie = new EntityZombie();
|
||||
zombie.pos = 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
|
||||
|
|
|
|||
|
|
@ -70,12 +70,14 @@ public class LayerGenEarth extends LayerGen
|
|||
@Override
|
||||
public void spawnEntities(Layer layer, Random rand)
|
||||
{
|
||||
if(rand.nextDouble() > 0.99)
|
||||
if(rand.nextDouble() > 0.98)
|
||||
{
|
||||
Entity zombie = new EntityZombie();
|
||||
zombie.pos = new Vec2d(
|
||||
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 100, (int)Main.player.pos.x + 100),
|
||||
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 100, (int)Main.player.pos.y + 100));
|
||||
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(zombie.pos.squareDistance(Main.player.pos) > 64)
|
||||
layer.spawnEntity(zombie);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue