How to change gamestates pressing R and particle cleanup

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
User avatar
IAsep-TrixI
Citizen
Posts: 89
Joined: Mon Aug 12, 2013 4:22 am
Location: Philippines,Asia

How to change gamestates pressing R and particle cleanup

Post by IAsep-TrixI »

SORRY IN ADVANCED FOR NOT USING .LOVE, FOR SOME REASON IT DOESN'T WORK USING .LOVE
ALSO SORRY FOR HAVING SUCH MESSY CODE.

I've been trying to make a space invader like game for practice, but for some reason, when I enter the gameover gamestate, I cant change back to the playing gamestate when i press R.
My gamestate system is just a string, so if you die for example your gamestate turns into "gameover" or if you're playing the gamestate is by default "playing". Now the thing is I've added a code where if you're in the game over state, you will go back to the playing gamestate via pressing R. This for some reason doesnt work.
Code goes like this

Code: Select all

  elseif gamestate == "gameover" then
           if love.keyboard.isDown("r") then
		gamestate = "playing"
	   end
It doesn't give out an error or anything, it just doesn't work.

Also my second problem is the fact that my particles dont disappear even after adding in a system that removes the particle table when it reaches a certain tick point.

Code: Select all

function particle_systems:cleanup()
	        if particlelimit <= 0 then
                   table.remove(particle_systems.list)
				   particlelimit = 220
			end
end
I've added this function to whenever an enemy dies, so this means that every enemy are sharing the same limit, meaning if I kill one enemy the particle limit will start counting down to 0 and when it does it will remove the particles AND restart the particle limit, but then this means that everytime I kill an enemy every particle will stay because they all share one time limit. Is there anyway to fix this?
Attachments
SpaceInvadersLike.zip
(3.82 MiB) Downloaded 164 times
An agent of the free

check out the game I'm doing with Jkash!
Muzz
Citizen
Posts: 54
Joined: Sun Jun 28, 2015 1:24 pm

Re: How to change gamestates pressing R and particle cleanup

Post by Muzz »

You aren't removing the conditions that put it into game over, as in, you just paused the game and so when you press "r" it tries to reset, but then instantly goes back to being gameover.



Btw this is a cleaner way to spawn your grid of enemies.

Code: Select all

	
 for i=1,7 do
	 for v=1,8 do
	 	enemies_controller:spawnEnemy(i * 100,200-(100*v))
	 end
end
As a general rule try and keep your indents clean, it's hard to read your code. In sublime text you can autoindent, which does an ok job.
I actually have no idea what you are trying to achieve with the particle system stuff as the way you have done it is really convoluted.

With the way you are trying to code i'd recommend you to pickup using a class library, i like Middleclass especially when combined with stateful, It should help keep things cleaner and easier to read and code.
https://github.com/kikito/middleclass
https://github.com/kikito/stateful.lua
Post Reply

Who is online

Users browsing this forum: Google [Bot], PotatoDude and 205 guests