`load the images for the title screen
`gosub loadimages
`create a global variable for the number of citizens to create
global citnum
`create a global variable for the number of allies to create
global allynum
`create a global variable for the number of zombies to create
global zombienum
`create a global variable for the number of trees to create
global treenum
`set the default values for the variables
allynum=2
zombienum=100
treenum=100
citnum=50
`Creates the types for the units, the arrays are created in the "setup" subroutine.
`the vector will be used for the target position
type vector
x as integer
z as integer
endtype
`creates the type for each ally and enemy
type aiunit
`the target is used to see which object/ally/zombie the ally/zombie is attacking. if it is not attacking, it equals zero.
target as integer
`the position of the target area. The target is not the object the ally/zombie is attacking, but the position the player
`tells it to move towards. obsolete with citizens and zombies.
targetpos as vector
`the amount of health the zombie/ally/citizen has.
health as float
`the speed of the ally/zombie/citizen
speed as float
`the damage of the ally/zombie, damage of the citizen is zero
damage as float
`this tells if the ally/zombie/citizen has reached the edge of the map
reachrange as boolean
`this variable is only used if the ally is selected or not. It is not used for the zombies or citizens.
selected as boolean
endtype
`Goes to the intro screen
`goto introscreen
goto game
`=========================================================================================================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`==================================--------------<<<<<<<Main Loop>>>>>>>--------------====================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`=========================================================================================================================
game:
`sets up the game
gosub setup
do
`camera subroutine
gosub camera
`targeting subroutine
gosub targeting
`Allied AI subroutine
gosub allyAI
`Zombie AI subroutine
gosub zombieAI
`citizen AI subroutine
`gosub citizenAI
sync
loop
return
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`================================--------------<<<<<<<Camera Movement>>>>>>>--------------================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
camera:
if rightkey()=1
position camera camera position x()+0.5,camera position y(), camera position z()
endif
if leftkey()=1
position camera camera position x()-0.5,camera position y(), camera position z()
endif
if upkey()=1
position camera camera position x(),camera position y(), camera position z()+0.5
endif
if downkey()=1
position camera camera position x(),camera position y(), camera position z()-0.5
endif
rem sets up camera position variables
camera_x=camera position x()
camera_y=camera position y()
camera_z=camera position z()
return
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`====================================--------------<<<<<<<Ally AI>>>>>>>--------------====================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
allyAI:
`ally attacking
for b=1 to allynum
`sets the variable C,which is the object number of the allies
c=b+zombienum
`only bothers to do this if the ally exists
if object exist (c)
for a=1 to zombienum
if object exist (a)
null = make vector3(1000)
set vector3 1000, object position x(c)-object position x(a), object position y(c)-object position y(a), object position z(c)- object position z(a)
distance#=length vector3(1000)
null = delete vector3(1000)
`zombie ai
if distance#<40
if characterinfo(a).target=0
characterinfo(a).target=c
endif
endif
if distance#<1
if characterinfo(a).target=c
dec characterinfo(c).health, characterinfo(a).damage
endif
endif
z=characterinfo(a).target
if z>0
if object exist(z)=0
characterinfo(a).target=0
endif
endif
if characterinfo(a).target=c
if object exist(z)
characterinfo(a).speed=0.04
point object a, object position x(c), 0.5, object position z(c)
else
characterinfo(a).speed=0.02
endif
endif
`lower ally's health by the zombie damage amount if the zombie is too close
` Checks to see if the zombie is close enough
if distance#<23
`checks to see if the ally isn't already targeting another zombie
if characterinfo(c).target=0
`changes the zombie the ally is targeting to the zombie on the current *for-next* loop
characterinfo(c).target=a
endif
endif
`if the zombie the ally is targeting is equal to the zombie on the current *for-next* loop...
if characterinfo(c).target=a
`characterinfo(c).speed=0
point object c, object position x(a), 0.5, object position z(a)
`rolls the dice to see whether the ally will hit or miss with his bullet...
abc=rnd (10)
`if you roll snake eyes...
if abc=2
`subtracts zombie health
dec characterinfo(a).health, characterinfo(c).damage
ink RGB(255,255,0),rgb(0,0,0)
line object screen x(c),object screen y(c), object screen x(a), object screen y(a)
endif
endif
if distance#>23
if characterinfo(c).target=a
characterinfo(c).target=0
characterinfo(c).speed=0.05
endif
endif
endif
if characterinfo(c).target=a
if object exist(a)=0
characterinfo(b+zombienum).target=0
characterinfo(b+zombienum).speed=0.05
endif
endif
`if characterinfo(c).target=0
next a
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
if characterinfo(b+zombienum).targetpos.x>0
if characterinfo(b+zombienum).targetpos.z>0
set vector3 1, characterinfo(b+zombienum).targetpos.x-object position x(b+zombienum), 0.5,characterinfo(b+zombienum).targetpos.z-object position z(b+zombienum)
distance2#= length vector3(1)
if distance2#>=1
normalize vector3 1,1
set vector3 2, limb position x(b+zombienum, 1) - object position x(b+zombienum), 0.5, limb position z(b+zombienum, 1) - object position z(b+zombienum)
normalize vector3 2, 2
AllyToTargetA# = acos(dot product vector3(1, 2))
set vector3 3, 0, 1, 0
cross product vector3 3, 2, 3
angle2# = acos(dot product vector3(1, 3))
if AllyToTargetA# > 0.1
if angle2# <> 0
if angle2# >= 90
turn object right b+zombienum, 1
else
turn object left b+zombienum, 1
endif
endif
endif
if characterinfo(b+zombienum).target =0
move object b+zombienum, characterinfo(b+zombienum).speed
endif
endif
endif
endif
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
`kill ally
if characterinfo(b+zombienum).health<=0
delete object b+zombienum
endif
endif
next b
return
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`==================================--------------<<<<<<<Zombie AI>>>>>>>--------------====================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
zombieAI:
for a=1 to zombienum
if object exist(a)
`random zombie turning, also gives them their staggering "gait"... if thats what you wanna call cubes sliding...
turn object right a, rnd(10)/5
turn object left a, rnd(10)/5
`controls the zombies movement
move object a, characterinfo(a).speed
if object exist (a)
if object position x(a)<0
position object a, 0, 0.5, object position z(a)
characterinfo(a).reachrange=55
endif
if object position x(a)>200
position object a, 200, 0.5, object position z(a)
characterinfo(a).reachrange=55
endif
if object position z(a)<0
position object a, object position x(a), 0.5, 0
characterinfo(a).reachrange=55
endif
if object position z(a)>200
position object a, object position x(a), 0.5,200
characterinfo(a).reachrange=55
endif
endif
if characterinfo(a).reachrange>=1
turn object left a, 2
dec characterinfo(a).reachrange
endif
`kill zombie
if characterinfo(a).health<=0
delete object a
endif
endif
next a
return
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
`==================================--------------<<<<<<<Targeting>>>>>>>--------------====================================
`=========================================-----------<<<<<<<=>>>>>>>>----------===========================================
targeting:
`if you click, you target an enemy
if mouseclick()=1
objnum=pick object(mousex(), mousey(), 1, 1000)
if objnum>allynum+zombienum
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
null = make vector3(4)
set vector3 1, 0, -1, 0
pick screen mousex(), mousey(), 1
x# = get pick vector x()
y# = get pick vector y()
z# = get pick vector z()
set vector3 2, x#, y#, z#
angle# = acos(dot product vector3(2, 1))
cos_angle# = cos(angle#)
hypo_length# = camera_y / cos_angle#
normalize vector3 2, 2
scale vector3 2, 2, hypo_length#
set vector3 1, camera_x, camera_y, camera_z
add vector3 4, 1, 2
num=1
num2=0
for b=1 to allynum
if characterinfo(b+zombienum).selected=1
if gh=0
characterinfo(c).speed=0.05
characterinfo(b+zombienum).targetpos.z=z vector3(4)+3*num
characterinfo(b+zombienum).targetpos.x=x vector3(4)+3*num2
inc num
if num>4
num=1
inc num2
endif
endif
endif
next b
if gh=0
position object allynum+zombienum+2, x vector3(4),0,z vector3(4)
point object allynum+zombienum+2,camera position x(0), 0, camera position z(0)
null = make vector2(1)
null = make vector2(4)
null = make vector2(5)
set vector2 1,object position x(allynum+zombienum+2),object position z(allynum+zombienum+2)
set vector2 4,camera position x(0), camera position z(0)
subtract vector2 5, 4,1
j=length vector2(5)
null = delete vector3(1)
null = delete vector3(4)
null = delete vector2(5)
gh=1
endif
endif
endif
if gh=1
if rightkey()=1
turn object left allynum+zombienum+2, 0.5
move=1
endif
if leftkey()=1
turn object right allynum+zombienum+2,0.5
move=1
endif
if move=1
null = make vector2(1)
null = make vector2(2)
null = make vector2(3)
null = make vector2(4)
null = make vector2(5)
null = make vector2(6)
null = make vector2(7)
set vector2 1,object position x(allynum+zombienum+2),object position z(allynum+zombienum+2)
set vector2 2,limb position x(allynum+zombienum+2,1), limb position z(allynum+zombienum+2,1)
set vector2 4,camera position x(0), camera position z(0)
subtract vector2 3,2,1
normalize vector2 3,3
scale vector2 6,3,j
add vector2 7,6,1
position camera 0,x vector2(7),30,y vector2(7)
endif
endif
null = delete vector2(1)
null = delete vector2(2)
null = delete vector2(3)
null = delete vector2(4)
null = delete vector2(5)
null = delete vector2(6)
null = delete vector2(7)
if mouseclick()=0
gh=0
move=0
endif
for b=1 to allynum
if object exist(b+zombienum)
if objnum>0
if objnum=b+zombienum
if characterinfo(b+zombienum).selected=0
characterinfo(b+zombienum).selected=1
endif
endif
endif
if characterinfo(b+zombienum).selected=1
ink rgb(0,0,0),rgb(0,256,0)
circle object screen x(b+zombienum), object screen y(b+zombienum), 5
if mouseclick()=>2
characterinfo(b+zombienum).selected=0
endif
endif
endif
next b
return
return
`======================================================================================================================
`======================================================================================================================
`======================================================================================================================
`===============================================Sets up the game (level, objects, etc.)================================
`======================================================================================================================
`======================================================================================================================
`======================================================================================================================
setup:
gosub grassmaker
gosub grassmaker2
make static collision box 0,0,0,200,0,200
dim characterinfo(allynum+zombienum) as aiunit
`create the ground
make object plain allynum+zombienum+1, 200,200
rotate object allynum+zombienum+1, 90,0,0
position object allynum+zombienum+1, 100,0,100
texture object allynum+zombienum+1,12
make object box 1, 0.2,0.2, 1
make mesh from object 1, 1
delete object 1
make object cone 1,6
make mesh from object 2,1
delete object 1
make object plain allynum+zombienum+3, 600,600
rotate object allynum+zombienum+3,90,0,0
position object allynum+zombienum+3, 100, -0.1,100
texture object allynum+zombienum+3,13
make object sphere allynum+zombienum+2,1
add limb allynum+zombienum+2,1,1
offset limb allynum+zombienum+2,1,0,0,1
hide object allynum+zombienum+2
hide limb allynum+zombienum+2,1
`create allies
for b=1 to allynum
`make allies (b+zombienum because the first X many objects are the zombies)
make object cube b+zombienum, 1
color object b+zombienum, RGB(256,256,256)
add limb b+zombienum, 1, 1
offset limb b+zombienum, 1, 0, 0, 1
hide limb b+zombienum, 1
add limb b+zombienum,2,1
offset limb b+zombienum,2,0.5,0,0.5
color limb b+zombienum,2, RGB(0,0,0)
`position allies
pox=rnd(40)+160
poz=rnd(40)+80
position object b+zombienum, pox,0.5,poz
`set health variable for all allies
characterinfo(b+zombienum).health=100
characterinfo(b+zombienum).damage=5
characterinfo(b+zombienum).speed=0.05
next b
for c=1 to treenum
make object box c+allynum+zombienum+3,0.8,2,0.8
add limb c+allynum+zombienum+3,1, 2
offset limb c+allynum+zombienum+3,1,0,4.7,0
position object c+allynum+zombienum+3, rnd(600)-200,1,rnd(600)-200
color object c+allynum+zombienum+3, rgb(0,0,0)
texture limb c+allynum+zombienum+3,1,13
next c
`create zombies
for a=1 to zombienum
`create cube shaped zombies
make object cube a, 1
color object a, RGB(0,100,0)
add limb a, 1, 1
offset limb a, 1, 0, 0, 1
hide limb a, 1
`position them
pox=rnd(20)
poz=rnd(200)
position object a, pox, 0.5, poz
`set their health variable
characterinfo(a).health=100
characterinfo(a).damage=1
characterinfo(a).speed=0.02
`points each zombie at a random ally
num=rnd(allynum)
if num=0
num=1
endif
point object a,object position x(num+zombienum),0.5,object position z(num+zombienum)
next a
position camera 0,30,0
point camera 0,10,30
color backdrop 0, rgb(1,1,1)
set ambient light 20
return
grassmaker:
create bitmap 1, 33, 33
set current bitmap 1
for x=1 to 33
for y=1 to 33
dot x,y,RGB(0,rnd(60)+130,0)
next x
next y
get image 12,1,1,33,33
set current bitmap 0
return
grassmaker2:
create bitmap 2, 200, 200
set current bitmap 2
for x=1 to 200
for y=1 to 200
dot x,y,RGB(0,rnd(60)+70,0)
next x
next y
get image 13,2,1,200,200
set current bitmap 0
return
I really didn't change much about the game. I'm combining the Ally and zombie AI, it's alot faster.
What i'm going to try to do now is to start groupind the zombies, to enhance the speed. Right now, you can get about 33 fps with 200 zombies and 10 allies. What i'm going to try to do is make groups of 10 zombies, that will stay within a certain range of eachother. For these ten zombies, the average of their positions will be taken,and THEN compared to the allied units. This will, in theory, mean that you could have the same amount of tests run for 2,000 zombies, as for the 200 right now. If there is a loss in gameplay, meaning, if it's not fun if the zombies stay grouped together like that, then maybe groups of five, three, or two.
parrot