Uhh, that doesn't work either. By the way, I think I posted that code wrong because I opened my project today and the numbers in the 'for' statements were different hten what I posted.
Here's my full code.
`basic set up
sync on
sync rate 60
set display mode 1024,768,32
autocam off
hide mouse
`matrix set up
matrix = 1
size = 500
make matrix matrix,size,size,20,20
for x = 0 to 64
for y = 0 to 64
dot x,y,rgb(0,rnd(156),0)
next y
next x
get image 1,0,0,64,64
cls
prepare matrix texture matrix,1,1,1
update matrix matrix
`player set up
player = 100
pspeed# = 0.5
bullet# = 200
score# = 0
full_ammo# = 1
ammo# = full_ammo#
health# = 100
make object cube player,1
position object player,rnd(20),1,rnd(20)
make object sphere bullet#,1
set object collision on bullet#
set object collision to spheres bullet#
hide object bullet#
`ammo crate set up
number_crates = 5
for x = 1 to number_crates
make object sphere x+100,2
set object collision on x+100
set object collision to spheres x+100
color object x+100,rgb(255,0,0)
position object x+100,rnd(size),1,rnd(size)
next x
`enemy set up
number_enemies = 10
dim enemystate(number_enemies)
dim enemymove(number_enemies)
enemyawareness# = 15
enemyspeed# = 0.3
for x = 1 to number_enemies
make object sphere x,1
set object collision on x
set object collision to spheres x
enemystate(x) = rnd(2)
enemymove(x) = 1
position object x,rnd(size),1,rnd(size)
next x
do
`shooting control
`actual shooting
`updates vars + prep bullet# object
if mouseclick()=1 and bulletlife = 0 and ammo# > 0
position object bullet#,x1#,y1#+4.5,z1#
set object to camera orientation bullet#
bulletlife = 25
show object bullet#
ammo# = ammo# - 1
endif
`move bullet# object
if bulletlife > 0
dec bulletlife
move object bullet#,10
if bulletlife = 0
hide object bullet#
endif
endif
`reload stuff
`alert user of ammo status
if ammo# = 0
text screen width()/2,screen height()/2,"Press 'R' to reload!"
`if keystate(19)=1
`ammo# = full_ammo#
`endif
endif
`picking up ammo boxes
for x = 101 to 100+number_crates
if object collision(player#,x)=1
position object x,-5,1,-5
ammo# = full_ammo#
endif
next x
`shooting collision detection
for x = 1 to number_enemies
if object collision(bullet#,x)=1
score# = score# + 10
endif
next x
`movement control
`player movement
`variables what it does
x1# = object position x(player) `x location of player
z1# = object position z(player) `z location of player
y1# = get ground height(matrix,x1#,z1#)+0.1 `places charcater on ground, y location
ax1# = object angle x(player) `x angle of player
ay1# = object angle y(player) `y angle of player
mx# = mousemovex() `x movement of mouse. up and down
my# = mousemovey() `y movement of mouse. left and right
oldcamx# = camx# `old camera posistion x
oldcamy# = camy# `old camera position y
camx# = wrapvalue(camx#+my#*0.2) `current cam x position
camy# = wrapvalue(camy#+mx#*0.2) `current cam y position
`position camera to follow player
set camera to follow x1#,y1#,z1#,ay1#,10,5,1,1
position object player,x1#,y1#,z1#
`keep player inside matrix
if x1# <= 0 then position object player,0.1,y1#,z1#
if x1# >= 500 then position object player,499.9,y1#,z1#
if z1# <= 0 then position object player,x1#,y1#,0.1
if z1# >= 500 then position object player,x1#,y1#,499.9
`create a crosshair
line screen width()/2-12,screen height()/2,screen width()/2+12,screen height()/2
line screen width()/2,screen height()/2-10,screen width()/2,screen height()/2+10
`look around with the mouse
xrotate camera curveangle(camx#,oldcamx#,24)
yrotate camera curveangle(camy#,oldcamy#,24)
yrotate object player,curveangle(camy#,oldcamy#,24)
`stop mouse from going upside down
if wrapvalue(camera angle x(0)) >= 22 then xrotate camera 0,21
if wrapvalue(camera angle x(0)) <= -7 then xrotate camera 0,-6
`move player with WASD keys
if keystate(17)=1 then move object player,pspeed# `foward - W
if keystate(31)=1 then move object player,pspeed#*(-1) `backard - S
if keystate(30)=1 then move object left player,pspeed# `left - A
if keystate(32)=1 then move object right player,pspeed# `right - D
`enemy movement
for x = 1 to number_enemies
if enemymove(x) = 1
`location variables
x2# = object position x(x)
z2# = object position z(x)
y2# = get ground height(matrix,x2#,z2#)
ay2# = object angle y(x)
`get enemy distance, to see if they will attack or not
distance# = sqrt( ((x2# - x1#) ^ 2) + ((y2# - y1#) ^ 2) + ((z2# - z1#) ^2 ) )
`if enemy distance is less then the awareness number (see start of code)
`then enemy will come after player
if distance# <= enemyawareness#
enemystate(x) = 3
endif
`if distance is farther then awareness number enemy
`goes to the wandering state
if distance# > enemyawareness# and enemystate(x) = 3
enemystate(x) = 2
endif
`if enemystate()=2 or wandering, just walking around
if enemystate(x) = 2
`move enemy
if upright = 0
x2# = x2# + enemyspeed#
z2# = z2# + enemyspeed#
`keep enemy in boundary
`turn around if neccesary
`upright to 1 means turning it around
if x2# > size or z2# > size then upright = 1
endif
if upright = 1
x2# = x2# - enemyspeed#
z2# = z2# - enemyspeed#
`keep in boundary, turn around if needed
if x2# < 0 or z2# < 0 then upright = 0
endif
endif
`chase mode...only if close enough
`need to move enemy towards player location
if enemystate(x) = 3
`move towards player
if x2# < x1# then x2# = x2# + enemyspeed#
if x2# > x1# then x2# = x2# - enemyspeed#
if z2# < z1# then z2# = z2# + enemyspeed#
if z2# > z1# then z2# = z2# - enemyspeed#
endif
`position the enemy now
`for enemystate 2, rotate object to face direction
`its moving
if enemystate(x)=2
position object x,x2#,y2#+1,z2#
rotate object x,object angle x(x),ay1#,object angle z(x)
endif
`for enemystate 3, we want enemies to look at us
`so rotate enemy towards us
if enemystate(x)=3
position object x,x2#,y2#+1,z2#
rotate object x,object angle x(x),ay1#,object angle z(x)
endif
endif
next x
`HUD-type display
set cursor 10,600
print
print "Health: ";health#
print "Ammo: ";ammo#
print "Score: ";score#
sync
loop