I'm from the camp that likes to simply point objects and move them toward other objects rather than use atanfull, but it can work either way.
I edited your code and installed some TYPE variables. My hope is that you can learn from it, even if you don't end up using it. I also tried to organize it so that repetitive code was placed into subroutines. I declared some variables as global in case you want to change the subroutines into functions at some point (this is not necessary when using subroutines, it's just a force of habit on my part I guess).
The enemy spheres will look at where the player is and move towards it. Some move faster than others. If they collide with the player, the player will turn red and fade out. The player and enemies are then re-spawned at their original locations.
Rem Project: That Game
Rem Created: Sunday, June 13, 2010
Rem ***** Main Source File *****
Sync On : Sync Rate 60 : Hide Mouse : Set Display Mode 800,600,32
Autocam Off : randomize timer()
type PlayerData
ObjNum as integer
x# as float : y# as float : z# as float
status as integer
speed# as float
fade as integer
endtype
player as PlayerData
type EnemyData
ObjNum as integer
x# as float : y# as float : z# as float
status as integer
speed# as float
endtype
global TotalEnemies as integer : TotalEnemies = 3
dim enemy(TotalEnemies) as EnemyData
global ESpawnX# as float : ESpawnX# = -280.0
global ESpawnZ# as float : ESpawnZ# = 180.0
global GotPlayer as integer : GotPlayer = 0
player.ObjNum = 1 : player.status = 1 : player.speed# = 5.0
Player.x# = 0.0 : Player.y# = 0.0 : Player.z# = 0.0
player.fade = 255
For a = 1 to TotalEnemies
Enemy(a).ObjNum = 99 + a
Enemy(a).x# = ESpawnX# + (a * 50)
Enemy(a).y# = 0.0
Enemy(a).z# = EspawnZ#
Enemy(a).status = 1 : ` active
Enemy(a).speed# = a
Next a
Make Object cube player.ObjNum,50
Color Object player.ObjNum,RGB(0,255,0) : set object ambience player.ObjNum,rgb(0,player.fade,0)
make object collision box player.ObjNum, -25.0, -25.0, -25.0, 25.0, 25.0, 25.0, 1
For e = 1 to TotalEnemies
Make object sphere Enemy(e).ObjNum,25
Color object Enemy(e).ObjNum,RGB(255,0,0)
Position Object Enemy(e).ObjNum,Enemy(e).x#,Enemy(e).y#,Enemy(e).z#
make object collision box Enemy(e).ObjNum, -12.5, -12.5, -12.5, 12.5, 12.5, 12.5, 1
Next e
`Make Walls
Make Object Box 30,100,100,600 : Position Object 30,-330,0,25
Make Object Box 31,600,100,100 : Position Object 31,20,0,320
Make Object Box 32,100,100,600 : Position Object 32,355,0,50
Make Object Box 33,700,100,100 : Position Object 33,20,0,-300
For w = 30 to 33
Color Object w,RGB(100,0,100)
Next w
Do
gosub PlayerInput
gosub MoveEnemies
`Camera
Position Camera Player.x#,700,-600
Point Camera Player.x#,Player.y#,Player.z#
Sync
Loop
end
PlayerInput:
if GotPlayer = 0
` allow the player to move
`Controls
oldx# = player.x# : oldy# = player.y# : oldz# = player.z#
If Upkey() = 1 Then player.z# = player.z# + player.speed#
If Downkey() = 1 Then player.z# = player.z# - player.speed#
If Leftkey() = 1 Then player.x# = player.x# - player.speed#
If RightKey() = 1 Then player.x# = player.x# + player.speed#
position object player.ObjNum,player.x#,player.y#,player.z#
collide = object collision(player.ObjNum,0)
If collide >= 30 and collide <= 33
player.x# = oldx# : player.y# = oldy# : player.z# = oldz#
endif
position object player.ObjNum,player.x#,player.y#,player.z#
else
` player is dying - fade it out
player.fade = player.fade - 4
if player.fade <= 0
player.fade = 255
color object player.ObjNum,rgb(0,player.fade,0) : set object ambience player.ObjNum,rgb(0,player.fade,0)
GotPlayer = 0
` re-spawn enemies
For a = 1 to TotalEnemies
Enemy(a).x# = ESpawnX# + (a * 50)
Enemy(a).y# = 0.0
Enemy(a).z# = EspawnZ#
Enemy(a).status = 1 : ` active
Enemy(a).speed# = a
position object Enemy(a).ObjNum,Enemy(a).x#,Enemy(a).y#,Enemy(a).z#
Next a
Player.x# = 0.0 : Player.y# = 0.0 : Player.z# = 0.0
position object player.ObjNum,player.x#,player.y#,player.z#
else
color object player.ObjNum,rgb(player.fade,0,0) : set object ambience player.ObjNum,rgb(player.fade,0,0)
endif
endif
return
MoveEnemies:
for e = 1 to TotalEnemies
if enemy(e).status = 1 : ` is enemy active?
point object enemy(e).ObjNum,player.x#,player.y#,player.z#
` store old values in case we run into a wall
oldx# = enemy(e).x# : oldy# = enemy(e).y# : oldz# = enemy(e).z#
move object enemy(e).ObjNum,enemy(e).speed#
`check collision
collide = object collision(enemy(e).ObjNum,0)
if collide >= 30 and collide <= 33
` hit a wall, back it up
position object enemy(e).ObjNum,Oldx#,Oldy#,Oldz#
else
if collide = player.ObjNum
GotPlayer = 1
endif
endif
endif
next e
return
I hope this is helpful.
LB