One Way To Go

Show off your games, demos and other (playable) creations.
User avatar
Ruirize
Prole
Posts: 20
Joined: Tue Dec 13, 2011 9:02 pm
Location: England
Contact:

Re: One Way To Go

Post by Ruirize »

Please tell me that you have used the good ol '*dt' in there. It goes way too fast even on easy.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post 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.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post 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.
Last edited by gordebak on Tue Jan 03, 2012 4:42 pm, edited 4 times in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: One Way To Go

Post by Robin »

dt changes all the time, and that's the way it's supposed to be. Or is that not what you meant?
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: One Way To Go

Post 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.
When I write def I mean function.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post by gordebak »

So I won't use dt then. I want the velocity to be constant.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: One Way To Go

Post 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. ;)
Help us help you: attach a .love.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post 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. :)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: One Way To Go

Post by kikito »

The problem might be that you are calculating velx and vely correctly ... but you never use them.

Code: Select all

x = x + dv
y = y +  dv
I take this should be

Code: Select all

x = x + velx
y = y +  vely
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.
When I write def I mean function.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post by gordebak »

Actually I use velx and vely. I just wrote it here incorrectly.

Edit: Corrected the code.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests