Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* checkWall checks if a specified x/y tile is a wall
- additionally it can check if a NPC also has its bounding box inside that tiles
- @ x (integer) : x position to check (in tile coordinates)
- @ y (integer) : y position to check (in tile coordinates)
- @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
- @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the tile
- returns: object info
- { collision, tileCollision, npcCollision }
- @ collision (boolean) : if a collision has been found
- @ 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
- @ npcCollision (array) : array of NPC objects that collided (if checkNPC was true)
- */
- /* checkWallArea checks if a specified area has any collisions
- 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
- @ x (integer) : x position to start the check (in tile coordinates)
- @ y (integer) : y position to start the check (in tile coordinates)
- @ w (integer) : width of the area to check (in tile coordinates)
- @ h (integer) : height of the area to check (in tile coordinates)
- @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
- @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the area
- returns: object info
- { collision, tileCollision, npccollision }
- @ collision (boolean) : if any collision has been found
- @ tileCollision (2D-array) : 2D array of the checked area, each element being a return of checkWall call
- @ npcCollision (array) : array of NPCs that have a bounding box that intersects or overlaps with the checked area
- */
- /* checkRect checks a rect with direction
- @ x (float) : x position of where the rect start (in world coordinates)
- @ y (float) : y position of where the rect starts (in world coordinates)
- @ w (float) : width of the rect
- @ h (float) : height of the rect
- @ direction (integer) : direction to stop through the rect (0 = up, 1 = right, 2 = down, 3 = left)
- @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
- @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the rect
- @ stopOnFirst (boolean) : if to return on first step that has a collision or keep going
- returns object info
- { steps, collision, collisions }
- @ steps (integer) : steps taken
- @ collision (boolean) : if a collision happened at all
- @ collisions (array) : array, step as index, each value being a return of checkWallArea (thus [0] will always be the first step and so on)
- */
- /* collideMovement calls checkRect with the right parameters and calculates the new move vector that should be applied
- @ sprite (Phaser.Sprite) : the sprite to check the collision for
- @ moveVector (array) : array of the x/y movement that is desired
- @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
- @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the sprite
- returns object
- { newMoveVecto, rectCollisionInfo }
- @ newMoveVector (array) : x/y movement that should be applied
- @ rectCollisionInfo (object) : return of checkRect
- */
- /* doMove just calls collideMovement and applies the return vector
- @ sprite (Phaser.Sprite) : the sprite to move
- @ moveVector (array) : x/y desired movement
- @ layers (Phaser.Group/Array of Phaser.TilemapLayer) : the layers of the map to check
- @ checkNPC (boolean) : if the function should check for NPC bounding boxes intersecting with the sprite during the movement
- returns nothing
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement