|  | @@ -0,0 +1,135 @@
 | 
	
		
			
				|  |  | +/*
 | 
	
		
			
				|  |  | + * To change this license header, choose License Headers in Project Properties.
 | 
	
		
			
				|  |  | + * To change this template file, choose Tools | Templates
 | 
	
		
			
				|  |  | + * and open the template in the editor.
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +package gameplay;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import me.hammerle.snuviengine.api.KeyBinding;
 | 
	
		
			
				|  |  | +import me.hammerle.snuviengine.api.KeyHandler;
 | 
	
		
			
				|  |  | +import me.hammerle.snuviengine.api.Renderer;
 | 
	
		
			
				|  |  | +import me.hammerle.snuviengine.api.Texture;
 | 
	
		
			
				|  |  | +import org.lwjgl.glfw.GLFW;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + * @author Julia
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +public class Hiker {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private float oldX = 0;
 | 
	
		
			
				|  |  | +    private float oldY = 0;
 | 
	
		
			
				|  |  | +    private float x = 0;
 | 
	
		
			
				|  |  | +    private float y = 0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static final float speed = 2;
 | 
	
		
			
				|  |  | +    private static final float maxWidth = 1024;
 | 
	
		
			
				|  |  | +    private static final float maxHeight = 1024;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private enum moveStates {
 | 
	
		
			
				|  |  | +        still, left, right, up, down
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +    private moveStates moveState = moveStates.still;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static final Texture characterFront = new Texture("res\\character\\characterFront.png");
 | 
	
		
			
				|  |  | +    private static final Texture characterLeft = new Texture("res\\character\\characterLeft.png");
 | 
	
		
			
				|  |  | +    private static final Texture characterRight = new Texture("res\\character\\characterRight.png");
 | 
	
		
			
				|  |  | +    private static final Texture characterBack = new Texture("res\\character\\characterBack.png");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static final KeyBinding UP_KEY = KeyHandler.register(GLFW.GLFW_KEY_W);
 | 
	
		
			
				|  |  | +    private static final KeyBinding DOWN_KEY = KeyHandler.register(GLFW.GLFW_KEY_S);
 | 
	
		
			
				|  |  | +    private static final KeyBinding LEFT_KEY = KeyHandler.register(GLFW.GLFW_KEY_A);
 | 
	
		
			
				|  |  | +    private static final KeyBinding RIGHT_KEY = KeyHandler.register(GLFW.GLFW_KEY_D);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void Hiker() {
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void tick() {
 | 
	
		
			
				|  |  | +        calcMoveState();
 | 
	
		
			
				|  |  | +        animate();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        oldX = x;
 | 
	
		
			
				|  |  | +        oldY = y;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (LEFT_KEY.isDown() && moveState != moveStates.up && moveState != moveStates.down && x > 0) {
 | 
	
		
			
				|  |  | +            x -= speed;
 | 
	
		
			
				|  |  | +        } else if (RIGHT_KEY.isDown() && moveState != moveStates.up && moveState != moveStates.down && x < maxWidth) {
 | 
	
		
			
				|  |  | +            x += speed;
 | 
	
		
			
				|  |  | +        } else if (UP_KEY.isDown() && moveState != moveStates.left && moveState != moveStates.right && y > 0) {
 | 
	
		
			
				|  |  | +            y -= speed;
 | 
	
		
			
				|  |  | +        } else if (DOWN_KEY.isDown() && moveState != moveStates.left && moveState != moveStates.right && y < maxHeight) {
 | 
	
		
			
				|  |  | +            y += speed;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            if (x % 32 != 0 || y % 32 != 0) {
 | 
	
		
			
				|  |  | +                if (moveState == moveStates.left) {
 | 
	
		
			
				|  |  | +                    x -= speed;
 | 
	
		
			
				|  |  | +                } else if (moveState == moveStates.right) {
 | 
	
		
			
				|  |  | +                    x += speed;
 | 
	
		
			
				|  |  | +                } else if (moveState == moveStates.up) {
 | 
	
		
			
				|  |  | +                    y -= speed;
 | 
	
		
			
				|  |  | +                } else if (moveState == moveStates.down) {
 | 
	
		
			
				|  |  | +                    y += speed;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void renderTick(Renderer r, float lag) {
 | 
	
		
			
				|  |  | +        r.setMixColorEnabled(false);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        renderTestBackground(r);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        r.setColorEnabled(false);
 | 
	
		
			
				|  |  | +        r.setTextureEnabled(true);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        r.translateTo(0.0f, 0.0f);
 | 
	
		
			
				|  |  | +        r.updateMatrix();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        float ix = oldX + (x - oldX) * lag;
 | 
	
		
			
				|  |  | +        float iy = oldY + (y - oldY) * lag;
 | 
	
		
			
				|  |  | +        r.getTextureRenderer().drawRectangle(ix, iy, ix + 32, iy + 32, 0, 0, 1, 1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void calcMoveState() {
 | 
	
		
			
				|  |  | +        if (oldX == x && oldY == y) {
 | 
	
		
			
				|  |  | +            moveState = moveStates.still;
 | 
	
		
			
				|  |  | +        } else if (oldX > x) {
 | 
	
		
			
				|  |  | +            moveState = moveStates.left;
 | 
	
		
			
				|  |  | +        } else if (oldX < x) {
 | 
	
		
			
				|  |  | +            moveState = moveStates.right;
 | 
	
		
			
				|  |  | +        } else if (oldY > y) {
 | 
	
		
			
				|  |  | +            moveState = moveStates.up;
 | 
	
		
			
				|  |  | +        } else if (oldY < y) {
 | 
	
		
			
				|  |  | +            moveState = moveStates.down;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void animate() {
 | 
	
		
			
				|  |  | +        if (moveState == moveStates.still || moveState == moveStates.down) {
 | 
	
		
			
				|  |  | +            characterFront.bind();
 | 
	
		
			
				|  |  | +        } else if (moveState == moveStates.left) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            characterLeft.bind();
 | 
	
		
			
				|  |  | +        } else if (moveState == moveStates.right) {
 | 
	
		
			
				|  |  | +            characterRight.bind();
 | 
	
		
			
				|  |  | +        } else if (moveState == moveStates.up) {
 | 
	
		
			
				|  |  | +            characterBack.bind();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void renderTestBackground(Renderer r) {
 | 
	
		
			
				|  |  | +        r.setColorEnabled(true);
 | 
	
		
			
				|  |  | +        r.setTextureEnabled(false);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(0, 0, 32, 32, 0xFF0000FF);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(32, 0, 64, 32, 0xFF00FF00);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(0, 32, 32, 64, 0xFF00FF00);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(32, 32, 64, 64, 0xFF0000FF);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(64, 0, 96, 32, 0xFF0000FF);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(0, 64, 32, 96, 0xFF0000FF);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(64, 32, 96, 64, 0xFF00FF00);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(32, 64, 64, 96, 0xFF00FF00);
 | 
	
		
			
				|  |  | +        r.getColorRenderer().drawRectangle(64, 64, 96, 96, 0xFF0000FF);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |