So, in my game, there are two players, Crusader Red and Crusader Blue. They can each press a key to summon a lobster. Fun!
Code: Select all
function crusaderControl(crusaderTable, dt, up, down, left, right, shoot)
-- movement code here. blahblah...
-- The fun stuff: lobster summoning!
if love.keyboard.isDown(shoot) and crusaderTable.canShoot then
newlobster = {
x = (crusaderTable.x)+21, -- spawn from center of player
y = (crusaderTable.y)+32,
img = crusaderTable.lobsterImg,
speed = 50
}
table.insert(crusaderTable.lobsters, newlobster)
crusaderTable.canShoot = false
crusaderTable.canShootTimer = crusaderTable.canShootTimerMax
crusaderTable.lobsterCount = crusaderTable.lobsterCount + 1
end
end
Code: Select all
--collision check function, from the love wiki:
function CheckCollision(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
--Now the fun fun stuff. A lobster collides with another player.
for i, lobster in ipairs(crusaderTable.lobsters) do
--If player generated lobsters collide with other player crusader,
--the lobster is destroyed and you get 1000 pts.
if CheckCollision (lobster.x, lobster.y, lobster.img:getWidth(), lobster.img:getHeight(), theirCrusader.x, theirCrusader.y, theirCrusader.width, theirCrusader.height) then
crusaderTable.score = crusaderTable.score +1000
end
end