TGC Codebase Backup



javelin trajectory by Phaelax

21st May 2007 14:30
Summary

display a line following its path of trajectory



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem gravity
g# = -1.0
rem velocity
v = 20
rem starting coordinates of trajectory
x = 120
y = 240
rem angle of elevation (50 degrees above X-axis)
angle# = 310

sync on
sync rate 60


do
   cls


   rem reset time
   if spacekey() = 1
      t# = 0
      oldx# = x
      oldy# = y
   endif
   rem change angle of elevation
   if upkey() then dec angle#
   if downkey() then inc angle#

   rem increment time step
   t# = t#+0.2

   rem get new position
   rem x1,y1 is the back-end of our javelin
   x1# = x+v*cos(angle#)*t#
   y1# = y+(v*sin(angle#)*t# - 0.5*g#*t#^2)


   rem find angle between current and previous position
   a# = atanfull(x1#-oldx#, y1#-oldy#)

   rem update previous position
   oldx# = x1#
   oldy# = y1#

   rem this just shows what angle we fired at
   ax = x+cos(angle#)*30
   ay = y+sin(angle#)*30
   ink rgb(255,255,255),0
   line x,y,ax,ay


   rem x2,y2 is front-end of our javelin
   x2 = x1#+sin(a#)*20
   y2 = y1#+cos(a#)*20
   ink rgb(255,0,0),0
   line x1#,y1#,x2,y2


   set cursor 1,1
   print "Elevation: ",angle#

   sync
loop