stoneharry

Untitled

Jan 16th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1.     protected void moveTowardsObject(Point p, World world, Entity entity)
  2.     {
  3.         // Temp values for target position
  4.         int n_x = entity.getT_X();
  5.         int n_y = entity.getT_Y();
  6.         // Decide what the desired movement is
  7.         if (p.x < n_x)
  8.             --n_x;
  9.         else if (p.x > n_x)
  10.             ++n_x;
  11.         else if (p.y < n_y)
  12.             --n_y;
  13.         else if (p.y > n_y)
  14.             ++n_y;
  15.         // Get any objects at destination tile
  16.         if (world.getObjValue(n_x, n_y) == GlobalStaticVars.WORLD_VALUE.HUMAN_1)
  17.         {
  18.             // Get out of the way
  19.             moveRandom(world, entity);
  20.             return;
  21.         }
  22.        
  23.         // Check if tree exists at target location. If it does, try to move around it
  24.         if (world.getObjValue(n_x, n_y) == GlobalStaticVars.WORLD_VALUE.TREE_1
  25.                 || world.getObjValue(n_x + 1, n_y - 1) == GlobalStaticVars.WORLD_VALUE.TREE_1)
  26.         {
  27.            
  28.         }
  29.        
  30.         // If all tests passed, update current position
  31.         entity.setT_X(n_x);
  32.         entity.setT_Y(n_y);
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment