Hi all
Almost total newb here asking what may be a foolish question:
I’ve been working on turning the Side Scroller Tutorial into a top-down vertical scroller, like the 194x series, or dozens of other games I can’t remember the names of.
I’ve got (blocky) clouds floating by, and I’ve turned the stars into two different types of in-game objects. The yellow stars add score, the green ones take away score. In a ‘final’ game the green stars will be replaced by enemy craft that shoot at the player and attempt to crash into the player, costing a life.
I’ve added bullets that fly upward from the player’s plane, basically bullets are just like the stars, just going in the opposite direction.
I want the bullets to destroy the stars if they collide. How do I do that?
The two star scripts currently look like this (pretty much what they were in original)
lua
local speed = -120
local score = -500
function update(self, dt)
local p = go.get_position()
p.y = p.y + speed * dt
if p.y < -32 then
go.delete()
end
go.set_position(p)
end
function on_message(self, message_id, message, sender)
if message_id == hash(“collision_response”) then
msg.post(“main#gui”, “add_score”, {amount = score})
go.delete()
end
end
I’m guessing there is something needed to be more precise in the line:
if message_id == hash(“collision_response”) then
My experience with C/C++ suggests that this line would feed into a for loop checking the coords of each star verses each bullet.
My immediate wish is to set things up that collisions between bullets and the green stars add to the score but collisions between the player’s plane and green stars take away points.
Any advice or wisdom is welcome.
Thank you all.
REgards
Frank