Page 1 of 1

pong quest

Posted: Fri Mar 01, 2013 1:44 am
by musky44
This pong game can be confusing and their are a few glitches but it is very addicting. You start at level 1 where the ball goes very slow but each time the ball is hit it speeds up a little. you have 5 lives, each enemy has 3 lives and win, if you beat them you go to the next level. The stats are shown outside of the game play zone. Each level you speed up and the enemy speeds up, although if you get a good hit on a enemy, they might not be able to get the serve and you would get a free passage to the next level. Once you get to level 10 words are shown, by level 13 you have unlocked the secret rank of... There is also difficulty setting that makes the ball speed up faster or slower. and there is sound. also there is a delta time but is still being tested, and it is not automatic and needs to be changed.

I am also planning on adding upgrades. the second version had been taken out.

controls
left/right arrows: move
w/s: change difficulty
e/d: change delta time
q: quit

Re: pong quest

Posted: Mon Mar 04, 2013 7:27 pm
by Germanunkol
There's something wrong with your code.
I tried version 4 and, as you descirbe, the deltatime does not work correctly yet.
This means that it's unplayable on my computer, because the computer is too fast, I believe.

For one thing, you need to actually set the deltatime. Try doing it in love.update:

Code: Select all

function love.update(timePassed)
	dt = timePassed
end
Then, in the functions handling left and right movement, you should multiply the added x value by dt, not divide it.
The idea behind this is:
timePassed is a value that shows the time between two frames that are being rendered. It can change, that's why you need to update dt in love.update.
Also, timePassed is very different on each PC, depending on the speed of the PC. If a PC is fast, timePassed is very low, because the time it takes the PC to render a frame is very low (and so the time between two frames is also low).
That means if you do something like:
x = x + speed*dt
then this is mostly system-independent, and that's what you want. Speed is a constant (let's say it's 5) and dt is low on fast computers.
So every frame, this function line gets executed. Because frames render faster, this line is executed more often than on a slow PC, but since dt is also lower, in the end, you get a similar result on both PCs, meaning your paddle (or the ball, or whatever) moves with the same speed on both PCs.

Edit: On a side note, indent your code! It's very hard to read otherwise. There's lots of good editors out there that actually do this for you.

It's be great if you could update the game, I'd love to try the higher levels but can't reach them right now ^^.

Re: pong quest

Posted: Mon Mar 04, 2013 7:30 pm
by musky44
thanks, i figured that out in my second game, fast flight.

Re: pong quest

Posted: Mon Mar 04, 2013 10:45 pm
by veethree
Germanunkol wrote:There's something wrong with your code.
I tried version 4 and, as you descirbe, the deltatime does not work correctly yet.
This means that it's unplayable on my computer, because the computer is too fast, I believe.

For one thing, you need to actually set the deltatime. Try doing it in love.update:

Code: Select all

function love.update(timePassed)
	dt = timePassed
end
Then, in the functions handling left and right movement, you should multiply the added x value by dt, not divide it.
The idea behind this is:
timePassed is a value that shows the time between two frames that are being rendered. It can change, that's why you need to update dt in love.update.
Also, timePassed is very different on each PC, depending on the speed of the PC. If a PC is fast, timePassed is very low, because the time it takes the PC to render a frame is very low (and so the time between two frames is also low).
That means if you do something like:
x = x + speed*dt
then this is mostly system-independent, and that's what you want. Speed is a constant (let's say it's 5) and dt is low on fast computers.
So every frame, this function line gets executed. Because frames render faster, this line is executed more often than on a slow PC, but since dt is also lower, in the end, you get a similar result on both PCs, meaning your paddle (or the ball, or whatever) moves with the same speed on both PCs.

Edit: On a side note, indent your code! It's very hard to read otherwise. There's lots of good editors out there that actually do this for you.

It's be great if you could update the game, I'd love to try the higher levels but can't reach them right now ^^.
I'm pretty sure you don't need the "timePassed" variable, You can just put "dt" as love.update's argument.

Re: pong quest

Posted: Tue Mar 05, 2013 8:19 am
by Robin
veethree wrote:I'm pretty sure you don't need the "timePassed" variable, You can just put "dt" as love.update's argument.
A rose by any other name...

Re: pong quest

Posted: Tue Mar 05, 2013 1:08 pm
by substitute541
Robin wrote:
veethree wrote:I'm pretty sure you don't need the "timePassed" variable, You can just put "dt" as love.update's argument.
A rose by any other name...
... just as sweet.
When everything's worse, our work is complete!
Jessie!
James!
Meowth thats the name!

... Actually, I'm laughing too hard to continue on (it's a version of the team rocket motto in pokemon).

Re: pong quest

Posted: Tue Mar 05, 2013 1:59 pm
by Germanunkol
Robin wrote:
veethree wrote:I'm pretty sure you don't need the "timePassed" variable, You can just put "dt" as love.update's argument.
A rose by any other name...
Wait, what? Why?
He wants dt to be global, right? He's using the dt value everywhere else.
But aren't received arguments automatically local? So to make it global, I need to assign the local value to a global variable.
?

Re: pong quest

Posted: Tue Mar 05, 2013 2:56 pm
by Robin
Germanunkol wrote:Wait, what? Why?
He wants dt to be global, right? He's using the dt value everywhere else.
But aren't received arguments automatically local? So to make it global, I need to assign the local value to a global variable.
?
You are right. I don't know about veethree, but I read right past that because making dt global is really ugly and bad design and you shouldn't do that ever. Instead, pass dt as an argument to whatever function needs it.

Re: pong quest

Posted: Tue Mar 05, 2013 3:51 pm
by Germanunkol
Good, just making sure I didn't miss something.

I agree with you, of course. Just didn't want to make it more complicated than it already was.

I'm not very fond of the way Lua makes everything global by default...