Page 1 of 1

game development questions

Posted: Sat Dec 04, 2021 4:47 pm
by ureiki
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.

Re: game development questions

Posted: Sat Dec 04, 2021 8:13 pm
by grump
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.

Re: game development questions

Posted: Sat Dec 04, 2021 8:19 pm
by BrotSagtMist
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?

Re: game development questions

Posted: Sat Dec 04, 2021 10:42 pm
by darkfrei
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

Posted: Sat Dec 04, 2021 11:05 pm
by GVovkiv
darkfrei wrote: Sat Dec 04, 2021 10:42 pm

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
Yandere dev moment, pog