
-----------------------------------
mynameisbob
Wed Jun 16, 2004 5:58 pm

Acceleration
-----------------------------------
Im making a star wars game and I need help making the ship accelerate and decelerate. For example if I hold the forwards button the ship should slowly start up then go faster then if i let go of the forwards key the ship should still be moving and eventually slow down.

-----------------------------------
Paul
Wed Jun 16, 2004 6:07 pm


-----------------------------------
have a increase speed to add on to ur ship value, then have another acceleration variable value, and keep adding that to your increase speed. the same goes for the decreasing speed.

-----------------------------------
Delos
Wed Jun 16, 2004 6:21 pm


-----------------------------------
Don't forget to limit how fast/slow it can go!

You may want to look at pixels moved per draw of whatever character you're considering.  It's an easy way to emulate speed changes...or velocity changes if you want to get into components...

-----------------------------------
Paul
Wed Jun 16, 2004 6:29 pm


-----------------------------------
right, some kinda terminal velocity.

-----------------------------------
mynameisbob
Wed Jun 16, 2004 9:23 pm


-----------------------------------
ok this is what i got so far...

var speed : int := 0

    if keys (KEY_RIGHT_ARROW) then
        speed += 1
        X += speed
    end if

 Pic.Draw (wing, X, Y, picMerge)

but the picture moves so fast. How do i use real numbers when drawing pictures. 
Is this how to do it or do i have to use acceleration and velocity formulas?

-----------------------------------
SuperGenius
Wed Jun 16, 2004 9:27 pm


-----------------------------------
You cannot use real numbers when drawing pictures, and if you could it would not matter because human's eyesight is not good to differentiate between different fractions of a pixel. That said, to make the acceleration slower you need to make your program evaluate that if statement a smaller number of times per second.

-----------------------------------
mynameisbob
Wed Jun 16, 2004 9:38 pm


-----------------------------------
so do i do something like, if arrow key is held for 3 seconds then speed+=1?

-----------------------------------
Tony
Wed Jun 16, 2004 11:31 pm


-----------------------------------
no, use real numbers for all the calculations, but round for drawing pictures only. I mean you can't expect for numbers to work out to be integers if you move at angles and what not...

so x += 0.3

and you draw Pic.Draw(round(x), round(y)...)

the movement will average out to be just right :wink:

-----------------------------------
Cervantes
Thu Jun 17, 2004 6:41 am


-----------------------------------
you're almost there.  as for decay, have a constant that is close to one, but just under one. something like 0.99.   then every time through the loop do vX *= decay.


setscreen ("offscreenonly")
const decay := .99

var X := 5.0
var vX := 0.0
var keys : array char of boolean
loop
    cls
    Input.KeyDown (keys)
    if keys (KEY_RIGHT_ARROW) then
        vX += 0.1
    end if
    if keys (KEY_LEFT_ARROW) then
        vX -= 0.1
    end if
    vX *= decay
    X += vX

    drawfilloval (round (X), 100, 10, 10, red)
    View.Update
    delay (10)
end loop

