package org.egordorichev.lasttry.entity;

import org.egordorichev.lasttry.LastTry;
import org.egordorichev.lasttry.util.Assets;
import org.egordorichev.lasttry.util.Direction;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Input;

public class Player extends Entity {
	public Player(String name) {
		super(name, true, 100, 0, 0);

		this.texture = Assets.playerTexture;

		Animation idleAnimation = new Animation();
		idleAnimation.addFrame(this.texture.getSubImage(0, 0, 32, 48), 1000);
		idleAnimation.setLooping(false);

		Animation movingAnimation = new Animation();
		movingAnimation.addFrame(this.texture.getSubImage(0, 96, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 144, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 192, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 240, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 288, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 336, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 384, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 432, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 480, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 528, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 576, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 624, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 672, 32, 48), 30);
		movingAnimation.addFrame(this.texture.getSubImage(0, 720, 32, 48), 30);

		Animation jumpingAnimation = new Animation();
		jumpingAnimation.addFrame(this.texture.getSubImage(0, 48, 32, 48), 1000); // TODO

		Animation flyingAnimation = new Animation();
		flyingAnimation.addFrame(this.texture.getSubImage(0, 768, 32, 40), 40);

		Animation deadAnimation = new Animation(false);
		deadAnimation.addFrame(this.texture.getSubImage(0, 0, 32, 48), 1000); // TODO
		deadAnimation.setLooping(false);

		this.animations[State.IDLE.getId()] = idleAnimation;
		this.animations[State.MOVING.getId()] = movingAnimation;
		this.animations[State.JUMPING.getId()] = jumpingAnimation;
		this.animations[State.FALLING.getId()] = jumpingAnimation; // They are the same
		this.animations[State.FLYING.getId()] = flyingAnimation;
		this.animations[State.DEAD.getId()] = deadAnimation;
	}

	public void setGhostMode(boolean enabled) {
		this.isSolid = !enabled;

		if(enabled) {
			this.state = State.FLYING;
		} else {
			this.state = State.IDLE;
		}
	}

	@Override
	public void onSpawn() {
		for(int y = 0; y < 3; y++) {
			for(int x = 0; x < 2; x++) {
				LastTry.world.setBlock(null, this.getGridX() + x, this.getGridY() + y);
			}
		}
	}

	@Override
	public void update(int dt) {
		if(!this.shouldUpdate) {
			return;
		}

		if(this.state == State.FLYING) {
			if(LastTry.input.isKeyDown(Input.KEY_SPACE) || LastTry.input.isKeyDown(Input.KEY_W)) {
				this.velocity.y -= 1;
			}

			if(LastTry.input.isKeyDown(Input.KEY_S)) {
				this.velocity.y += 1;
			}

			if(LastTry.input.isKeyDown(Input.KEY_A)) {
				this.move(Direction.LEFT);
			}

			if(LastTry.input.isKeyDown(Input.KEY_D)) {
				this.move(Direction.RIGHT);
			}
		} else {
			if(LastTry.input.isKeyDown(Input.KEY_SPACE)) {
				this.jump();
			}

			if(LastTry.input.isKeyDown(Input.KEY_A)) {
				this.move(Direction.LEFT);
			}

			if(LastTry.input.isKeyDown(Input.KEY_D)) {
				this.move(Direction.RIGHT);
			}
		}

		super.update(dt);
	}

	
}
@@ -275,16 +275,42 @@
 ntity %7B%0A
+%09protected String name;%0A%09%0A
 %09public 
@@ -339,20 +339,31 @@
 %09%09super(
-name
+EntityID.player
 , true, 
@@ -371,24 +371,44 @@
 00, 0, 0);%0A%0A
+%09%09this.name = name;%0A
 %09%09this.textu
@@ -3589,7 +3589,57 @@
 %09%7D%0A%0A
+%09public String getName() %7B%0A%09%09return this.name;%0A%09%7D
 %09%0A%7D
+%0A

Update Player.java