Okay so I'm just having a problem that I can't figure out lol, maybe one of you will be able to find it.
Basically I've begun writing a tower d game, and I'm beginning to get most of the basics down(projectiles, enemies, towers etc.) I've gotten to the point where I can make towers that *should* fire projectiles, but I can't get the thing to fire.
The code is set up to check through a list of 100 projectiles and find a unused one to fire. Then it checks to see if there is an enemy within the tower range(I KNOW this isn't the problem, I've checked and it always confirms that it is within range.) So if it finds an enemy within the tower range and there is a projectile open, it will tell the program that it needs to be spawned along with the appropriate data(Which tower to spawn at and which enemy to fire at.) Though I just cant seem to get it firing.
Here is the code(with comments.)
Rem Init Game
Sync on: Sync rate 60
Rem Init Variables
DIM TowerData(10,10) : `Properties/Data of player built towers [Type, ]
DIM EnemyData(10,10) : `Protpeties/Data of enemy characters [ State{0=Unspawned, 1=Killed, 2=Alive}, health ]
DIM LevelData(10,10) : `Properties/Data of the level [ ]
DIM ProjectileData(100,4) : `Properties/Data for in game projectiles [ State{0=Unused,1=To-Be-Spawned,2=Spawned}, Enemy Target, Spawn Tower,type]
TowerCount = 0 : `Amount of towers currently built by player
EnemyCount = 0 : `Amount of enemies in the level
Rem Make base projectiles(For instancing
Make object sphere 10,5
position object 10,0,0,1000000
REM ALPHA STUFF ( CLEAN UP )
make object cone 2000,10 : `Make a test enemy
position object 2000,100,0,0
EnemyCount = 1
EnemyData(1,1) = 2
EnemyData(1,2) = 100
make object cube 1000,10 : `Make a test Tower
TowerData(1,1) = 1
towercount = 1
`-------------------------------
` MAIN LOOP
`-------------------------------
DO
print Use_Projectile
set cursor 0,0
Gosub AI
Gosub Projectile_Handling
Gosub Enemy_Handling
if upkey()=1 then move object 2000,3
if downkey()=1 then move object 2000,-3
if leftkey()=1 then turn object left 2000,3
if rightkey()=1 then turn object right 2000,3
position camera object position x(2000),100,object position z(2000)
point camera object position x(2000),0,object position z(2000)
sync
LOOP
`-------------------------------
` SUBROUTINES
`-------------------------------
Enemy_Handling:
Rem Check enemy health
For n = 1 to EnemyCount
If EnemyData(n,2) < 1 then EnemyData(n,1) = 1
`delete object n+1999
EnemyCount = EnemyCount - 1
next n
Return
Projectile_Handling:
For n = 1 to 100
`Create projectiles waiting to be made
If ProjectileData(n,1) = 1
Instance Object 10,n+2999
position object n+2999,0,0,0
ProjectileData(n,1) = 2
endif
`Update already active projectiles and check for collision with target
If ProjectileData(n,1) = 2
point object n+2999,object position x(ProjectileData(n,2)+1999),object position y(ProjectileData(n,2)+1999),object position z(ProjectileData(n,2)+1999)
move object n+2999,2
If Object Collision(n+2999,ProjectileData(n,2)+1999) = 1 then EnemyData(n,2)=EnemyData(n,2)-10
endif
next n
Return
AI:
For h = 1 to TowerCount
rem make data
`Range Data
tower_range = object position x(h+999)+50
tower_range2 = object position z(h+999)-50
Select TowerData(h,1)
`Check for tower type 1
Case 1:
`Find an enemy in range of tower
For n = 1 to EnemyCount
`Find a projectile to use
For n = 1 to 50
if ProjectileData(n,1) = 0
Use_Projectile = n
exit
endif
next n
if Use_Projectile > 0
if object position x(n+1999)<tower_range and object position x(n+1999)>tower_range2 and object position z(n+1999)<tower_range and object position z(n+1999)>tower_range2
print "inrange"
ProjectileData(Use_Projectile,1) = 1 : `Set the state of the projectile(to-be-spawned)
ProjectileData(Use_Projectile,2) = n : `Set the target enemy
ProjectileData(Use_Projectile,3) = h : `Set the tower for the projectile to spawn from
ProjectileData(Use_Projectile,4) = 1 : `Set the type of projectile
Use_Projectile = 0
exit
endif
endif
next n
Endcase
`Check for tower type 2
` Case 2
Endselect
Next h
Return