LDDestroier

platformer test 2

Apr 4th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. map = {{}}
  2. local tArg = {...}
  3. map = paintutils.serialize(tArg[1])
  4. solidmap = {}
  5. scrollX,scrollY = 0,0
  6. mapX,mapY = 0,#map
  7. for y = 1, #map do
  8.     solidmap[#solidmap+1] = {}
  9.     if map[y][x] == 0 then
  10.         solidmap[y][x] = false
  11.     else
  12.         solidmap[y][x] = true
  13.     end
  14.     if #map[y] > mapX then
  15.         mapX = #map[y]
  16.     end
  17. end
  18.  
  19. guy = {
  20.     name = "player",
  21.     sprite = {{2}},
  22.     x = 1,
  23.     y = 1,
  24.     xsize = 1,
  25.     ysize = 1,
  26.     xv = 0,
  27.     yv = 0,
  28. }
  29.  
  30. checkSolid = function(x,y)
  31.     if map[y] then
  32.         return solidmap[y][x]
  33.     else
  34.         return false
  35.     end
  36. end
  37.  
  38. checkCollision = function(p,strdir,dist)
  39.     local dir
  40.     if strdir:lower() == "down" then --I mean actually down, as in, y+.
  41.         dir = 90
  42.     elseif strdir:lower() == "up" then
  43.         dir = 270
  44.     elseif strdir:lower() == "right" then
  45.         dir = 0
  46.     elseif stdfir:lower() == "left" then
  47.         dir = 180
  48.     end
  49.     if dist < 0 then
  50.         dist = math.abs(dist)
  51.         dir = (dir + 180) % 360
  52.     end
  53.     dir = math.rad(dir) --gosh dang flipping radicals
  54.     for d = 1, dist do
  55.         if checkSolid(p.x*dist*math.cos(dir),p.y*dist*math.sin(dir)) then
  56.             return true, d-1, p.x*(d-1)*math.cos(dir), p.y*(d-1)*math.sin(dir)
  57.         end
  58.     end
  59.     return false,dist,p.x*dist*math.cos(dir),p.y*dist*math.sin(dir)
  60. end
  61.  
  62. moveCollide = function(p,strdir,dist)
  63.     local hit,len,newX,newY = checkCollision(p,strdir,dist)
  64.     p.x,p.y = newX,newY
  65. end
Add Comment
Please, Sign In to add comment