Advertisement
Guest User

POINTONSLOPE pico-8

a guest
Feb 7th, 2018
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. function pointonslope(x,y)
  2.  --returns true if x,y overlaps
  3.  --some slope
  4.  
  5.  spriteid=mget(flr8(x),flr8(y))
  6.  
  7.  if not fget(spriteid,1) then
  8.   --tile isn't a slope
  9.   return false
  10.  end
  11.  
  12.  --define slope of tile
  13.  x1=flr8(x)*8
  14.  x2=x1+8
  15.  y1=flr8(y)*8+8
  16.  y2=y1-8
  17.  
  18.  if fget(spriteid,2) then
  19.   --halfstep up
  20.   y2=y1-4
  21.  end
  22.  if fget(spriteid,3) then
  23.   --halfstep up 2
  24.   y1-=4
  25.   y2-=1
  26.  end
  27.  if fget(spriteid,4) then
  28.   --fullstep up
  29.   --this is default so eh
  30.   y2-=1
  31.  end
  32.  if fget(spriteid,5) then
  33.   --fullstep down
  34.   y1=y2
  35.   y2+=8
  36.   y1-=1
  37.  end
  38.  if fget(spriteid,6) then
  39.   --halfstep down 2
  40.   y1=y2
  41.   y2+=4
  42.   y1-=1
  43.  end
  44.  if fget(spriteid,7) then
  45.   --halfstep down
  46.   y2=y1
  47.   y1-=4
  48.  end
  49.  
  50.  --now check if x,y is below
  51.  --the line between p1 and p2
  52.  t=(x2-x)/8
  53.  
  54.  
  55.  height=lerp(y2,y1,t)
  56.  if (height<=y) return true
  57.  
  58.  
  59.  return false
  60.  
  61. end
  62.  
  63. function flr8(v)
  64.  --converts a position from
  65.  --game space to map space
  66.  return flr(v/8)
  67. end
  68.  
  69. function lerp(a,b,t)
  70.  return (1-t)*a+t*b
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement