package shootergame.entity.player; import java.util.Random; import shootergame.Main; import shootergame.display.Camera; import shootergame.entity.Entity; import shootergame.entity.EntityAlive; import shootergame.entity.EntityBullet; import shootergame.entity.EntityVertical; import shootergame.init.Textures; import shootergame.util.gl.texture.TextureReference; import shootergame.util.math.MathHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; public class EntityPlayer extends EntityVertical implements EntityAlive { public boolean MOVE_FORWARD = false; public boolean MOVE_BACKWARD = false; public boolean MOVE_LEFT = false; public boolean MOVE_RIGHT = false; public boolean moving = false; private int bullet_frequency = 0; private Random rand; private double health_max = 100; private double health = health_max; public EntityPlayer() { this.angle = 45; rand = new Random(); // Set some settings hitbox = 0.5; isSolid = true; } @Override public void tick(Chunk chunk, Layer layer) { // Call super super.tick(chunk, layer); // Rotate left if(MOVE_LEFT) { this.angle -= 1; this.angle = MathHelpers.mod(this.angle, 360); } // Rotate right if(MOVE_RIGHT) { this.angle += 1; this.angle = MathHelpers.mod(this.angle, 360); } // Move forward if(MOVE_FORWARD) { this.moveForward(); } // Move backward if(MOVE_BACKWARD) { this.moveBackward(); } } @Override public void render(Vec2d pos, Camera camera) { // Moving if(MOVE_BACKWARD || MOVE_FORWARD || moving) super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, 1); // Standing still else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, 1); } public void fireBullet(double angle) { bullet_frequency += 1; bullet_frequency %= 10; if(bullet_frequency == 0) { // Summon bullets at this angle relative to the player Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle)); } } @Override public void addHealth(double amount) { health += amount; } @Override public void removeHealth(double amount) { health -= amount; } @Override public double getHealth() { return health; } @Override public void resetHealth() { health = health_max; } @Override public void clearHealth() { health = 0; } @Override public double maxHealth() { return health_max; } @Override public void setHealth(double health) { this.health = health; } }