How to slow down number generator, create victory screen ?

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
ShandiX
Prole
Posts: 2
Joined: Sat May 25, 2013 1:42 pm

How to slow down number generator, create victory screen ?

Post by ShandiX »

This is my first time making game. I decided to make grid like game and encountered several issues i hope someone can help me with:
1. My random number generator generates numbers to fast, making computer cube move like a missile. I guess its due to being in update function and updates happening very rapidly, is there any way to slow it down, that computer cube is moving slower ?
2. How to create victory/ defeat screen ? What i want is, after collision with computer or collision with eXit cube for victory/ defeat screen to appear, i tried it in DefeatScreen() function but nothing happens, is there any way to do it and make it stay while appropriate action is made ? In this case space to retry, escape to exit.
3. Is there any way to make explosion like sprites appear when collision happen and stay for a sec or two before defeat screen rolls in ?

Any advice on game or help about issues would be appreciated!
I have added my code in love zip file.
Attachments
cubegame.zip
(1.14 KiB) Downloaded 59 times
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: How to slow down number generator, create victory screen

Post by veethree »

1. You can use a simple timer for that.

In love.load():

Code: Select all

tick = 0
interval = 1
in love.update()

Code: Select all

tick = tick + dt
if tick > interval then
	--Random number code goes here
	tick = 0
end
Of course you can name the variables whatever you want. But this will run whatever code you put after the if statement roughly every second.

2. You can do that with gamestates. Basically you would have a variable called "gamestate" or something like that and based on the variables value you would draw/update different things.

Code: Select all

if gamestate == "game" then
	--Game code
elseif gamestate == "gameover" then
	--Game over code
end
You could do that in love.draw() and love.update() (if you need to update anything in the gameover state that is), And love.keypressed() for the retry and exit keys. When the state is "game" and collision with the computer occurs you would set the gamestate to "gameover", and when the retry key is pressed you would set it back to "game", Also you would have to reset any variables such as score etc.

3. That can be done with a timer like i mentioned above.
ShandiX
Prole
Posts: 2
Joined: Sat May 25, 2013 1:42 pm

Re: How to slow down number generator, create victory screen

Post by ShandiX »

Thank you veethree, your advice helped me fix all problems. Solutions were so simple, i cant believe i didnt think of them....
Anyway thanks.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 11 guests