Hi everyone. I need some advice on a game I'm making for a class project. I'm making a basic space shooter game. This is my first time making one from scratch. Currently, I am having trouble with:
I usually have to shoot an enemy several times before it appears off the screen. I can't figure out how to fix my collision detection.
When I shoot one enemy, multiple enemies will disappear from the screen. Also, if I shoot the first enemy that appears at (0,0), all the enemies will disappear and the "you win" message will appear on the screen. How do I fix this?
I would also like to include a second collision detection function that makes the game over screen appear if an enemy ship touches the top of the player. What's a good way to get started with this?
I have one sound effect that will play when the game over screen appears and another one that will play when the "you win" message appears. However, I want the sounds to only play one time instead of over and over, which is what they are currently doing. I can't figure out how to do this.
game development questions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: game development questions
Did this class teach you how to use conditionals? The "if" and "then" thing? That's what you have to use.
Your description of your problems is way too abstract to give a better answer.
Your description of your problems is way too abstract to give a better answer.
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: game development questions
Just upload the .love file for us to look at, or at least describe how you implemented collision detection.
The basic approach of "for every enemy check the distance to every bullet" for example would not cause such problems.
So, what did you do?
The basic approach of "for every enemy check the distance to every bullet" for example would not cause such problems.
So, what did you do?
obey
Re: game development questions
It can be something like this:
Code: Select all
function isCollision (body, bullet)
local minDist = body.r + bullet.r
if math.abs(body.x-bullet.x) < minDist and math.abs(body.y-bullet.y) < minDist then
-- "square" collision
return true
end
return false
end
Code: Select all
for iBullet, bullet in ipairs (bullets) do
if bullet.valid then
for iBody, body in ipairs (bodies) do
if body.valid and isCollision (body, bullet) then
bullet.valid = false
body.valid = false
break -- stop inner loop
end
end
end
end
-- here remove not valid bullets and bodies
Re: game development questions
Yandere dev moment, pogdarkfrei wrote: ↑Sat Dec 04, 2021 10:42 pmCode: Select all
for iBullet, bullet in ipairs (bullets) do if bullet.valid then for iBody, body in ipairs (bodies) do if body.valid and isCollision (body, bullet) then bullet.valid = false body.valid = false break -- stop inner loop end end end end -- here remove not valid bullets and bodies
Who is online
Users browsing this forum: No registered users and 7 guests