One Way To Go

Show off your games, demos and other (playable) creations.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: One Way To Go

Post by MarekkPie »

kikito wrote:Kindof similar to brushing up your teeth between eating smelly cheese and going to the dentist.
I always give the dentist my raw, unadulterated stagnant fumes.
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 »

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

Edit: Corrected the code.
I think the problem is somewhere else then. Why don't you just upload the whole .love file?
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: One Way To Go

Post by bartbes »

Anyway, robin explained it well, you define your speed as pixels per second, then multiply it by dt (every frame) to get the distance traveled between the frames.
So:

Code: Select all

--somewhere, when the speed is set
velx = 200 -- pixels per second

--and the starting x position of your object
x = 15

--in update
x = x + velx*dt -- it moves 200 pixels per second, so after 1 second it will be at 215
EDIT: Of course there is the risk that I've misunderstood and you're past this stage.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post by gordebak »

Here it is.

Edit: Sorry, the code is a bit ugly.
Attachments
one way to go - dt.love
(1.85 MiB) Downloaded 331 times
Last edited by gordebak on Tue Jan 03, 2012 5:15 pm, edited 1 time in total.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post by gordebak »

bartbes wrote:Anyway, robin explained it well, you define your speed as pixels per second, then multiply it by dt (every frame) to get the distance traveled between the frames.
So:

Code: Select all

--somewhere, when the speed is set
velx = 200 -- pixels per second

--and the starting x position of your object
x = 15

--in update
x = x + velx*dt -- it moves 200 pixels per second, so after 1 second it will be at 215
EDIT: Of course there is the risk that I've misunderstood and you're past this stage.
That's what I do in the code. It works fine, but velocity changes from time to time. Especially after changing direction.
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 »

I haven't checked the code, but I think it's not dt.

Your speed is faster when you hold the arrow keys than when you release them. That explains how it changes after changing direction.
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 »

I checked the game on another computer, and it works fine. It seems that it's a hardware problem on my side.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: One Way To Go

Post by MarekkPie »

The relative velocity (the velocity at each call) will change. But when you sum the displacement between your position at t = 0 and your displacement at t = 1, it will equal your velocity in pixels/second.

If you simply go, x = x + velx, then your velocity is in pixels/dt, which is 1/dt times faster than the above.

I think this is where you are getting the perception of a speed increase/decrease. If you just print(velx * dt) then it will look like a speed change. Just remember that isn't really the case.

I hope I have that math right. My brain hurts today.
gordebak
Prole
Posts: 37
Joined: Tue Dec 27, 2011 6:38 am

Re: One Way To Go

Post by gordebak »

MarekkPie wrote:The relative velocity (the velocity at each call) will change. But when you sum the displacement between your position at t = 0 and your displacement at t = 1, it will equal your velocity in pixels/second.

If you simply go, x = x + velx, then your velocity is in pixels/dt, which is 1/dt times faster than the above.

I think this is where you are getting the perception of a speed increase/decrease. If you just print(velx * dt) then it will look like a speed change. Just remember that isn't really the case.

I hope I have that math right. My brain hurts today.
But velx = difficulty * dt in this case. To be exact, x = x + (difficulty * dt). So it must be the same as what you said, right?
spirulence
Prole
Posts: 8
Joined: Tue Sep 21, 2010 8:27 pm

Re: One Way To Go

Post by spirulence »

This is quite a lot of fun! Kudos. :)

My only niggle is that the music can get repetitive.
Post Reply

Who is online

Users browsing this forum: No registered users and 64 guests