Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Very basic code for Way Points

Author
Message
Lance
21
Years of Service
User Offline
Joined: 22nd Jul 2003
Location: Third planet from Sun
Posted: 1st Feb 2019 15:25 Edited at: 6th Feb 2019 16:27

Found the code while doing research and converted it to AppGameKit . It works in the project I am working on ( I only do coding during winter months ) . I added it as a text file . Don't know how to add the code button




// 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]=Random2(-50,89)
wpz[a]=Random2(-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


Attachments

Login to view attachments
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 1st Feb 2019 16:06
Nice!! This is on my to-do list.
Lance
21
Years of Service
User Offline
Joined: 22nd Jul 2003
Location: Third planet from Sun
Posted: 2nd Feb 2019 20:29 Edited at: 2nd Feb 2019 20:29

YouTube video of code running . I added a save and load function . This is how I learn to do stuff . I looked at other examples and decided to try my hand at converting a very simple DBP program I had found a few years ago .


https://youtu.be/7pztUt7pYYo
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Feb 2019 21:34
Quote: " Don't know how to add the code "

if you click the code button at the top firstly before your code and then again after your code it will place the code in proper comment blocks

fubar
Rick Nasher
7
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 3rd Feb 2019 08:24 Edited at: 3rd Feb 2019 08:26
Always nice. Thanks for sharing.
Just mark the begin and end of the code from the Code dropdownbox.


VeryBasicWaypointExample.agc
Rick Nasher
7
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 3rd Feb 2019 08:30
Ah fubarpk beat me to it. lol
Also works for other stuff like images, videos and such.
Lance
21
Years of Service
User Offline
Joined: 22nd Jul 2003
Location: Third planet from Sun
Posted: 3rd Feb 2019 12:05
Thanks for the tip . Never really knew how it worked .

Login to post a reply

Server time is: 2024-11-05 18:37:53
Your offset time is: 2024-11-05 18:37:53