ma top-down view arcade game is doing what it should , for a debug version, but the fps becomes verry low when there're lots of enemies.
But the gameplay requires lots of enemies...
so, can any1 test my code and tell me what is the biggest problem ?
(i know many object causes low fps, so looking for suggestion in fixing that but keeping same gameplay = lots of enemies )
any comments on the way to structure code are also welcome.
actually, all comments are welcome
gameplay :
drive around and kill all enemies + spawnpoints
(currently 4 spawnpoints with each max 99 enemies)
small spheres are powerups (bulletspeed/time_between_bullets/health)
controls :
qsdz/cursor = move
leftmouse = shoot
rightmouse = reload
scroll wheel = camera height
control = lock turret on car
enter = change to FPS (switch code needs help!! )
this is the full source :
sync on
hide mouse
' sync rate 60
' set display mode 1024,768,32
rem -------- make rnd texture for testing
Image_Size=256
for a=1 to 4
for b=1 to 4
ink rgb(rnd(255),rnd(255),rnd(255)),1
box -64+a*64,-64+b*64,a*64,b*64
next a
next b
get image 1,0,0,Image_Size,Image_Size
rem -------- make rnd grasslike texture
Image_Size=64
for x = 0 to Image_Size
for y = 0 to Image_Size
dot x,y,rgb(0,rnd(156),0)
next x
next y
get image 2,0,0,Image_Size,Image_Size
rem ------ make matrix
make matrix 1,2000,2000,20,20
' randomize matrix 1,50
prepare matrix texture 1,1,1,1
rem set these vars as globals
rem they or called in loop function and come from a copied funtion
rem to determine mouse position in 3d
global mouse3d_x#
global mouse3d_y#
global mouse3d_z#
backdrop on
color backdrop RGB(0,0,0)
rem light settings
COLOR AMBIENT LIGHT RGB(128,128,128)
SET AMBIENT LIGHT 50
COLOR LIGHT 0, RGB(0,0,0)
set light range 0,0
rem player headlights
MAKE LIGHT 1
show LIGHT 1
set light range 1,1500
set spot light 1, 0, 45
COLOR LIGHT 1, RGB(255,128,0)
rem mouse light
MAKE LIGHT 2
show LIGHT 2
set light range 2,250
set spot light 2, 0, 45
COLOR LIGHT 2, RGB(0,255,0)
rem turret spot
MAKE LIGHT 3
show LIGHT 3
set light range 3,2000
set spot light 3, 0, 20
COLOR LIGHT 3, RGB(255,128,0)
rem player top light
MAKE LIGHT 4
show LIGHT 4
set light range 4,750
' set spot light 4, 0, 90
COLOR LIGHT 4, RGB(128,128,128)
rem --- setup some vars
default_player_speed#=3
player_speed#=3
speed#=5
enemy_speed#=10
rem player start pos
posx#=500.0
posz#=500.0
nr_kills# = 0
player_cam$ = "main"
turret_lock = 0
rem hud font
SET TEXT SIZE 20
set text to bold
ink rgb(255,0,0),rgb(255,0,0)
rem ------- cam setup
rem cam range (needed for mouse3d)
camr#=10000
rem cam focal (needed for mouse3d)
FOV#=60
set camera fov FOV#
rem cam_switch boolean
cam_switch = 0
rem pov cam
MAKE CAMERA 2
SET CAMERA VIEW 2, 40, screen height()-100, 165, screen height()-5
color backdrop 2, RGB(0,0,0)
rem turret cam
MAKE CAMERA 3
SET CAMERA VIEW 3, 190, screen height()-100, 315, screen height()-5
color backdrop 3, RGB(0,0,0)
rem mouse cam
MAKE CAMERA 4
SET CAMERA VIEW 4, 340, screen height()-100, 465, screen height()-5
color backdrop 4, RGB(0,0,0)
rem overview cam
MAKE CAMERA 5
SET CAMERA VIEW 5, 490, screen height()-100, 615, screen height()-5
color backdrop 5, RGB(0,0,0)
rem Make walls
make object box 10, 2000, 100, 5
SET OBJECT LIGHT 10, 1
position object 10, 1000, 0, 0
make object box 11, 2000, 100, 5
SET OBJECT LIGHT 11, 1
position object 11, 1000, 0, 2000
make object box 12, 5, 100, 2000
SET OBJECT LIGHT 12, 1
position object 12, 2000, 0, 1000
make object box 13, 5, 100, 2000
SET OBJECT LIGHT 13, 1
position object 13, 0, 0, 1000
REM ------ bullets setup
rem starting from 0 !!
max_bullets_on_screen# = 99
bullets_on_screen# = 0
bullets_until_reload# = 25
bullets_until_reload_count# = 0
time_between_bullets# = 250
bullet_life# = 3000
time_since_last_bullet# = timer()
bullet_id# = 0
bullet_speed# = 20
dim bullet$(100,6)
rem make bullets and put them in objects 100 to 199
for i=0 to max_bullets_on_screen#
objid# = 100+bullet_id#
make object box objid#,1,1,50
color object objid#, rgb(255,0,0)
rem ghost object on objid#,0
bullet_id# = bullet_id# + 1
bullet$(i,0) = str$(0)
bullet$(i,1) = "setup"
bullet$(i,2) = "niks"
bullet$(i,3) = "x"
bullet$(i,4) = "y"
bullet$(i,5) = "z"
set object collision on objid#
set object collision to boxes objid#
make particles objid#,1,10,30.0
set particle life objid#,5
set particle velocity objid#, 10
SET PARTICLE EMISSIONS objid#, 1
SET PARTICLE GRAVITY objid#, 0
SET PARTICLE SPEED objid#, 0.01
SET PARTICLE CHAOS objid#, 0
hide particles objid#
MAKE LIGHT objid#
hide LIGHT objid#
set light range objid#,500
COLOR LIGHT objid#, RGB(255,0,0)
next i
rem bullet_id setting to zero again just to be safe
bullet_id# = 0
rem ------- end bullets setup
rem level start
level = 1
level_start=0
remstart
rem Make enemies
dim EnemyState(100)
dim enemy$(100,3)
dim health_enemy(100)
`This will define how far the enemies can spot you and chase you.
EnemyAwareness#=500
enemies_on_screen# = 0
rem starting from 0 !!
max_enemies_on_screen# = 25
for i=0 to max_enemies_on_screen#
objid# = 900+i
make object cube objid#,50
rem hidden cube for patrol
make object cube 9000+objid#,1
position object 9000+objid#, rnd(2000),10,rnd(2000)
set object collision on 9000+objid#
set object collision to boxes 9000+objid#
hide object 9000+objid#
SET OBJECT LIGHT objid#, 1
rem color object objid#,rgb(255,0,0)
position object objid#, rnd(2000),25,rnd(2000)
enemy$(i,1) = "alive"
enemy$(i,2) = str$(timer())
enemy$(i,3) = "onscreen"
enemy$(i,4) = str$(100)
health_enemy(i) = 100
set object collision on objid#
set object collision to boxes objid#
enemies_on_screen# = enemies_on_screen# + 1
EnemyState(i) = rnd(2)
next i
remend
rem Make powerups
dim powerup$(100,3)
for i=0 to 10
rem health powerups
objid# = 500+i
make object sphere objid#,50
color object objid#,rgb(0,255,0)
position object objid#, rnd(2000),0,rnd(2000)
powerup_height = get ground height(1,object position x(objid#),object position z(objid#))
position object objid#, rnd(2000),powerup_height,rnd(2000)
rem health powerup
powerup$(i,1) = str$(75)
powerup$(i,2) = "health"
powerup$(i,4) = "waiting"
set object collision on objid#
set object collision to boxes objid#
next i
for i=11 to 20
rem speed powerups
objid# = 500+i
make object sphere objid#,50
color object objid#,rgb(0,0,255)
position object objid#, rnd(2000),10,rnd(2000)
powerup_height = get ground height(1,object position x(objid#),object position z(objid#))
position object objid#, rnd(2000),powerup_height,rnd(2000)
rem health powerup
powerup$(i,1) = str$(50)
powerup$(i,2) = "weapon_rate"
powerup$(i,3) = "waiting"
set object collision on objid#
set object collision to boxes objid#
next i
for i=21 to 30
rem speed powerups
objid# = 500+i
make object sphere objid#,50
color object objid#,rgb(0,255,255)
position object objid#, rnd(2000),10,rnd(2000)
powerup_height = get ground height(1,object position x(objid#),object position z(objid#))
position object objid#, rnd(2000),powerup_height,rnd(2000)
rem health powerup
powerup$(i,1) = str$(20)
powerup$(i,2) = "bullet_speed"
powerup$(i,3) = "waiting"
set object collision on objid#
set object collision to boxes objid#
next i
rem Make player
dim player(4)
rem health
player(4) = 100
make object box 1,30,10,100
color object 1,rgb(0,0,255)
rem front
make object box 50,15,5,15
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 1, 20
delete mesh 20
show limb 1, 1
COLOR LIMB 1, 1, RGB(0,255,0)
SCALE LIMB 1, 1, 100, 100, 100
OFFSET LIMB 1, 1, 0,0,50
rem back
make object box 50,25,4,4
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 2, 20
delete mesh 20
show limb 1, 2
COLOR LIMB 1, 2, RGB(255,0,0)
SCALE LIMB 1, 2, 100, 100, 100
OFFSET LIMB 1, 2, 0,5,-50
rem wheel left front
make object sphere 50,20
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 3, 20
delete mesh 20
show limb 1, 3
COLOR LIMB 1, 3, RGB(255,0,0)
SCALE LIMB 1, 3, 100, 100, 100
OFFSET LIMB 1, 3, -10,-6,30
rem wheel right front
make object sphere 50,20
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 4, 20
delete mesh 20
show limb 1, 4
COLOR LIMB 1, 4, RGB(255,0,0)
SCALE LIMB 1, 4, 100, 100, 100
OFFSET LIMB 1, 4, 10,-6,30
rem wheel left back
make object sphere 50,20
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 5, 20
delete mesh 20
show limb 1, 5
COLOR LIMB 1, 5, RGB(255,0,0)
SCALE LIMB 1, 5, 100, 100, 100
OFFSET LIMB 1, 5, -10,-6,-30
rem wheel right back
make object sphere 50,20
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 6, 20
delete mesh 20
show limb 1, 6
COLOR LIMB 1, 6, RGB(255,0,0)
SCALE LIMB 1, 6, 100, 100, 100
OFFSET LIMB 1, 6, 10,-6,-30
rem limb for headlight
make object cube 50, 1
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 7, 20
delete mesh 20
hide limb 1, 7
COLOR LIMB 1, 7, RGB(0,255,0)
SCALE LIMB 1, 7, 100, 100, 100
OFFSET LIMB 1, 7, 0,0,-250
rem end make player
rem Make turret
make object box 2,10,10,15
color object 2,rgb(255,0,0)
rem extend turret
make object box 50,5,5,40
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 2, 1, 20
delete mesh 20
show limb 2, 1
COLOR LIMB 2, 1, RGB(255,0,0)
SCALE LIMB 2, 1, 100, 100, 100
OFFSET LIMB 2, 1, 0,0,25
rem make limb for turret spot
make object cube 50,50
MAKE MESH FROM OBJECT 20, 1
delete object 50
ADD LIMB 2, 2, 20
delete mesh 20
hide limb 2, 2
SCALE LIMB 2, 2, 100, 100, 100
OFFSET LIMB 2, 2, 0,0,-500
rem make limb for bullet direction
make object cube 50,50
MAKE MESH FROM OBJECT 20, 1
delete object 50
ADD LIMB 2, 3, 20
delete mesh 20
hide limb 2, 3
SCALE LIMB 2, 3, 100, 100, 100
OFFSET LIMB 2, 3, 0,0,500
rem make mouse
make object sphere 3,20
make object box 50,5,150,5
rem stickpointer
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 3, 1, 20
delete mesh 20
show limb 3, 1
SCALE LIMB 3, 1, 100, 100, 100
OFFSET LIMB 3, 1, 0,25,0
ghost object on 3,4
rem make pointer outside of matrix, extending turret
make object sphere 4,1
hide object 4
rem spawnpoints vars setup
spawnpoints_object_start_nr# = 5000
enemies_object_start_nr# = 9000
nr_enemies_created = 0
nr_enemies_on_screen = 0
TYPE MyType_spawnpoints
use AS STRING
status AS STRING
hit_status AS STRING
pos_x AS STRING
pos_y AS STRING
pos_z AS STRING
nr_enemies_spawned AS INTEGER
time_between_spawns AS INTEGER
time_since_last_spawn AS INTEGER
level AS STRING
health AS INTEGER
scale_x AS INTEGER
scale_y AS INTEGER
scale_z AS INTEGER
ENDTYPE
DIM spawnpoint(50) AS MyType_spawnpoints
TYPE MyType_enemies
status AS STRING
hit_status AS STRING
pos_x AS STRING
pos_y AS STRING
pos_z AS STRING
time_off_dead AS INTEGER
health AS INTEGER
spawnpoint_objid AS integer
vision as integer
ENDTYPE
DIM enemy(100) AS MyType_enemies
rem Begin main loop
rem -------------------------------------------
do
rem call 3dmouse positioning function, copied from codebase
mmcoord(mousex(),mousey(),1,camr#,FOV#)
rem levelcheck
rem all level settings like spawnpoints nr and location, enemy types etc
rem this part can be included so all level settings go in seperate file
if level = 1
if level_start = 0
rem setup spawnpoint 1
spawnpoint(1).use="on"
spawnpoint(1).status="waiting_to_spawn_enemy"
spawnpoint(1).pos_x=str$(1000)
spawnpoint(1).pos_y=str$(0)
spawnpoint(1).pos_z=str$(1000)
spawnpoint(1).nr_enemies_spawned=0
spawnpoint(1).time_between_spawns=3000
spawnpoint(1).time_since_last_spawn=timer()
spawnpoint(1).level="medium"
spawnpoint(1).health=100
spawnpoint(1).scale_x=100
spawnpoint(1).scale_y=100
spawnpoint(1).scale_z=100
spawnpoint(2).use="on"
spawnpoint(2).status="waiting_to_spawn_enemy"
spawnpoint(2).pos_x=str$(1000)
spawnpoint(2).pos_y=str$(0)
spawnpoint(2).pos_z=str$(1500)
spawnpoint(2).nr_enemies_spawned=0
spawnpoint(2).time_between_spawns=3000
spawnpoint(2).time_since_last_spawn=timer()
spawnpoint(2).level="medium"
spawnpoint(2).health=100
spawnpoint(2).scale_x=100
spawnpoint(2).scale_y=100
spawnpoint(2).scale_z=100
spawnpoint(3).use="on"
spawnpoint(3).status="waiting_to_spawn_enemy"
spawnpoint(3).pos_x=str$(1500)
spawnpoint(3).pos_y=str$(0)
spawnpoint(3).pos_z=str$(1000)
spawnpoint(3).nr_enemies_spawned=0
spawnpoint(3).time_between_spawns=3000
spawnpoint(3).time_since_last_spawn=timer()
spawnpoint(3).level="medium"
spawnpoint(3).health=100
spawnpoint(3).scale_x=100
spawnpoint(3).scale_y=100
spawnpoint(3).scale_z=100
spawnpoint(4).use="on"
spawnpoint(4).status="waiting_to_spawn_enemy"
spawnpoint(4).pos_x=str$(1500)
spawnpoint(4).pos_y=str$(0)
spawnpoint(4).pos_z=str$(1500)
spawnpoint(4).nr_enemies_spawned=0
spawnpoint(4).time_between_spawns=3000
spawnpoint(4).time_since_last_spawn=timer()
spawnpoint(4).level="medium"
spawnpoint(4).health=100
spawnpoint(4).scale_x=100
spawnpoint(4).scale_y=100
spawnpoint(4).scale_z=100
for i=1 to ARRAY COUNT(spawnpoint())
objid# = spawnpoints_object_start_nr# + i
if spawnpoint(i).use = "on"
make object sphere objid#,150
SET OBJECT LIGHT objid#, 1
ghost object on objid#, 3
color object objid#, rgb(rnd(255),rnd(255),rnd(255))
position object objid#, val(spawnpoint(i).pos_x),val(spawnpoint(i).pos_y),val(spawnpoint(i).pos_z)
scale object objid#, spawnpoint(i).scale_x, spawnpoint(i).scale_y, spawnpoint(i).scale_z
rem make limb for health bar
make object box 50,100,5,5
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB objid#, 1, 20
delete mesh 20
OFFSET LIMB objid#, 1, 0,100,0
color limb objid#, 1, rgb(255,0,0)
endif
next i
level_start = 1
rem setup level
endif
rem end level check
endif
rem ------- Controls
rem forwards (z) (azerty layout)
if keystate(17)=1 or upkey()=1
posx#=newxvalue(posx#, angle#, player_speed#)
posz#=newzvalue(posz#, angle#, player_speed#)
endif
rem backwards (s) (azerty layout)
if keystate(31)=1 or downkey()=1
posx#=newxvalue(posx#, angle#, 0-(player_speed#/3))
posz#=newzvalue(posz#, angle#, 0-(player_speed#/3))
endif
rem left (q) (azerty layout)
if keystate(30)=1 or leftkey()=1
angle#=wrapvalue(angle#-(player_speed#/2))
remstart also move forward for carlike controls
posx#=newxvalue(posx#, angle#, player_speed#/6)
posz#=newzvalue(posz#, angle#, player_speed#/6)
remend
endif
rem right (d) (azerty layout)
if keystate(32)=1 or rightkey()=1
angle#=wrapvalue(angle#+(player_speed#/2))
remstart also move forward for carlike controls
posx#=newxvalue(posx#, angle#, player_speed#/6)
posz#=newzvalue(posz#, angle#, player_speed#/6)
remend
endif
rem strafe links (a) (azerty layout)
if keystate(16)=1
posx#=newxvalue(posx#, angle#-90, player_speed#/3)
posz#=newzvalue(posz#, angle#-90, player_speed#/3)
endif
rem strafe rechts (e) (azerty layout)
if keystate(18)=1
posx#=newxvalue(posx#, angle#+90, player_speed#/3)
posz#=newzvalue(posz#, angle#+90, player_speed#/3)
endif
REM start shift/turbo check
if shiftkey()=1
if turbo# = 0
player_speed# = player_speed#*2
turbo# = 1
endif
endif
if shiftkey()=0
turbo# = 0
player_speed# = default_player_speed#
endif
REM end shift/turbo check
rem end controls
rem a temp solution for rightmouse+space bug (aka reload cheat)
if bullets_on_screen# > max_bullets_on_screen#
bullets_on_screen# = max_bullets_on_screen#
endif
if bullets_on_screen# < 0
bullets_on_screen# = 0
endif
rem spawnpoints check
for i=1 to ARRAY COUNT(spawnpoint())
if spawnpoint(i).use = "on"
spawnpoint_id# = spawnpoints_object_start_nr# + i
if spawnpoint(i).level = "medium"
enemies_to_spawn = 99
else
enemies_to_spawn = 2
endif
if spawnpoint(i).nr_enemies_spawned > enemies_to_spawn
spawnpoint(i).status = "idle"
endif
if spawnpoint(i).status = "waiting_to_spawn_enemy"
if spawnpoint(i).nr_enemies_spawned < enemies_to_spawn
if spawnpoint(i).time_since_last_spawn < timer() - spawnpoint(i).time_between_spawns
enemy_id = nr_enemies_created
enemy(enemy_id).status = "waiting_to_spawn"
enemy(enemy_id).spawnpoint_objid = spawnpoint_id#
enemy(enemy_id).vision = 500
nr_enemies_created = nr_enemies_created + 1
nr_enemies_on_screen = nr_enemies_on_screen + 1
spawnpoint(i).time_since_last_spawn = timer()
spawnpoint(i).nr_enemies_spawned = spawnpoint(i).nr_enemies_spawned + 1
endif
endif
endif
if spawnpoint(i).hit_status = "hit"
rem if spawnpoint medium
spawnpoint(i).health = spawnpoint(i).health - 10
spawnpoint(i).hit_status = "none"
scale limb spawnpoint_id#, 1, spawnpoint(i).health, 100, 100
endif
if spawnpoint(i).status <> "dead"
if spawnpoint(i).health <= 0
hide object spawnpoint_id#
set object collision off spawnpoint_id#
spawnpoint(i).status = "dead"
spawnpoint(i).use = "off"
endif
endif
rem end if ON
endif
next i
rem end spawnpoints check
rem enemy check
for i=0 to nr_enemies_created
enemy_id# = enemies_object_start_nr# + i
if enemy(i).status = "waiting_to_spawn"
make object cube enemy_id#, 50
SET OBJECT LIGHT enemy_id#, 1
color object enemy_id#, rgb(255,255,255)
position object enemy_id#, object position x (enemy(i).spawnpoint_objid), object position y (enemy(i).spawnpoint_objid), object position z (enemy(i).spawnpoint_objid)
scale object enemy_id#, 100, 100, 100
set object collision on enemy_id#
set object collision to boxes enemy_id#
rem make patrol object
make object cube 9000+enemy_id#, 50
position object 9000+enemy_id#, rnd(2000),10,rnd(2000)
set object collision on 9000+enemy_id#
set object collision to boxes 9000+enemy_id#
hide object 9000+enemy_id#
rem make limb for health bar
make object box 50,100,5,5
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB enemy_id#, 1, 20
delete mesh 20
OFFSET LIMB enemy_id#, 1, 0,100,0
rem if medium
enemy(i).status = "patrol"
enemy(i).health = 100
endif
if enemy(i).status = "patrol"
distance_between_current_enemy_and_player# = distance_between_player_and_object(enemy_id#)
if distance_between_current_enemy_and_player# <= enemy(i).vision
enemy(i).status = "chasing"
endif
color object enemy_id#, RGB(255,128,0)
point object enemy_id#, object position x(9000+enemy_id#),object position y(9000+enemy_id#),object position z(9000+enemy_id#)
move object enemy_id#, 1
enemy_height# = 25+get ground height(1,object position x(enemy_id#),object position z(enemy_id#))
position object enemy_id#, object position x(enemy_id#), enemy_height#, object position z(enemy_id#)
rem if enemy at hidden marker, move marker
if object collision (enemy_id#,0)
if object collision (enemy_id#,0) = 9000+enemy_id#
position object 9000+enemy_id#, rnd(2000),10,rnd(2000)
endif
endif
endif
if enemy(i).status = "chasing"
distance_between_current_enemy_and_player# = distance_between_player_and_object(enemy_id#)
if distance_between_current_enemy_and_player# > enemy(i).vision
enemy(i).status = "patrol"
endif
color object enemy_id#, RGB(255,0,0)
point object enemy_id#, object position x(1),object position y(1),object position z(1)
move object enemy_id#, 2
enemy_height# = 25+get ground height(1,object position x(enemy_id#),object position z(enemy_id#))
position object enemy_id#, object position x(enemy_id#),enemy_height#,object position z(enemy_id#)
endif
if enemy(i).hit_status = "hit"
rem if enemy medium
enemy(i).health = enemy(i).health - 25
enemy(i).hit_status = "none"
scale limb enemy_id#, 1, enemy(i).health, 100, 100
endif
rem if enemy medium
if enemy(i).health < 50
enemy(i).vision = 2000
endif
if enemy(i).status <> "dead"
if enemy(i).health <= 0
hide object enemy_id#
hide object 9000+enemy_id#
set object collision off enemy_id#
enemy(i).status = "dead"
nr_enemies_on_screen = nr_enemies_on_screen - 1
endif
endif
next i
rem end enemy check
rem start bullet check
for i=0 to max_bullets_on_screen#
objid# = 100+i
if object exist(objid#) = 1
if bullet$(i,1) = "fired"
if val(bullet$(i,0)) < timer() - bullet_life#
rem if old bullet kill it
hide object objid#
hide particles objid#
hide light objid#
bullets_on_screen# = bullets_on_screen# - 1
bullet$(i,1) = "hidden"
else
rem if active bullet do the following
move object objid#, bullet_speed#
position particles objid#, object position x(objid#),object position y(objid#),object position z(objid#)
position LIGHT objid#, object position x(objid#),object position y(objid#)+25,object position z(objid#)
if object collision (objid#,0)
obj_hit# = object collision (objid#,0)
if obj_hit# >= spawnpoints_object_start_nr# and spawnpoints_object_start_nr# + 999 > obj_hit#
obj_hit_id = obj_hit# - spawnpoints_object_start_nr#
spawnpoint(obj_hit_id).hit_status = "hit"
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
bullets_on_screen# = bullets_on_screen# - 1
bullet$(i,1) = "hidden"
endif
if obj_hit# >= enemies_object_start_nr# AND enemies_object_start_nr# + 999 > obj_hit#
rem if enemy
obj_hit_id = obj_hit# - enemies_object_start_nr#
enemy(obj_hit_id).hit_status = "hit"
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
bullets_on_screen# = bullets_on_screen# - 1
bullet$(i,1) = "hidden"
endif
if 14 > obj_hit# AND obj_hit# > 9
rem if wall
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
bullets_on_screen# = bullets_on_screen# - 1
bullet$(i,1) = "hidden"
endif
endif
if object position x(objid#) > 2000
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
endif
if object position z(objid#) > 2000
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
endif
if object position x(objid#) < 0
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
endif
if object position z(objid#) < 0
hide object objid#
hide particles objid#
hide light objid#
set object collision off objid#
endif
endif
endif
if bullet$(i,1) = "setup"
hide object objid#
hide particles objid#
hide light objid#
bullet$(i,1) = "hidden"
endif
endif
next i
rem end bullet check
rem start player check
if object collision (1,0)
obj_hit# = object collision (1,0)
if obj_hit# > enemies_object_start_nr# and obj_hit# < enemies_object_start_nr# + 1000
rem if enemy
player(4) = player(4) - 1
endif
if obj_hit# > 499 AND obj_hit# < 599
rem if powerup
obj_hit_id = obj_hit# - 500
if powerup$(obj_hit_id,2) = "health"
player(4) = player(4) + val(powerup$(obj_hit_id,1))
endif
if powerup$(obj_hit_id,2) = "weapon_rate"
time_between_bullets# = time_between_bullets# - val(powerup$(obj_hit_id,1))
if time_between_bullets# < 75
time_between_bullets# = 75
endif
endif
if powerup$(obj_hit_id,2) = "bullet_speed"
bullet_speed# = bullet_speed# + val(powerup$(obj_hit_id,1))
if bullet_speed# > 100
bullet_speed# = 100
endif
endif
hide object obj_hit#
set object collision off obj_hit#
endif
endif
rem end player check
if player(4) <= 0
player(4) = 0
text 250, 100, "health = 0 !!"
endif
if nr_enemies_on_screen = 0
text 250, 60, "debug... u killed em all !!!! but theyll respawn"
text 250, 75, "debug... kill spawnpoints to stop spawning"
endif
rem mouseclick for bullets
if mouseclick()=1 or spacekey()=1
text 400,0, "shooting"
if bullets_until_reload_count# < bullets_until_reload#
if time_since_last_bullet_fired# < timer() - time_between_bullets#
bullet_id# = bullet_id# + 1
bullets_on_screen# = bullets_on_screen# + 1
if bullet_id# > max_bullets_on_screen#
bullet_id# = 0
endif
objid# = 100+bullet_id#
crap = bullet_id#
if bullet$(crap,1) = "fired"
rem search for next non-fired bullet
endif
bullet$(crap,0) = str$(timer())
bullet$(crap,1) = "fired"
bullet$(crap,3) = str$(object position x(4))
bullet$(crap,4) = str$(object position y(4))
bullet$(crap,5) = str$(object position z(4))
show object objid#
set object collision on objid#
rem position bullet on turret
position object objid#, limb position x(2,1), limb position y(2,1), limb position z(2,1)
rem point at turret extension
point object objid#, limb position x(2,3), limb position y(2,3), limb position z(2,3)
show particles objid#
position particles objid#, object position x(2),object position y(2),object position z(2)
rotate particles objid#, -90,object angle y(2),object angle z(2)
show light objid#
position light objid#, object position x(2),object position y(2),object position z(2)
rotate light objid#, -90,object angle y(2),object angle z(2)
remstart check between turret and mousepointer
for i=900 to 999
if intersect object (i, object position x(2),object position y(2),object position z(2), mouse3d_x#,mouse3d_y#,mouse3d_z#) > 0
text 10, 240, "HIT : "+str$(i)+" at : "+str$(intersect object (i, object position x(2),object position y(2),object position z(2), mouse3d_x#,mouse3d_y#,mouse3d_z#))
hide object i
endif
next i
remend
remstart check between turret and obj4 being extended turret outside of matrix
for i=900 to 999
if enemy$(i-900,1) = "alive"
if intersect object (i, object position x(2),object position y(2),object position z(2), object position x(4),object position y(4),object position z(4)) > 0
text 10, 240, "HIT : "+str$(i)+" at : "+str$(intersect object (i, object position x(2),object position y(2),object position z(2), object position x(4),object position y(4),object position z(4)))
hide object i
enemy$(i-900,1) = "dead"
enemy$(i-900,2) = str$(timer())
endif
endif
next i
remend
time_since_last_bullet_fired# = timer()
bullets_until_reload_count# = bullets_until_reload_count# + 1
endif
endif
endif
if mouseclick()=2 or mouseclick()=3
text 400,0, "reloading"
rem rightmouse button reload
bullets_until_reload_count# = 0
endif
if mouseclick()=4
text 400,0, "middle mouse button"
endif
rem groundheight under player
ground#=get ground height(1,posx#,posz#)+5
rem update player
if posx# >= 2000 then posx# = 2000
if posx# <= 0 then posx# = 0
if posz# >= 2000 then posz# = 2000
if posz# <= 0 then posz# = 0
position object 1,posx#,ground#+5,posz#
yrotate object 1,angle#
rem update turret
if controlkey() = 1
turret_lock = 1
else
turret_lock = 0
endif
position object 2,object position x(1),ground#+15,object position z(1)
if turret_lock = 0
point object 2, mouse3d_x#,ground#+15,mouse3d_z#
show object 3
endif
if turret_lock = 1
set object to object orientation 2, 1
hide object 3
endif
rem update lights -------------
rem player headlights
ROTATE LIGHT 1, object angle x(1)+15,object angle y(1),object angle z(1)
position LIGHT 1, limb position x(1,7), limb position y(1,7)+200, limb position z(1,7)
rem mouse light
ROTATE LIGHT 2, 90,0,0
position LIGHT 2, object position x(3),object position y(3)+200,object position z(3)
rem turret spot
ROTATE LIGHT 3, object angle x(2)+15,object angle y(2),object angle z(2)
position LIGHT 3, limb position x(2,2), limb position y(2,2)+200, limb position z(2,2)
rem player top light
position LIGHT 4, object position x(2),object position y(2)+100,object position z(2)
rem end lights ---------
rem update mousebox
border_mouse3d_x# = mouse3d_x#
border_mouse3d_y# = mouse3d_y#
border_mouse3d_z# = mouse3d_z#
if border_mouse3d_x# >= 2000 then border_mouse3d_x# = 2000
if border_mouse3d_x# <= 0 then border_mouse3d_x# = 0
if border_mouse3d_z# >= 2000 then border_mouse3d_z# = 2000
if border_mouse3d_z# <= 0 then border_mouse3d_z# = 0
position object 3, border_mouse3d_x#,border_mouse3d_y#,border_mouse3d_z#
circle mousex(),mousey(),2
rem pointer_border_mouse3d_x# = mouse3d_x#
rem pointer_border_mouse3d_y# = mouse3d_y#
rem pointer_border_mouse3d_z# = mouse3d_z#
rem if pointer_border_mouse3d_x# >= 2000 then pointer_border_mouse3d_x# = 2000
rem if pointer_border_mouse3d_x# <= 0 then pointer_border_mouse3d_x# = 0
rem if pointer_border_mouse3d_z# >= 2000 then pointer_border_mouse3d_z# = 2000
rem if pointer_border_mouse3d_z# <= 0 then pointer_border_mouse3d_z# = 0
rem position object 4, pointer_border_mouse3d_x#,pointer_border_mouse3d_y#,pointer_border_mouse3d_z#
position object 4,object position x(1),ground#+15,object position z(1)
point object 4, mouse3d_x#,ground#+15,mouse3d_z#
move object 4, 2000+50
if returnkey()=1
cam_switch = cam_switch + 1
endif
if cam_switch > 20 then cam_switch = 0
rem camera update
if cam_switch >= 10
player_cam$ = "pov"
else
player_cam$ = "main"
endif
if player_cam$ = "main"
cam_main = 0
cam_pov = 2
cam_turret = 3
cam_mouse = 4
cam_overview = 5
endif
if player_cam$ = "pov"
cam_main = 2
cam_pov = 0
cam_turret = 3
cam_mouse = 4
cam_overview = 5
endif
rem cam1
camposition# = mousez()
if camposition# < -240 then camposition# = -240
if camposition# = -240
new_cam1x# = 200
new_cam1y# = 100
new_cam1z# = 200
endif
if camposition# = -120
new_cam1x# = 200
new_cam1y# = 200
new_cam1z# = 200
endif
if camposition# = 0
new_cam1x# = 200
new_cam1y# = 400
new_cam1z# = 200
endif
if camposition# = 120
new_cam1x# = 200
new_cam1y# = 600
new_cam1z# = 200
endif
if camposition# = 240
new_cam1x# = 200
new_cam1y# = 800
new_cam1z# = 200
endif
if camposition# = 360
new_cam1x# = 200
new_cam1y# = 1000
new_cam1z# = 200
endif
if camposition# = 480
new_cam1x# = 200
new_cam1y# = 1200
new_cam1z# = 200
endif
if camposition# = 600
new_cam1x# = 200
new_cam1y# = 1400
new_cam1z# = 200
endif
if camposition# = 720
new_cam1x# = 1000
new_cam1y# = 100
new_cam1z# = 1000
endif
if camposition# = 840
new_cam1x# = 1000
new_cam1y# = 200
new_cam1z# = 1000
endif
if camposition# = 960
new_cam1x# = 1000
new_cam1y# = 400
new_cam1z# = 1000
endif
if camposition# = 1080
new_cam1x# = 1000
new_cam1y# = 600
new_cam1z# = 1000
endif
if camposition# = 1200
new_cam1x# = 1000
new_cam1y# = 800
new_cam1z# = 1000
endif
if camposition# = 1320
new_cam1x# = 1000
new_cam1y# = 1000
new_cam1z# = 1000
endif
if camposition# = 1480
new_cam1x# = 1000
new_cam1y# = 1200
new_cam1z# = 1000
endif
if camposition# > 1320
new_cam1x# = 1000
new_cam1y# = camposition#
new_cam1z# = 1000
endif
if camposition# > 2640
new_cam1x# = 1000
new_cam1y# = 2640
new_cam1z# = 1000
endif
position camera cam_main, new_cam1x#,new_cam1y#,new_cam1z#
POINT CAMERA cam_main, posx#,posy#,posz#
rem cam2
text 50, screen height()-100, "pov cam"
position camera cam_pov, object position x(1), object position y(1)+20, object position z(1)
SET CAMERA TO OBJECT ORIENTATION cam_pov, 1
' yrotate camera cam_pov,object angle y(1)
rem cam3
position camera cam_turret, posx#,posy#+ground#+40,posz#
point camera cam_turret, mouse3d_x#,mouse3d_y#+10,mouse3d_z#
text 200, screen height()-100, "turret cam"
rem cam4
position camera cam_mouse, mouse3d_x#,250,mouse3d_z#
POINT CAMERA cam_mouse, mouse3d_x#,mouse3d_y#+10,mouse3d_z#
text 500, screen height()-100, "overview cam"
rem cam5
position camera cam_overview, 1000,500,1000
POINT CAMERA cam_overview, posx#,posy#,posz#
text 350, screen height()-100, "mouse cam"
text 10, 0, "fps : "+STR$(SCREEN FPS())
text 10, 15, "max_bullets_on_screen: "+str$(bullets_on_screen#)+"/"+str$(max_bullets_on_screen#)
text 10, 30, "reload: "+str$(bullets_until_reload_count#)+"/"+str$(bullets_until_reload#)
text 10, 45, "nr_enemies_on_screen : "+str$(nr_enemies_on_screen)
text 10, 60, "nr_enemies_created :"+str$(nr_enemies_created)
text 10, 75, "nr_kills: "+str$(nr_kills#)
text 10, 90, "mousex: "+str$(mousex())
text 10, 105, "mousey: "+str$(mousey())
text 10, 120, "mousez: "+str$(mousez())
text 10, 135, "mouse3d_x: "+str$(mouse3d_x#)
text 10, 150, "mouse3d_y: "+str$(mouse3d_y#)
text 10, 165, "mouse3d_z: "+str$(mouse3d_z#)
text 10, 180, "player posx: "+str$(posx#)
text 10, 195, "player posy: "+str$(posy#)
text 10, 210, "player posz: "+str$(posz#)
text 10, 225, "timer: "+str$(timer())
text 10, 240, "bullet_speed: "+str$(bullet_speed#)
text 10, 255, "time_between_bullets: "+str$(time_between_bullets#)
text 10, 270, "player_cam: "+player_cam$
text 10, 285, "health: "+str$(player(4))
text 10, 300, " "
text 10, 315, " "
rem Update Screen
sync
loop
function distance_between_player_and_object(objid#)
rem player position
x1#=object position x(1)
z1#=object position z(1)
y1#=get ground height(1,x1#,z1#)
ay1#=object angle y(1)
rem current enemy position
x2#=object position x(objid#)
z2#=object position z(objid#)
y2#=get ground height(1,x2#,z2#)
ay2#=object angle y(objid#)
rem The distance forumula
distance#=sqrt( ((x2#-x1#)^2)+((y2#-y1#)^2)+((z2#-z1#)^2) )
endfunction distance#
function mmcoord(scrx#,scry#,matnum,r#,FOV#)
ax#=camera angle x()
ay#=camera angle y()
scrw#=screen width()
scrh#=screen height()
hmax# = r#*tan(FOV#/2)
mh# = (((scrh#/2-scry#)*2)/scrh#)*hmax#
wmax# = r#*scrw#/scrh#*tan(FOV#/2)
mw# = (((scrx#-scrw#/2)*2)/scrw#)*wmax#
cl# = r#*cos(ax#)
ch# = -r#*sin(ax#)
sl# = mh#*cos(90-ax#)
sh# = mh#*sin(90-ax#)
ox# = camera position x() + (cl#+sl#)*sin(ay#) + mw#*cos(ay#)
oy# = camera position y() + (ch#+sh#)
oz# = camera position z() + (cl#+sl#)*cos(ay#) - mw#*sin(ay#)
for i#=0 to 1 step (1.0/r#)
x# = camera position x() + (ox#-camera position x())*i#
y# = camera position y() + (oy#-camera position y())*i#
z# = camera position z() + (oz#-camera position z())*i#
if y#-get ground height(matnum,x#,z#)<=0
mouse3d_x#=x#
mouse3d_y#=y#
mouse3d_z#=z#
exitfunction
endif
next i#
endfunction