Guest User

Untitled

a guest
May 14th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. box = {}
  2. player = {}
  3. vol = {}
  4. onplat = false
  5.  
  6. function love.load()
  7.  
  8. player.x = 10
  9. player.y = 10
  10. player.w = 10;
  11. player.h = 10;
  12. function coln(wallx,wallw,wally,wallh,playerx,playery,playerh,playerw)
  13. if wallx < playerx + playerw and
  14. playerx < wallx + wallw and
  15. wally < playery + playerh and
  16. playery < wally + wallh then
  17. return true
  18. end
  19. return false
  20. end
  21. function cb(x,y,w,h)
  22. rv = {}
  23. rv.x = x
  24. rv.y = y
  25. rv.w = w
  26. rv.h = h
  27. return rv
  28. end
  29. box[1] = cb(100,400,200,200)
  30. end
  31.  
  32. function love.update(dt)
  33. new = {}
  34. new.x = player.x
  35. new.y = player.y
  36. vol = 2
  37. if love.keyboard.isDown('d') then
  38. new.x = new.x+5
  39. elseif love.keyboard.isDown('a') then
  40. new.x = new.x-5
  41. end
  42. onplat = false
  43. for i=1,#box do
  44. if coln(box[i].x-5,box[i].w-5,box[i].y,box[i].h,new.x,new.y,player.w,player.h) == true then
  45. onplat = true
  46. end
  47. end
  48. if onplat == false then
  49. new.y = new.y+vol
  50. end
  51.  
  52. for i=1,#box do
  53. if coln(box[i].x-5,box[i].w-5,box[i].y-5,box[i].h-5,new.x,new.y,player.w,player.h) == false then
  54. player.y = new.y
  55. player.x = new.x
  56. end
  57. end
  58. end
  59. function love.draw()
  60. for i=1,#box do
  61. love.graphics.rectangle('fill',box[i].x,box[i].y,box[i].w,box[i].h)
  62. end
  63. love.graphics.rectangle('fill', player.x, player.y, player.w, player.h)
  64.  
  65.  
  66. end
Add Comment
Please, Sign In to add comment