// Project: A-A Waypoint Test // Created: 2019-01-25 . Converted into AGK // Original BY DARKGuy in DBP converted from DB code // Original code (idea ?) from Binary moon tutorials DB code // show all errors SetErrorMode(2) // set window properties SetWindowTitle( "A-A Waypoint Test" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts GridObjectID=CreateObjectPlane(1024,768) // Create a plane and texture it SetObjectColor( GridObjectID,125,125,125,255) SetObjectPosition(GridObjectID,0,-1.5,0) SetObjectRotation(GridObjectID,90,90,0) //90,90,0 SetObjectTransparency(GridObjectID,1) // WPX stands for WayPoint X dim wpx[5] // WPZ stands for WayPoint Z dim wpz[5] // THIS IS ONLY FOR THIS EXAMPLE, AND WHAT IT DOES IS TO GENERATE RANDOM X AND Z COORDS for a=1 to 4 //88 wpx[a]=Random(-50,89) wpz[a]=Random(-50,89) next a /////////////////// End of temp arrray ///////////////////////// BLUE =1 // RED =2 GREEN=3 SetCameraRotation( 1, 90, 0 , 0 ) SetCameraPosition (1,1,225,-10) // The "Player" Object CreateObjectBox(BLUE,5,5,5) SetObjectColor( BLUE,0,0,255,255) // BLUE SetObjectVisible(BLUE,1) // make it invisible SetObjectCollisionMode(BLUE,1) // This is another Dummy for knowing where is the next waypoint CreateObjectBox(GREEN,5,5,5) SetObjectColor( GREEN,0,255,0,255) // GREEN SetObjectVisible(GREEN,1) // RotateObjectLocalx(BLUE,90) // Not needed when using SetObjectLookAt // fixobjectpivot( BLUE) // Not needed do // We get the player position here... x#=getobjectx(1) //BLUE z#=getobjectz(1) // BLUE //...and get the distance beetween the player's X,Z and the waypoint X,Z dx# = Abs(wpx[a] - x#) dz# = Abs(wpz[a] - z#) // (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 dz#<=4) or (wpx[a]=0 and wpz[a]=0) // So, for saying it simple, if the player is close to the waypoint, we increment // the waypoint variable a ( a new location to go! ). // waypoint=waypoint+1 a=a+1 // If the waypoint variable is greater than the maximum, reset it to 0 (first waypoint) If a>4 then a=0 // if waypoint (a)>88 then waypoint(a) =0 else // We move our object in the X & Z direction .5 unit forward MoveObjectLocalX(BLUE,.5) : MoveObjectLocalZ(BLUE,.5) // .5 is the SPEED // We get again the Player's position AFTER moving it x#=getobjectx(1) z#=getobjectz(1) SetObjectPosition(BLUE,x#,1,z#) // BLUE(1) box SetObjectLookAt(BLUE,GetObjectX(3),GetObjectY(3),GetObjectZ(3),90) // GetObjectZ(3),90) (90) BLUE object hits GREEN box endif // This is just for putting the dummy waypoint object where it must be :) SetObjectPosition(GREEN,wpx[a],1,wpz[a]) // GREEN print("") print("") print( " FPS "+str (screenfps())) print("") print( " Going to WayPoint "+str(a)) sync() loop