Advertisement
Pinkishu

Untitled

Oct 18th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. /* checkWall checks if a specified x/y tile is a wall
  2. additionally it can check if a NPC also has its bounding box inside that tiles
  3. @ x (integer) : x position to check (in tile coordinates)
  4. @ y (integer) : y position to check (in tile coordinates)
  5. @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
  6. @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the tile
  7.  
  8. returns: object info
  9. { collision, tileCollision, npcCollision }
  10. @ collision (boolean) : if a collision has been found
  11. @ tileCollision (array) : array of objects with info on the collision { layer, tile, collision } => layer is the layer of the collision, tile is the tile, collision is a boolean that says if it collided
  12. @ npcCollision (array) : array of NPC objects that collided (if checkNPC was true)
  13. */
  14.  
  15. /* checkWallArea checks if a specified area has any collisions
  16. this will call checkWall and always pass checkNPC as false, since it easier to just run its own check on the whole area it is checking
  17. @ x (integer) : x position to start the check (in tile coordinates)
  18. @ y (integer) : y position to start the check (in tile coordinates)
  19. @ w (integer) : width of the area to check (in tile coordinates)
  20. @ h (integer) : height of the area to check (in tile coordinates)
  21. @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
  22. @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the area
  23.  
  24. returns: object info
  25. { collision, tileCollision, npccollision }
  26. @ collision (boolean) : if any collision has been found
  27. @ tileCollision (2D-array) : 2D array of the checked area, each element being a return of checkWall call
  28. @ npcCollision (array) : array of NPCs that have a bounding box that intersects or overlaps with the checked area
  29. */
  30.  
  31. /* checkRect checks a rect with direction
  32. @ x (float) : x position of where the rect start (in world coordinates)
  33. @ y (float) : y position of where the rect starts (in world coordinates)
  34. @ w (float) : width of the rect
  35. @ h (float) : height of the rect
  36. @ direction (integer) : direction to stop through the rect (0 = up, 1 = right, 2 = down, 3 = left)
  37. @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
  38. @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the rect
  39. @ stopOnFirst (boolean) : if to return on first step that has a collision or keep going
  40.  
  41. returns object info
  42. { steps, collision, collisions }
  43. @ steps (integer) : steps taken
  44. @ collision (boolean) : if a collision happened at all
  45. @ collisions (array) : array, step as index, each value being a return of checkWallArea (thus [0] will always be the first step and so on)
  46. */
  47.  
  48. /* collideMovement calls checkRect with the right parameters and calculates the new move vector that should be applied
  49. @ sprite (Phaser.Sprite) : the sprite to check the collision for
  50. @ moveVector (array) : array of the x/y movement that is desired
  51. @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
  52. @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the sprite
  53.  
  54. returns object
  55. { newMoveVecto, rectCollisionInfo }
  56. @ newMoveVector (array) : x/y movement that should be applied
  57. @ rectCollisionInfo (object) : return of checkRect
  58. */
  59.  
  60. /* doMove just calls collideMovement and applies the return vector
  61. @ sprite (Phaser.Sprite) : the sprite to move
  62. @ moveVector (array) : x/y desired movement
  63. @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
  64. @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the sprite during the movement
  65.  
  66. returns nothing
  67. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement