Waypoints example by DARKGuy23rd Apr 2004 9:10
|
---|
Summary Here is is a small example for helping you in the waypoints thing. Waypoints are needed in FPS games (some) and in Race Games and perhaps in RTS games, so this example might help y Description Here is is a small example for helping you in the waypoints thing. Waypoints are needed in FPS games (some) and in Race Games and perhaps in RTS games, so this example might help you :). Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `======================================================================================= ` `WAYPOINTS EXAMPLE `BY DARKGuy ` `Developing time: 10 min. ` `This is a simple example to do some waypoints handling, somewhat like the Limit Rush `tutorial, but with my own code. ` `As you must know, if you're gonna use anything of my snippets, please put my name in `your credits (DARKGuy) :). ` `======================================================================================= `Here we create a random seed for random numbers randomize timer() `here we set the framerate control options (frame rate controlling on and a fixed speed `of 30 FPS, you can change it if you want) and we hide the mouse. sync on sync rate 30 hide mouse `WPX stands for WayPoint X dim wpx(90) `WPZ stands for WayPoint Z dim wpz(90) `THIS IS ONLY FOR THIS EXAMPLE, AND WHAT IT DOES IS TO GENERATE RANDOM X AND Z COORDS for a=0 to 90 wpx(a)=(0-50)+rnd(100) wpz(a)=(0-50)+rnd(100) next a `We don't want the Auto Camera On autocam off `Here we setup the camera position camera 0,100,0 point camera 0,0,0 `The "Player" Object make object cube 1,5 ghost object on 1 `The Dummy object, will be used for getting the Y angle for the next waypoint make object cone 2,2.5 `This is another Dummy for knowing where is the next waypoint make object cone 3,5 `Here we color our object. Blue is Player, Red is Y Angle of next waypoint and Green is `where the next waypoint is. color object 1,rgb(0,0,255) color object 2,rgb(255,0,0) color object 3,rgb(0,255,0) `Here we correct the Red cone for pointing in the right direction. pitch object down 2,90 fix object pivot 2 do `We color the background black color backdrop 0 `just for putting the info where it must be set cursor 0,0 `We print your FPS here print screen fps()," FPS" `We get the player position here... x#=object position x(1) z#=object position z(1) `...and get the distance beetween the player's X,Z and the waypoint X,Z dx# = Abs(wpx(waypoint) - x#) dz# = Abs(wpz(waypoint) - z#) `Alright...explaining: ` `(dx#<=4 and dy#<=4) = if the object's distance is less than 4 units in both X and Z `coordinates... `OR `(wpx(waypoint)=0 and wpz(waypoint)=0) = if the next waypoint is blank... if (dx#<=4 and dy#<=4) or (wpx(waypoint)=0 and wpz(waypoint)=0) `So, for saying it simple, if the player is close to the waypoint, we increment `the waypoint variable (oh!, a new location to go! :P ). waypoint=waypoint+1 `If the waypoint variable is greater than the maximum, reset it to 0 (first `waypoint) if waypoint>90 then waypoint=0 else `If the player hasn't arrivd to the next waypoint... `The current waypoint print "Waypoint ",waypoint `The next waypoint X print "Waypoint x = ",wpx(waypoint) `The next waypoint Z print "Waypoint z = ",wpz(waypoint) `We move our object in his Y direction 1 unit forward move object 1,1 `We get again the Player's position AFTER moving it x#=object position x(1) z#=object position z(1) `Here we position and point the dummy object. 10 is for the Y and it's in the two `instructions because the dummy object is 10 units above the player position object 2,x#,10,z# point object 2,wpx(waypoint),10,wpz(waypoint) `Here we get the Y angle for the next waypoint X,Z coordinates and smooth it ya#=curveangle(object angle y(2),object angle y(1),10) `We rotate our player object in direction to the smoothed Y angle yrotate object 1,ya# endif `This is just for putting the dummy waypoint object where it must be :) position object 3,wpx(waypoint),0,wpz(waypoint) sync loop |