Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Acceleration
Author Message
mynameisbob

Posted: 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.

Paul

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

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

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

right, some kinda terminal velocity.
mynameisbob

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

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

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

Posted: 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
Tony's programming blog. DWITE - a programming contest.
Cervantes

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: