Quote: "Well, you don't have to stick to my demo code."
Too late. I started with it as a base. I saw you used subroutines in it, so I followed suit. I typically only use functions with DBC when they are simple calls, as having to create arrays for every variable is a pain in my view. I can re-write the code to your specs, but I wanted you guys to take a look at it to see if this is something that will work or if it can be improved upon.
You will need the attached media added to the media that has already been provided in order to run it.
Notes: The aliens are not animated, they simply sit at idle and move. No collision. W and S keys are used to move ahead / backward instead of the arrow keys. Mouse is still used to look around. Code does not check if the monsters actually reach the waypoint, they just keep going.
` DBC Guard the Farm game
gosub _init
gosub _stars
gosub _load_objects
gosub _setup_ships
position camera 150,30,200
do
if timer() > place_ship_delay then gosub _place_ship
position light 1,camera position x(),camera position y()+20,camera position z()
scroll object texture 20,.00001,.00005
gosub _move_ships
for tt = 1 to 10 : gosub _move_NPCs : next tt
gosub _move_camera
gosub _debug
sync
loop
end
`----------------------------------------------------------------
_init:
set display mode 800,600,32
sync on
sync rate 35
autocam off
hide mouse
next_image = 1 : next_object = 1 : total_ships = 5 : total_monsters = 50
current_monster = 0
place_ship_delay = timer() + rnd(1000) + 1000
rem lighting
fog on
fog color rgb(64,64,128)
fog distance 1500
make light 1
set point light 1,camera position x(),camera position y(),camera position z()
color light 1,rgb(255,255,255)
set light range 1,1000
color light 0,rgb(255,255,255)
set directional light 0,1,-.5,-1
`color ambient light 0
color backdrop 0
return
`----------------------------------------------------------------
_load_objects:
farm = next_object
inc next_object
farm_lm = next_object
inc next_object
load object "farm.x",farm
load object "farm_lmap.x",farm_lm
ghost object on farm_lm,1
set object ambient farm,rgb(127,127,127)
set object diffuse farm,rgb(255,255,255)
set object ambient farm_lm,rgb(127,127,127)
set object diffuse farm_lm,rgb(255,255,255)
`SET OBJECT Object Number, Wireframe, Transparency, Cull, Filter, Light, Fog,ambient
set object farm,1,1,0,1,1,1
set object farm_lm,1,1,0,1,1,0
` NPCs
dim NPC(total_monsters,10)
for j = 1 to total_monsters
NPC(j,4) = next_object
inc next_object
load object "Alien Mutant\H-Alien Mutant-Idle.x",NPC(j,4)
yrotate object NPC(j,4),180.0
fix object pivot NPC(j,4)
scale object NPC(j,4),1500.0,1500.0,1500.0
hide object NPC(j,4)
NPC(j,3) = 0 : ` status = inactive
next j
return
`----------------------------------------------------------------
_move_camera:
move camera (keystate(17)- keystate(31)) * 5
position camera camera position x(),30,camera position z()
yang# = wrapvalue(camera angle y() + mousemovex() )
xang# = xang# + mousemovey()
if xang# < -80 then xang# = -80
if xang# > 75 then xang# = 75
rotate camera wrapvalue(xang#),yang#,0
return
`----------------------------------------------------------------
_move_ships:
for j = 1 to total_ships
if ship(j,3) = 2 : ` descending
y# = object position y(ship(j,4) )
if y# > 75.0
dec y#,1.0 : ` move ship downward
if y# > 150.0 and y# < 300.0 then dec y#,2.0
if y# > 300.0 and y# < 500.0 then dec y#,4.0
if y# > 500.0 and y# < 1000.0 then dec y#,8.0
if y# >= 1000.0 then dec y#,12.0
position object ship(j,4),object position x(ship(j,4) ),y#,object position z(ship(j,4) )
else
` ship is hovering above ground - change status
ship(j,3) = 3 : ` hovering, waiting for monsters to appear
ship(j,7) = timer() + 1500 : ` delay for how long the ship stays there - 1.5 seconds
` activate beam
if object exist(200 + j) = 0
make object cylinder 200 + j,40 : color object 200 + j,rgb(0,255,0)
scale object 200 + j,100.0,200.0,100.0 : ghost object on 200 + j
endif
position object 200 + j ,object position x(ship(j,4) ),y# - 30.0,object position z(ship(j,4) )
show object 200 + j
monsters_left = 0
for i = 1 to 50
if NPC(i,3) = 0 then inc monsters_left
next i
if monsters_left > 0
` place 2 - 6 monsters there
cm = 0 : avbl = 0
` get beam location
x# = object position x(200 + j) - 10.0 : z# = object position z(200 + j)
monsters_to_place = rnd(4) + 2
if monsters_to_place > monsters_left then monsters_to_place = monsters_left
for k = 1 to monsters_to_place
` check to see if one is available
avbl = 0
repeat
inc cm
if avbl = 0 and NPC(cm,3) = 0 then avbl = cm
until avbl > 0 or cm >= total_monsters
if avbl > 0
NPC(avbl,3) = 1 : ` status = active
if k = 4 then inc z#,10.0 : x# = object position x(200 + j) - 40.0
position object NPC(avbl,4),x# + (k * 10),7.0,z#
show object NPC(avbl,4)
endif
next k
endif
endif
endif
if ship(j,3) = 3 : ` hovering
if timer() > ship(j,7)
ship(j,3) = 4 : ` change status to ascending
hide object 200 + j : ` hide the tractor beam
else
ya# = object angle y(200 + j)
ya# = wrapvalue(ya# + 5.0)
yrotate object 200 + j,ya#
endif
endif
if ship(j,3) = 4 : ` ascending
y# = object position y(ship(j,4) )
if y# < 300.0
inc y#,2.0 : ` move ship upward
endif
if y# >= 300.0 and y# < 500.0 then inc y#, 4.0
if y# >= 500.0 and y# < 1000.0 then inc y#,8.0
if y# >= 1000.0 then inc y#,12.0
position object ship(j,4),object position x(ship(j,4) ),y#,object position z(ship(j,4) )
if y# > 2000.0 : ` hide ship and change status to available
ship(j,3) = 0 : hide object ship(j,4)
endif
endif
next j
return
`----------------------------------------------------------------
_move_NPCs:
inc current_monster
if current_monster > total_monsters then current_monster = 1
if NPC(current_monster,3) = 1
` just landed - select rotation direction to turn toward waypoint
xa# = object angle x(NPC(current_monster,4) )
ya# = object angle y(NPC(current_monster,4) )
za# = object angle z(NPC(current_monster,4) )
point object NPC(current_monster,4),153.0,object position y(NPC(current_monster,4) ),-159
newY# = object angle y(NPC(current_monster,4) )
NPC(current_monster,6) = newY# : ` target angle
NPC(current_monster,5) = 4 : ` default is clockwise
if newY# < ya# then NPC(current_monster,5) = 8 : ` counter - clockwise
rotate object NPC(current_monster,4),xa#,ya#,za#
NPC(current_monster,3) = 2 : ` status = rotating to correct angle so it points toward the waypoint
endif
if NPC(current_monster,3) = 2 : ` rotating to correct angle
ata# = 7.0
if NPC(current_monster,5) = 8 then ata# = -7.0
ya# = object angle y(NPC(current_monster,4) )
ya# = wrapvalue(ya# + ata#)
if abs(ya# - NPC(current_monster,6) ) < 10.0
` monster has rotated enough - change status to walking toward waypoint
NPC(current_monster,3) = 3 : ` walking toward waypoint
else
yrotate object NPC(current_monster,4),ya#
endif
endif
if NPC(current_monster,3) = 3 : ` walking toward waypoint
move object NPC(current_monster,4),1.0
` check to see if it has arrived
endif
` 153, -159
return
`----------------------------------------------------------------
_stars:
bmp=1
while bitmap exist(bmp)
inc bmp
endwhile
create bitmap bmp,512,512
stars = 300
cls 32
for n=1 to 200
g=128+rnd(127)
ink rgb(g,g,g),0
dot rnd(512),rnd(512)
ink rgb(0,0,128+rnd(127)),0
dot rnd(512),rnd(512)
ink rgb(128+rnd(127),0,0),0
dot rnd(512),rnd(512)
next n
get image stars,0,0,512,512,1
sync
delete bitmap bmp
set current bitmap 0
rem put a star map out there
make object sphere 300,-20000
texture object 300,stars
ghost object on 300
scale object texture 300,4,4
make object sphere 301,-18000
texture object 301,stars
scale object texture 301,3,3
ghost object on 301
set object 300,1,1,1,1,1,0
set object 301,1,1,1,1,1,0
set camera range 1,20000
color backdrop 0
return
`----------------------------------------------------------------
_setup_ships:
rem store ship x# and z# placement data in an array
dim coord(17,2)
restore _ss_coordinates
for j = 1 to 17
read coord(j,1),coord(j,2)
next j
temp = next_image
inc next_image
load image "SSMap.png",temp
dim ship(total_ships,7)
for j = 1 to total_ships
ship(j,4) = next_object
inc next_object
ship(j,5) = 1 : rem type of ship, in case we add more kinds of ships in the future
load object "SpaceShip.x",ship(j,4) : ` export from MS3D at 12.0
texture object ship(j,4),temp
hide object ship(j,4)
ship(j,3) = 0 : ` status = inactive
ship(j,6) = 0 : ` location
rem ship(j,7) is used for a timer to control how long the ship remains while the monsters unload
next j
return
`----------------------------------------------------------------
_place_ship:
rem first see if we even need to send a ship
monsters_left = 0
for i = 1 to 50
if NPC(i,3) = 0 then inc monsters_left
next i
if monsters_left = 0 then return : ` all of the monsters are in use already - no need to send a ship
rem see if we have a ship available
avbl = 0
for j = 1 to total_ships
if avbl = 0 and ship(j,3) = 0 then avbl = j
next j
if avbl = 0 then place_ship_delay = timer() + rnd(5000) + 3000 : return : ` no ships available
` ship is available - place it randomly
` make sure you don't place it at the same place another one is
repeat
okay = 1
location = rnd(16) + 1
` check against current ships
for j = 1 to total_ships
if ship(j,3) > 0 and j <> avbl
if ship(j,6) = location then okay = 0
endif
next j
until okay = 1
` store the ship's coordinates
ship(avbl,1) = coord(location,1)
ship(avbl,2) = coord(location,2)
ship(avbl,3) = 2 : ` ship status is descending to earth
ship(avbl,6) = location
position object ship(avbl,4),ship(avbl,1),rnd(500) + 500,ship(avbl,2)
show object ship(avbl,4)
place_ship_delay = timer() + rnd(5000) + 2000 : ` have a 2 - 7 second delay between ships
return
`----------------------------------------------------------------
_debug:
text 10,10,"FPS: " + str$(screen fps() )
` cx# = camera position x()
` cz# = camera position z()
` text 10,100,"cx: " + str$(cx#)
` text 10,120,"cz: " + str$(cz#)
` text 10,150,"scancode: " + str$( scancode() )
return
`----------------------------------------------------------------
_ss_coordinates:
` x, y coordinates where to place the monster's ships
data -122,819,-416,855,-875,833,-607,398,-885,473,-897,-170,-722,-433,-840,-728
data -698,-929,-495,-805,-239,-829,10,-833,189,-909,376,-737,599,-900,767,-852,900,-597
It is a little rough, but I can always tidy it up later.
EDIT: Thanks BN2 for the alien monster link. I knew I had seen that somewhere before.
So many games to code.......so little time.