package edu.smcm.gamedev.butterseal;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
 * Handles player state and movement on-screen.
 * 
 * @author Sean
 *
 */
public class BSPlayer {
	private static final int FRAME_ROWS = 2;
	private static final int FRAME_COLS = 2;

	BSGameState state;
	AssetManager assets;
	SpriteBatch batch;

	private static class BSAnimation {
		Animation animation;
		Texture spritesheet;
		TextureRegion frames;
		float time;

	    public BSAnimation(String spritesheet) {
		this.spritesheet = new Texture(spritesheet);
		this.setAnimations();
	    }

            public void setAnimations() {
                TextureRegion[][] tmp =
                    TextureRegion.split(this.spritesheet,
                                        this.spritesheet.getWidth() / FRAME_COLS,
                                        this.spritesheet.getHeight() / FRAME_ROWS);
                this.frames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
                int index = 0;
                for (int i = 0; i < FRAME_ROWS; i++) {
                    for (int j = 0; j < FRAME_COLS; j++) {
                        this.frames[index] = tmp[i][j];
                        index += 1;
                    }
                }
                this.animation = new Animation(0.25f, frames);
                this.time = 0f;
            }
        }

	BSAnimation walkUp, walkDown, walkRight, walkLeft, idle;
	TextureRegion currentFrame;

	float x, y;
	
	/**
	 * Draws the player on the screen.
	 */
	public void draw() {
		this.batch.draw(this.currentFrame, this.x, this.y);
	}
	
	/**
	 * Moves in the given direction.
	 * 
	 * If this is not the facing direction,
	 *   then the player will turn into that direction, updating
	 *   the {@link #state} and {@link #facingTile} appropriately.
	 * Otherwise, it's a very simple move.
	 * 
	 * @param direction the direction in which to move
	 */
	public void move(BSDirection direction) {
		switch(state.facing) {
		case NORTH:
			break;
		case SOUTH:
			break;
		case EAST:
			break;
		case WEST:
			break;
		}
	}
	
	private boolean canMove(BSDirection direction) {
		BSTile target = this.getAdjacentTile(direction);
		state.currentMap.getTileProperties(target);
		return true;
	}

	/**
	 * 
	 * @return a tile describing the one we're facing
	 */
	public BSTile getFacingTile() {
		return this.getAdjacentTile(state.facing);
	}
	
	public BSTile getAdjacentTile(BSDirection direction) {
		BSTile adj = new BSTile(state.currentTile);
		switch(direction) {
		case NORTH:
			adj.y += 1;
			break;
		case SOUTH:
			adj.y -= 1;
			break;
		case EAST:
			adj.x -= 1;
			break;
		case WEST:
			adj.x += 1;
			break;
		}
		return adj;
	}
}

@@ -1489,16 +1489,554 @@
 Frame;%0A%0A
+    public BSPlayer(float x, float y) %7B%0A%09walkUp    = new BSAnimation(assetManager.load(AssetInfo.PLAYER_WALK_UP.getAssetPath()));%0A%09walkDown  = new BSAnimation(assetManager.load(AssetInfo.PLAYER_WALK_DOWN.getAssetPath()));%0A%09walkRight = new BSAnimation(assetManager.load(AssetInfo.PLAYER_WALK_RIGHT.getAssetPath()));%0A%09walkLeft  = new BSAnimation(assetManager.load(AssetInfo.PLAYER_WALK_LEFT.getAssetPath()));%0A%09idle      = new BSAnimation(assetManager.load(AssetInfo.PLAYER_IDLE.getAssetPath()));%0A%0A%09this.x = x - 16;%0A%09this.y = y - 16;%0A    %7D%0A%0A
 %09float x

Use BSPlayer.BSAnimation constructor in BSPlayer()