Fixed bugs in Level Changes
Fixed bugs in Level Changes
Stairs in Player House work again
Building exits work properly again
Moved nextTile funciton from movmentAnimator to Pose
Adjusted all mat tiles to have
exit point 1 less in y axis
Fixed any Tranistion Tile bugs besides Cave
Adjusted Grid function to return proper LevelChange for Mat Tiles
Movment animator keyboard control no longer depends on player position,
but uses fed position instead
Added function to check if a level transition is stepOnLeave and fixed
bug in rightDirection to compenaste for Direction.NONE in LevelChange

--- a/res/Tiles.json
+++ b/res/Tiles.json
@@ -378,7 +378,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":4,
-		"ynew":4,
+		"ynew":3,
 		"rf":null
 	},
 	{
@@ -1325,7 +1325,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":12,
-		"ynew":4,
+		"ynew":3,
 		"rf":null
 	},
 	{
@@ -1397,7 +1397,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":11,
-		"ynew":10,
+		"ynew":9,
 		"rf":null
 	},
 	{
@@ -1770,7 +1770,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":13,
-		"ynew":7,
+		"ynew":6,
 		"rf":null
 	},
 	{
@@ -1798,7 +1798,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":13,
-		"ynew":13,
+		"ynew":12,
 		"rf":null
 	},
 	{
@@ -1994,7 +1994,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":15,
-		"ynew":23,
+		"ynew":22,
 		"rf":null
 	},
 	{
@@ -2302,7 +2302,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":9,
-		"ynew":26,
+		"ynew":25,
 		"rf":null
 	},
 	{
@@ -3568,7 +3568,7 @@
 		"pixelOffsetY":0,
 		"changeToLevel":14,
 		"leaveDirection":"UP",
-		"exitDir":"UP",
+		"exitDir":"NONE",
 		"xnew":12,
 		"ynew":43,
 		"rf":null
@@ -3612,7 +3612,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":1,
-		"ynew":-3,
+		"ynew":-4,
 		"rf":null
 	},
 	{
@@ -3696,7 +3696,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":3,
-		"ynew":0,
+		"ynew":-1,
 		"rf":null
 	},
 	{
@@ -4181,7 +4181,7 @@
 		"leaveDirection":"UP",
 		"exitDir":"UP",
 		"xnew":0,
-		"ynew":3,
+		"ynew":2,
 		"rf":null
 	},
 	{
@@ -4195,7 +4195,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":-3,
-		"ynew":-4,
+		"ynew":-5,
 		"rf":null
 	},
 	{
@@ -4207,7 +4207,7 @@
 		"pixelOffsetY":0,
 		"changeToLevel":16,
 		"leaveDirection":"UP",
-		"exitDir":"UP",
+		"exitDir":"NONE",
 		"xnew":9,
 		"ynew":47,
 		"rf":null
@@ -4694,7 +4694,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":1,
-		"ynew":-3,
+		"ynew":-4,
 		"rf":null
 	},
 	{
@@ -4708,7 +4708,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":1,
-		"ynew":-3,
+		"ynew":-4,
 		"rf":null
 	},
 	{
@@ -4722,7 +4722,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":15,
-		"ynew":-4,
+		"ynew":-5,
 		"rf":null
 	},
 	{
@@ -4734,7 +4734,7 @@
 		"pixelOffsetY":0,
 		"changeToLevel":18,
 		"leaveDirection":"UP",
-		"exitDir":"UP",
+		"exitDir":"NONE",
 		"xnew":0,
 		"ynew":3,
 		"rf":null
@@ -4748,7 +4748,7 @@
 		"pixelOffsetY":0,
 		"changeToLevel":17,
 		"leaveDirection":"UP",
-		"exitDir":"UP",
+		"exitDir":"NONE",
 		"xnew":17,
 		"ynew":19,
 		"rf":null
@@ -4778,7 +4778,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":12,
-		"ynew":18,
+		"ynew":17,
 		"rf":null
 	},
 	{
@@ -4890,7 +4890,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":15,
-		"ynew":4,
+		"ynew":3,
 		"rf":null
 	},
 	{
@@ -4918,7 +4918,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":3,
-		"ynew":30,
+		"ynew":29,
 		"rf":null
 	},
 	{
@@ -4946,7 +4946,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":25,
-		"ynew":14,
+		"ynew":13,
 		"rf":null
 	},
 	{
@@ -4974,7 +4974,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":21,
-		"ynew":17,
+		"ynew":16,
 		"rf":null
 	},
 	{
@@ -5002,7 +5002,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":19,
-		"ynew":18,
+		"ynew":17,
 		"rf":null
 	},
 	{
@@ -5156,7 +5156,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":15,
-		"ynew":6,
+		"ynew":5,
 		"rf":null
 	},
 	{
@@ -5184,7 +5184,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":10,
-		"ynew":8,
+		"ynew":7,
 		"rf":null
 	},
 	{
@@ -5381,7 +5381,7 @@
 		"leaveDirection":"DOWN",
 		"exitDir":"DOWN",
 		"xnew":7,
-		"ynew":2,
+		"ynew":1,
 		"rf":null
 	},
 	{
@@ -5491,9 +5491,9 @@
 		"pixelOffsetY":0,
 		"changeToLevel":28,
 		"leaveDirection":"DOWN",
-		"exitDir":"NONE",
+		"exitDir":"DOWN",
 		"xnew":14,
-		"ynew":2,
+		"ynew":1,
 		"rf":null
 	},
 	{
@@ -6246,8 +6246,8 @@
 		"changeToLevel":33,
 		"leaveDirection":"UP",
 		"exitDir":"NONE",
-		"xnew":-2,
-		"ynew":1,
+		"xnew":-4,
+		"ynew":-4,
 		"rf":null
 	}
 ]

--- a/src/com/dryerzinia/pokemon/map/Grid.java
+++ b/src/com/dryerzinia/pokemon/map/Grid.java
@@ -1,4 +1,5 @@
 package com.dryerzinia.pokemon.map;

+

 import java.io.*;

 import java.awt.*;

 import java.util.*;

@@ -8,7 +9,6 @@
 import com.dryerzinia.pokemon.obj.RandomFight;

 import com.dryerzinia.pokemon.obj.tiles.Ledge;

 import com.dryerzinia.pokemon.obj.tiles.Tile;

-import com.dryerzinia.pokemon.ui.menu.GMenu;

 import com.dryerzinia.pokemon.util.JSON;

 

 public class Grid implements Serializable, JSON {

@@ -142,7 +142,22 @@
 

     }

 

-    public LevelChange changeLevel(int x, int y) {

+    public LevelChange changeLevel(Pose location, Point futureLocation) {

+

+		int x = (int) location.getX();

+		int y = (int) location.getY();

+

+        // Step off logic

+    	try {

+    		// TODO fix the 4 4 offset in the maps

+    		for(int i = 0; i < grid[x][y].size(); i++){

+    			if(grid[x][y].get(i).changeToLevel != -1 && grid[x][y].get(i).exitDir != Direction.NONE)

+    				return new LevelChange(grid[x][y].get(i).xnew+4, grid[x][y].get(i).ynew+4, grid[x][y].get(i).changeToLevel, grid[x][y].get(i).exitDir, grid[x][y].get(i).leaveDirection);

+    		}

+    	} catch(Exception e){}

+

+    	x = futureLocation.getX();

+    	y = futureLocation.getY();

 

         if(x < 0 && l.borderL != null && l.borderL[0] != null){

         	if(l.borderL[0].grid.canStepOn(l.borderL[0].grid.getWidth() - 1, (int) ClientState.player.getPose().getY() + l.borderoffset[0]))

@@ -168,9 +183,8 @@
 

         // TODO fix the 4 4 offset in the maps

         for(int i = 0; i < grid[x][y].size(); i++)

-            if(grid[x][y].get(i).changeToLevel != -1)

-            	return new LevelChange(grid[x][y].get(i).xnew+4, grid[x][y].get(i).ynew+4, grid[x][y].get(i).changeToLevel, grid[x][y].get(i).leaveDirection, grid[x][y].get(i).exitDir);

-        

+            if(grid[x][y].get(i).changeToLevel != -1 && grid[x][y].get(i).exitDir == Direction.NONE)

+            	return new LevelChange(grid[x][y].get(i).xnew+4, grid[x][y].get(i).ynew+4, grid[x][y].get(i).changeToLevel, grid[x][y].get(i).exitDir, grid[x][y].get(i).leaveDirection);

 

         return null;

     }


--- a/src/com/dryerzinia/pokemon/map/Pose.java
+++ b/src/com/dryerzinia/pokemon/map/Pose.java
@@ -38,6 +38,34 @@
 	public Pose copy(){
 		return new Pose(x, y, level, facing);
 	}
+
+    /**
+     * Returns the x y of the next tile player will step on
+     * @param position Location of the player
+     * @return Next point the player will step on
+     */
+    public Point nextTile(){
+    
+    	switch(facing){
+    		case UP:
+    			return new Point((int) Math.ceil(x), (int) Math.ceil(y - 1));
+
+    		case DOWN:
+    			return new Point((int) Math.floor(x), (int) Math.floor(y + 1));
+
+    		case LEFT:
+    			return new Point((int) Math.ceil(x - 1), (int) Math.ceil(y));
+
+    		case RIGHT:
+    			return new Point((int) Math.floor(x + 1), (int) Math.floor(y));
+    	
+    		case NONE:
+    			throw new IllegalArgumentException("Player is facing direction NONE!");
+    	}
+
+    	return null;
+
+    }
 
 	public float getX(){
 		return x;
@@ -99,7 +127,7 @@
 	public void setLevel(int level){
 		this.level = level;
 	}
-
+	
 	public String toString(){
 		return "{x:"+x+",y:"+y+",level:"+level+",facing:"+facing+"}";
 	}

--- a/src/com/dryerzinia/pokemon/obj/LevelChange.java
+++ b/src/com/dryerzinia/pokemon/obj/LevelChange.java
@@ -28,8 +28,17 @@
 
 	}
 
+	public boolean stepOnLeave(){
+		return toLeaveDirection != Direction.NONE;
+	}
+
 	public boolean rightDirection(Direction direction){
+
+		if(toLeaveDirection == Direction.NONE)
+			return true;
+
 		return direction == toLeaveDirection;
+
 	}
 
 	public Pose getNewPosition(){

--- a/src/com/dryerzinia/pokemon/obj/MovementAnimator.java
+++ b/src/com/dryerzinia/pokemon/obj/MovementAnimator.java
@@ -58,7 +58,7 @@
 
 	/*
 	 * When the character is making a movement from the movements list the
-	 * character needs to keep track of where he is going so he cant set
+	 * character needs to keep track of where he is going so he can set
 	 * his X, Y and level variables accordingly if there is a malfunction
 	 * and he misses a movement update
 	 */
@@ -158,32 +158,31 @@
     			return position.copy();
     		}
 
-    		setState(position, nextTile(position), false);
+    		setState(position, position.nextTile(), false);
 
     		/*
     		 * Figure out where we are going
     		 */
-    		Pose pose = ClientState.player.getPose();
     		Pose newPose = null;
     		if(state == STEPPING){
 
-    			Point newPoint = nextTile(pose);
-
-    			Level level = GameState.getMap().getLevel(pose.getLevel());
+    			Point newPoint = position.nextTile();
+
+    			Level level = GameState.getMap().getLevel(position.getLevel());
     	    	boolean canStep = level.canStepOn(newPoint.getX(), newPoint.getY(), isPlayer);
-    	    	LevelChange levelChange = level.grid.changeLevel(newPoint.getX(), newPoint.getY());    			
+    	    	LevelChange levelChange = level.grid.changeLevel(position, newPoint);    			
 
     	    	if(canStep || levelChange != null)
-    	    		newPose = new Pose(newPoint.getX(), newPoint.getY(), pose.getLevel(), direction);
+    	    		newPose = new Pose(newPoint.getX(), newPoint.getY(), position.getLevel(), direction);
     	    	else
-    	    		newPose = pose.copy();
+    	    		newPose = position.copy();
 
     		} else if(state == JUMPING){
 
-    			Point newPoint = nextTile(pose);
-    			newPose = new Pose(newPoint.getX(), newPoint.getY(), pose.getLevel(), direction);
-    			newPoint = nextTile(newPose);
-    			newPose = new Pose(newPoint.getX(), newPoint.getY(), pose.getLevel(), direction);
+    			Point newPoint = position.nextTile();
+    			newPose = new Pose(newPoint.getX(), newPoint.getY(), position.getLevel(), direction);
+    			newPoint = newPose.nextTile();
+    			newPose = new Pose(newPoint.getX(), newPoint.getY(), position.getLevel(), direction);
 
     		}
 
@@ -230,7 +229,7 @@
     		/*
     		 * See where character is going
     		 */
-        	Point futurePoint = nextTile(position);
+        	Point futurePoint = position.nextTile();
         	Level level = GameState.getMap().getLevel(position.getLevel());
 
         	boolean levelChanged = false;
@@ -250,7 +249,7 @@
 
         	} else {
 
-        		LevelChange levelChange = level.grid.changeLevel(futurePoint.getX(), futurePoint.getY());
+        		LevelChange levelChange = level.grid.changeLevel(position, futurePoint);
             	if(levelChange != null)
             		levelChanged = true;
 
@@ -258,7 +257,7 @@
 
         	boolean canStepNew = level.canStepOn(futurePoint.getX(), futurePoint.getY(), isPlayer);
 
-        	boolean overrideCanStep = setState(position, nextTile(position), sameSpot);
+        	boolean overrideCanStep = setState(position, position.nextTile(), sameSpot);
 
         	/*
         	 * If we are in different spot move
@@ -271,7 +270,7 @@
     		if(!sameSpot || !(canStepNew || directionChange || overrideCanStep) && !(levelChanged && directionChange)){
 
     			elapsedTime += deltaTime;
-    			animationMove(position, deltaTime);
+    			animationMove(position, deltaTime, false);
 
     		}
     	}
@@ -307,7 +306,7 @@
 	 * @param position Current character position to be moved (mutated) forward
 	 * @param deltaTime Change in time since last move in milliseconds
 	 */
-    private void animationMove(Pose position, int deltaTime){
+    private void animationMove(Pose position, int deltaTime, boolean finishing){
 
     	/*
     	 * Before we can move we have to make sure the tile can be stepped on
@@ -315,12 +314,12 @@
     	 * the characters sprite so we can do the wall bump
     	 */
     	
-    	Point futurePoint = nextTile(position);
+    	Point futurePoint = position.nextTile();
 
     	Level level = GameState.getMap().getLevel(position.getLevel());
 
     	boolean canStep = level.canStepOn(futurePoint.getX(), futurePoint.getY(), isPlayer);
-    	LevelChange levelChange = level.grid.changeLevel(futurePoint.getX(), futurePoint.getY());
+    	LevelChange levelChange = level.grid.changeLevel(position, futurePoint);
 
     	/*
     	 * We need to continue the step through to the next level
@@ -330,8 +329,19 @@
     		/*
     		 * If we are the clients player we change positions immediately
     		 */
-    		if(newPosition == null)
-    			position.set(levelChange.getNewPosition());
+    		if(newPosition == null){
+    			if(finishing && !levelChange.stepOnLeave()){
+
+       				elapsedTime = 0;
+
+    				position.set(levelChange.getNewPosition());
+
+    			} else if(levelChange.stepOnLeave()){
+
+    				position.set(levelChange.getNewPosition());
+
+    			}
+   			}
     		canStep = true;
 
     	}
@@ -404,7 +414,7 @@
     		/*
     		 * we have to get even with the square
     		 */
-   			animationMove(position, (int)(deltaTime-(elapsedTime-stepTime)));
+   			animationMove(position, (int)(deltaTime-(elapsedTime-stepTime)), true);
    			if(newPosition == null){
    				position.setX(Math.round(position.getX()));
    				position.setY(Math.round(position.getY()));
@@ -433,7 +443,7 @@
 	    			deltaTime = (int) (elapsedTime - stepTime);
 	    			elapsedTime = 0;
 
-	    			update(direction, position, elapsedTime);
+	    			update(direction, position, deltaTime);
 
 	    		}
 
@@ -452,6 +462,10 @@
     			deltaTime = (int) (elapsedTime - stepTime);
     			elapsedTime = 0;
 
+    			// Fix for level change bounce back when stepping though a door
+    			if(deltaTime < 0)
+    				deltaTime = 0;
+
     			/*
     			 * Continue with next update
     			 */
@@ -465,36 +479,8 @@
    		 * Otherwise we just move like normal
    		 */
     	else
-    		animationMove(position, deltaTime);
-
-
-    }
-
-    /**
-     * Returns the x y of the next tile player will step on
-     * @param position Location of the player
-     * @return Next point the player will step on
-     */
-    private Point nextTile(Pose position){
-    
-    	switch(position.facing()){
-    	case UP:
-    		return new Point((int) Math.ceil(position.getX()), (int) Math.ceil(position.getY() - 1));
-
-    	case DOWN:
-    		return new Point((int) Math.floor(position.getX()), (int) Math.floor(position.getY() + 1));
-
-    	case LEFT:
-    		return new Point((int) Math.ceil(position.getX() - 1), (int) Math.ceil(position.getY()));
-
-    	case RIGHT:
-    		return new Point((int) Math.floor(position.getX() + 1), (int) Math.floor(position.getY()));
-    	
-    	case NONE:
-    		throw new IllegalArgumentException("Player is facing direction NONE!");
-    	}
-
-    	return null;
+    		animationMove(position, deltaTime, false);
+
 
     }
 

--- a/src/com/dryerzinia/pokemon/obj/tiles/Tile.java
+++ b/src/com/dryerzinia/pokemon/obj/tiles/Tile.java
@@ -107,6 +107,7 @@
         return img;

     }

 

+    @Override

     public String toString() {

         return imgName;

     }