Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. fun canWalkInto(pos : Vector2): Boolean {
  2. var localPosX: Int = (pos.x.toInt() - x * GameConstants.PIXEL_SIZE) / GameConstants.PIXEL_SIZE
  3. var localPosY: Int = (pos.y.toInt() - y * GameConstants.PIXEL_SIZE) / GameConstants.PIXEL_SIZE
  4.  
  5. if (localPosX >= if (rot == 0 || rot == 2) def.shape.w - 1 else def.shape.h - 1)
  6. localPosX = if (rot == 0 || rot == 2) def.shape.w - 1 else def.shape.h - 1
  7.  
  8. if (localPosY >= if (rot == 1 || rot == 3) def.shape.w - 1 else def.shape.h - 1)
  9. localPosY = if (rot == 1 || rot == 3) def.shape.w - 1 else def.shape.h - 1
  10.  
  11. //Cases of < 0 will be handled by the "/" operation
  12.  
  13. var internals = def.internalCollision
  14. if (internals.equals(""))
  15. return !def.isWall
  16.  
  17. //rotations
  18. when (rot) {
  19. 0 -> return internals[localPosX + localPosY * def.shape.h] == 'a' // x, y
  20. 1 -> return internals[localPosY + (def.shape.w - localPosX - 1) * def.shape.w] == 'a' // y, -x
  21. 2 -> return internals[(def.shape.w - localPosX - 1) + (def.shape.h - localPosY - 1) * def.shape.h] == 'a' //-x, -y
  22. 3 -> return internals[(def.shape.h - localPosY - 1) + localPosX * def.shape.w] == 'a' // -y, x
  23. }
  24.  
  25. return !def.isWall
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement