Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Acceleration
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mynameisbob




PostPosted: Wed Jun 16, 2004 5:58 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Wed Jun 16, 2004 6:07 pm   Post subject: (No subject)

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




PostPosted: Wed Jun 16, 2004 6:21 pm   Post subject: (No subject)

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




PostPosted: Wed Jun 16, 2004 6:29 pm   Post subject: (No subject)

right, some kinda terminal velocity.
mynameisbob




PostPosted: Wed Jun 16, 2004 9:23 pm   Post subject: (No subject)

ok this is what i got so far...

code:
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




PostPosted: Wed Jun 16, 2004 9:27 pm   Post subject: (No subject)

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




PostPosted: Wed Jun 16, 2004 9:38 pm   Post subject: (No subject)

so do i do something like, if arrow key is held for 3 seconds then speed+=1?
Tony




PostPosted: Wed Jun 16, 2004 11:31 pm   Post subject: (No subject)

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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cervantes




PostPosted: Thu Jun 17, 2004 6:41 am   Post subject: (No subject)

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.

code:

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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: