Page 2 of 4
Re: One Way To Go
Posted: Mon Jan 02, 2012 9:57 pm
by Ruirize
Please tell me that you have used the good ol '*dt' in there. It goes way too fast even on easy.
Re: One Way To Go
Posted: Tue Jan 03, 2012 1:53 pm
by gordebak
Ruirize wrote:Please tell me that you have used the good ol '*dt' in there. It goes way too fast even on easy.
I didn't use dt. I will fix that, sorry.
Re: One Way To Go
Posted: Tue Jan 03, 2012 2:58 pm
by gordebak
It's strange. If I use dt in velocity, I can't make it constant. It changes from time to time. Wth?
Here's the code:
Code: Select all
dv = difficulty * dt
if love.keyboard.isDown("left") then
velx = -dv
vely = 0
end
if love.keyboard.isDown("right") then
velx = dv
vely = 0
end
if love.keyboard.isDown("up") then
vely = -dv
velx = 0
end
if love.keyboard.isDown("down") then
vely = dv
velx = 0
end
x = x + velx
y = y + vely
It should be constant, but it isn't.
Re: One Way To Go
Posted: Tue Jan 03, 2012 3:02 pm
by Robin
dt changes all the time, and that's the way it's supposed to be. Or is that not what you meant?
Re: One Way To Go
Posted: Tue Jan 03, 2012 3:02 pm
by kikito
dt is not meant to be constant. It's smaller in faster machines, and bigger in slower machines. Your code must take that into account.
Re: One Way To Go
Posted: Tue Jan 03, 2012 3:04 pm
by gordebak
So I won't use dt then. I want the velocity to be constant.
Re: One Way To Go
Posted: Tue Jan 03, 2012 3:08 pm
by Robin
gordebak wrote:So I won't use dt then. I want the velocity to be constant.
That's why you should use dt.
The faster the machine, the smaller dt. If you multiply the velocity with dt, it remains constant.
If you have 10 FPS, dt will be 0.1, if you have 100 FPS, dt will be 0.01. If you multiply the speed in seconds by dt, you get the speed in frames.
pixels/second * seconds/frame = pixels/frame.
EDIT: also, it would be nice if after X levels, you get an extra life.
Re: One Way To Go
Posted: Tue Jan 03, 2012 3:11 pm
by gordebak
But it doesn't stay constant on my machine. Sometimes it goes faster if I use dt. Isn't it a bit strange?
Edit: Sorry if I sound like a moron. Look at the code please, what am I doing wrong?
And you get an extra life on level 10.
Re: One Way To Go
Posted: Tue Jan 03, 2012 4:39 pm
by kikito
The problem might be that you are calculating velx and vely correctly ... but you never use them.
I take this should be
Or something along those lines.
PS: Please,
indent your code. It will help you program much easily. In addition, it's a common courtesy if you are going to ask others to review your code. Kindof similar to brushing up your teeth between eating smelly cheese and going to the dentist.
Re: One Way To Go
Posted: Tue Jan 03, 2012 4:41 pm
by gordebak
Actually I use velx and vely. I just wrote it here incorrectly.
Edit: Corrected the code.