Skip to main content
guest
Join
|
Help
|
Sign In
Liberty BASIC Programmer's Encyc
Home
guest
|
Join
|
Help
|
Sign In
Wiki Home
Recent Changes
Pages and Files
Members
Home
General Tutorials
Advanced Tutorials
GUI Programming
Graphics and Games
Strings and Text
Numbers and Math
Using Files
Windows API
Communications
Programmer's Tools
Articles by Date
FAQs
Rosetta Code
General Articles
Newsletters Contents
Table of Contents
Demos
Submit Articles
TOS and License
GamePhysics2
Edit
8
…
1
Tags
graphics and games
edit
Save
Cancel
Notify
RSS
Backlinks
Source
Print
Export (PDF)
<h1>2D Game Physics - Part II - Acceleration</h1> <em>[[user:benjamin805]]</em><br /> <img id="wikitext@@toc@@normal" class="WikiMedia WikiMediaToc" title="Table of Contents" src="/site/embedthumbnail/toc/normal?w=225&h=100"/><br /> <br /> <h1>Acceleration</h1> In some games accelerating objects is needed to show a speed increase. In this example we see how adding a constant<br /> acceleration value to the speed of a missile increases the distance traveled each time the graphic screen is updated.<br /> <br /> <br /> <pre class="lb">'Window Setup<br/>nomainwin<br/>WindowWidth=400<br/>WindowHeight=400<br/>open "Missle Launch" for graphics_nsb as #main<br/>#main,"trapclose [exit]"<br/><br/>'launch angle (0-360)<br/>angle=90<br/>'convert angle to radians<br/>AngleInRadians=angle/57.29577951<br/><br/>'set missile starting values<br/>movingObject.speed=2<br/>movingObject.acceleration=1 'constant acceleration<br/><br/>'starting position<br/>movingObject.x=200<br/>movingObject.y=370<br/><br/>'set direction of movement by getting<br/>'the cos and sin of the angle in radians<br/>scale.x=cos(AngleInRadians)<br/>scale.y=sin(AngleInRadians)<br/><br/>#main,"down;color red;size 5"<br/><br/>timer 100,[loop]<br/><br/>wait<br/><br/>[loop]<br/>'add our constant acceleration to the speed<br/>movingObject.speed=movingObject.speed+movingObject.acceleration<br/><br/>#main,"up;goto 0 12;down;\Speed: ";movingObject.speed<br/>'increase the object velocity by multiplying our new speed by our<br/>'scale value<br/>movingObject.velocity.x=(movingObject.speed*scale.x)<br/>movingObject.velocity.y=(movingObject.speed*scale.y)<br/>'add our new velocity value to our current movingObject x and<br/>'y values<br/>movingObject.x=movingObject.x+movingObject.velocity.x<br/>movingObject.y=movingObject.y-movingObject.velocity.y<br/><br/>#main,"set ";movingObject.x;" ";movingObject.y<br/><br/>if movingObject.y<0 then<br/> timer 0<br/> wait<br/> end if<br/>wait<br/><br/>[exit]<br/>close #main<br/>end<br/></pre>
Javascript Required
You need to enable Javascript in your browser to edit pages.
help on how to format text
Turn off "Getting Started"
Home
...
Loading...