Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function game_load()
- heart_create(200, 100)
- spike_create(300, 500)
- end
- function game_update(dt)
- player_update(dt)
- heart_update(dt)
- spike_update(dt)
- end
- function game_draw()
- player_draw()
- love.graphics.push()
- love.graphics.translate(-scrollfactor, 0)
- heart_draw()
- spike_draw()
- love.graphics.pop()
- love.graphics.setColor(0, 0, 0)
- end
- function game_keypressed(key)
- player_keypressed(key)
- end
- function aabb(x1,y1,w1,h1, x2,y2,w2,h2)
- return x1 < x2+w2 and
- x2 < x1+w1 and
- y1 < y2+h2 and
- y2 < y1+h1
- end
- function trianglecollide(v1, v2) --By Qcode
- local pointcollide
- 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
- pointcollide = true
- end
- if not pointcollide then
- local x, y = {v2.x1, v2.x2, v2.x3}, {v2.y1, v2.y2, v2.y3}
- for i = 1, 3 do
- local second = i+1
- if i+1 > 3 then
- second = 1
- end
- if findlineIntersect(x[i], y[i], x[second], y[second], v1.x, v1.y, v1.x+v1.width, v1.y, true, true) or
- findlineIntersect(x[i], y[i], x[second], y[second], v1.x, v1.y, v1.x, v1.y+v1.height, true, true) or
- 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
- 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
- pointcollide = true
- --break
- end
- end
- end
- return pointcollide
- end
- --By some nerd
- function findlineIntersect(l1p1x,l1p1y, l1p2x,l1p2y, l2p1x,l2p1y, l2p2x,l2p2y, seg1, seg2)
- local a1,b1,a2,b2 = l1p2y-l1p1y, l1p1x-l1p2x, l2p2y-l2p1y, l2p1x-l2p2x
- local c1,c2 = a1*l1p1x+b1*l1p1y, a2*l2p1x+b2*l2p1y
- local det,x,y = a1*b2 - a2*b1
- if det==0 then return false, "The lines are parallel." end
- x,y = (b2*c1-b1*c2)/det, (a1*c2-a2*c1)/det
- if seg1 or seg2 then
- local min,max = math.min, math.max
- if seg1 and not (min(l1p1x,l1p2x) <= x and x <= max(l1p1x,l1p2x) and min(l1p1y,l1p2y) <= y and y <= max(l1p1y,l1p2y)) or
- seg2 and not (min(l2p1x,l2p2x) <= x and x <= max(l2p1x,l2p2x) and min(l2p1y,l2p2y) <= y and y <= max(l2p1y,l2p2y)) then
- return false, "The lines don't intersect."
- end
- end
- return x,y
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement