game development questions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ureiki
Prole
Posts: 1
Joined: Wed Dec 01, 2021 4:09 pm

game development questions

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: game development questions

Post 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.
User avatar
BrotSagtMist
Party member
Posts: 604
Joined: Fri Aug 06, 2021 10:30 pm

Re: game development questions

Post 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?
obey
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: game development questions

Post 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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: game development questions

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests