Hello, I'm trying to make it so that my player can run away from the AI's, my player never moves, everything else does.
In the code, I move the positions of the sprite when pressing the arrow keys. (It works when Dark AI is commented) How can I make it so that I can run away with Dark AI?
Here's an example:
Rem Project: Test A.I
Rem Created: Friday, November 03, 2011
Rem ***** Main Source File *****
// UDTs
Type Graphics
id as Integer
img as Integer
xpos as Integer
ypos as Integer
angle as float
width as Integer
height as Integer
EndType
// Globals
Global Player as Graphics
Global Background as Graphics
Global TotalEnemies = 0
Global EnemiesIDrange = 500
// Arrays
Dim Enemies(TotalEnemies) as Graphics
Sync On : Sync Rate 60 : Backdrop off : Autocam off
AI Start
AI Set Radius 10
// Setup Background
Background.id = 1
Background.img = 1
Background.xpos = 0
Background.ypos = 0
Load Image "background.png", Background.img
Sprite Background.id, Background.xpos, Background.ypos, Background.img
// Setup Player
Player.id = 999
Player.img = 999
Player.xpos = Screen Width() / 2
Player.ypos = Screen Height() / 2
Load Image "player.png", Player.img
Sprite Player.id, Player.xpos, Player.ypos, Player.img
Player.width = Sprite Width(Player.id) / 2
Player.height = Sprite Height(Player.id) / 2
Offset Sprite Player.id, Player.width, Player.height
// Setup Enemies
For x = 0 to TotalEnemies
Enemies(x).id = EnemiesIDrange
Enemies(x).img = EnemiesIDrange
Enemies(x).xpos = RND(400)
Enemies(x).ypos = RND(300)
Load Image "enemy.png", Enemies(x).img
Sprite Enemies(x).id, Enemies(x).xpos, Enemies(x).ypos, Enemies(x).img
Enemies(x).width = Sprite Width(Enemies(x).id) / 2
Enemies(x).height = Sprite Height(Enemies(x).id) / 2
Offset Sprite Enemies(x).id, Enemies(x).width, Enemies(x).height
AI Add Enemy Enemies(x).id, 0
AI Set Entity Speed Enemies(x).id, 70
AI Set Entity Position Enemies(x).id, Enemies(x).xpos, Enemies(x).ypos
AI Set Entity Idle Position Enemies(x).id, Enemies(x).xpos, Enemies(x).ypos
// Increase range so all IDs in array are unique
Inc EnemiesIDRange, 1
Next x
// place obstacles for AI to go around
WorldObstacles()
Do
For x = 0 to TotalEnemies
AI Entity Go To Position Enemies(x).id, player.xpos, player.ypos
Next x
AI Debug Show Waypoints 0,2.5
AI Debug Show Obstacle Bounds 0,2.5
AI Update
UpdateWorld()
RenderWorld()
Sync
Loop
Function RenderWorld()
// Resprite GFX
Sprite Background.id, Background.xpos, Background.ypos, Background.img
Sprite Player.id, Player.xpos, Player.ypos, Player.img
For x = 0 to TotalEnemies
Enemies(x).xpos = int(AI Get Entity X(Enemies(x).id))
Enemies(x).ypos = int(AI Get Entity Z(Enemies(x).id))
Enemies(x).angle = AI Get Entity Angle Y(Enemies(x).id)
Sprite Enemies(x).id, Enemies(x).xpos, Enemies(x).ypos, Enemies(x).img
Next x
EndFunction
Function UpdateWorld()
// player never moves, everything else does
If Upkey() = 1
background.ypos = background.ypos + 1
For x = 0 to TotalEnemies
Enemies(x).ypos = Enemies(x).ypos + 1
Next x
Endif
If Downkey() = 1
background.ypos = background.ypos - 1
For x = 0 to TotalEnemies
Enemies(x).ypos = Enemies(x).ypos - 1
Next x
EndIf
If Rightkey() = 1
background.xpos = background.xpos - 1
For x = 0 to TotalEnemies
Enemies(x).xpos = Enemies(x).xpos - 1
Next x
EndIf
If Leftkey() = 1
background.xpos = background.xpos + 1
For x = 0 to TotalEnemies
Enemies(x).xpos = Enemies(x).xpos + 1
Next x
EndIf
EndFunction
Function WorldObstacles()
rem create obstacles in a clockwise direction (imagining 3D top down x/z co-ordinates)
rem bottom wall
AI Start New Obstacle
AI Add Obstacle Vertex 5,310
AI Add Obstacle Vertex 5,330
AI Add Obstacle Vertex 500,330
AI Add Obstacle Vertex 500,310
AI End New Obstacle 0,1
rem top wall
AI Start New Obstacle
AI Add Obstacle Vertex 140,180
AI Add Obstacle Vertex 140,200
AI Add Obstacle Vertex 635,200
AI Add Obstacle Vertex 635,180
AI End New Obstacle 0,1
rem create the boundary in an anti-clockwise direction
rem boundary
AI Start New Obstacle
AI Add Obstacle Vertex 0,0
AI Add Obstacle Vertex 640,0
AI Add Obstacle Vertex 640,480
AI Add Obstacle Vertex 0,480
AI End New Obstacle 0,1
AI Complete Obstacles
EndFunction
End
Also how can I get the debug code to work?