Advertisement
Guest User

game.lua

a guest
Aug 30th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. function game_load()
  2. heart_create(200, 100)
  3. spike_create(300, 500)
  4. end
  5.  
  6. function game_update(dt)
  7. player_update(dt)
  8. heart_update(dt)
  9. spike_update(dt)
  10. end
  11.  
  12. function game_draw()
  13. player_draw()
  14.  
  15. love.graphics.push()
  16. love.graphics.translate(-scrollfactor, 0)
  17. heart_draw()
  18. spike_draw()
  19.  
  20. love.graphics.pop()
  21.  
  22. love.graphics.setColor(0, 0, 0)
  23.  
  24. end
  25.  
  26. function game_keypressed(key)
  27. player_keypressed(key)
  28. end
  29.  
  30. function aabb(x1,y1,w1,h1, x2,y2,w2,h2)
  31. return x1 < x2+w2 and
  32. x2 < x1+w1 and
  33. y1 < y2+h2 and
  34. y2 < y1+h1
  35. end
  36.  
  37. function trianglecollide(v1, v2) --By Qcode
  38. local pointcollide
  39. if (v2.x1 > v1.x and v2.x1 < v1.x + v1.width and v2.y1 > v1.y and v2.y1 < v1.y + v1.height) or (v2.x2 > v1.x and v2.x2 < v1.x + v1.width and v2.y2 > v1.y and v2.y2 < v1.y + v1.height) or (v2.x3 > v1.x and v2.x3 < v1.x + v1.width and v2.y3 > v1.y and v2.y3 < v1.y + v1.height) then
  40. pointcollide = true
  41. end
  42.  
  43. if not pointcollide then
  44. local x, y = {v2.x1, v2.x2, v2.x3}, {v2.y1, v2.y2, v2.y3}
  45. for i = 1, 3 do
  46. local second = i+1
  47. if i+1 > 3 then
  48. second = 1
  49. end
  50. if findlineIntersect(x[i], y[i], x[second], y[second], v1.x, v1.y, v1.x+v1.width, v1.y, true, true) or
  51. findlineIntersect(x[i], y[i], x[second], y[second], v1.x, v1.y, v1.x, v1.y+v1.height, true, true) or
  52. findlineIntersect(x[i], y[i], x[second], y[second], v1.x, v1.y + v1.height, v1.x + v1.width, v1.y+v1.height, true, true) or
  53. findlineIntersect(x[i], y[i], x[second], y[second], v1.x + v1.width, v1.y, v1.x+v1.width, v1.y+v1.height, true, true) then
  54. pointcollide = true
  55. --break
  56. end
  57. end
  58. end
  59. return pointcollide
  60. end
  61.  
  62. --By some nerd
  63. function findlineIntersect(l1p1x,l1p1y, l1p2x,l1p2y, l2p1x,l2p1y, l2p2x,l2p2y, seg1, seg2)
  64. local a1,b1,a2,b2 = l1p2y-l1p1y, l1p1x-l1p2x, l2p2y-l2p1y, l2p1x-l2p2x
  65. local c1,c2 = a1*l1p1x+b1*l1p1y, a2*l2p1x+b2*l2p1y
  66. local det,x,y = a1*b2 - a2*b1
  67. if det==0 then return false, "The lines are parallel." end
  68. x,y = (b2*c1-b1*c2)/det, (a1*c2-a2*c1)/det
  69. if seg1 or seg2 then
  70. local min,max = math.min, math.max
  71. if seg1 and not (min(l1p1x,l1p2x) <= x and x <= max(l1p1x,l1p2x) and min(l1p1y,l1p2y) <= y and y <= max(l1p1y,l1p2y)) or
  72. seg2 and not (min(l2p1x,l2p2x) <= x and x <= max(l2p1x,l2p2x) and min(l2p1y,l2p2y) <= y and y <= max(l2p1y,l2p2y)) then
  73. return false, "The lines don't intersect."
  74. end
  75. end
  76. return x,y
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement