daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Nov 16th, 2018 230 in 22 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. overlapsWall = (x, y) ->
  2.     return true if isWall(x, y)   or isWall(x+8, y)
  3.     return true if isWall(x, y+8) or isWall(x+8, y+8)
  4.     false
  5.  
  6. move: (vec_x, vec_y) =>
  7.     return if vec_x == 0 and vec_y == 0
  8.     x, y, speed = @x, @y, @speed
  9.  
  10.     x_n, y_n = normalize(vec_x, vec_y)
  11.     dx, dy = x_n*speed, y_n*speed
  12.        
  13.     --If moving into a wall, nullify the respective vector component
  14.     dx = 0 if overlapsWall(x+dx, y)
  15.     dy = 0 if overlapsWall(x, y+dy)
  16.  
  17.     @x += dx
  18.     @y += dy
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top