Can anyone tell me whats wrong with this code
Function InvaderBomb(InvaderData)
If Object Exist(Alien(0,0).Bomb) = 0
Make Object Sphere Alien(0,0).Bomb,10
Repeat
x = RND(10)
z = RND(4)
Until Alien(0,0).Dead = 1
Bomb.x = Object Position x(Alien(x,z).ID)
Bomb.y = Object Position y(Alien(x,z).ID)
Bomb.z = Object Position z(Alien(x,z).ID)
Endif
If Object Collision(Ground.ID,Alien(0,0).Bomb)
Repeat
x = RND(10)
z = RND(4)
Until Alien(0,0).Dead = 1
Endif
Position Object Alien(0,0).Bomb,Bomb.x,Bomb.y,Bomb.z
If Object Exist(Alien(0,0).Bomb) = 1
Inc Bomb.z,2
Endif
If Object Collision (BarrelMedium.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
If Object Collision (BarrelLarge.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
If Object Collision (CannonStand.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
EndFunction
Its only the bomb code of the invaders project, you see as soon as I compile the code the repeat|until keeps repeating and wont start the game until the condition from which I have set is false. I had a working version once although strange it contradicted itself but somehow worked and now I had to strip away this code and fix it properly because the old code kept conflicting with the second level I was trying to create :/
Here is the rest of the project. Ps it is not the final build so there might be repeats of code.
Space Invaders 1.1
Rem ***** Main Source File *****
Gosub DataSetup
Gosub Space
VarsSetup()
MakeObjects0(LightData)
MakeObjects1(PlayerData)
MakeObjects2(InvaderData)
MakeObjects3(CameraData)
MakeObjects4(BoundaryData)
ResetLevel1()
Do
MakeObjects5(InvaderData)
PlayerControl()
ScoreText(ScoreData)
InvaderMove(InvaderData)
InvaderBomb(InvaderData)
MakeBullet(BulletData)
ShootBullet(BulletData)
GameWinLose(GameData)
Levels()
Sync
Loop
Functions
Rem ***** Included Source File *****
Function VarsSetup()
Version.char = " Invader Engine V2.0 |"
Lives.char = " Lives ? **** Off! |"
Score.char = "Score : |"
Score.Total = 0
Alien(x,z).Direct = 0
Alien1(x,z).Direct = 0
Bullet.ID = 4000
Alien(x,z).Dead = 0
Alien1(x,z).Dead = 0
Alien(0,0).Bomb = 2000
Game.Trigger = 0
Alien.NextWave = 0
Alien.NextLvl = 0
EndFunction
Function MakeObjects0(LightData)
Light.ID = 1
Make Light Light.ID
Position Light Light.ID,0,0,-200
Color Light Light.ID,RGB(0,0,255)
Point Light Light.ID,0,0,150
EndFunction
Function MakeObjects1(PlayerData)
CannonStand.ID = 1
BarrelLarge.ID = 2
BarrelMedium.ID = 3
Make Object Box CannonStand.ID,55,45,8
Make Object Box BarrelLarge.ID,35,25,16
Make Object BOx BarrelMedium.ID,15,55,8
Rotate Object BarrelMedium.ID,95,0,0
Rotate Object BarrelLarge.ID,95,0,0
Position Object BarrelLarge.ID,0,0,260
Position Object BarrelMedium.ID,0,0,230
Position Object CannonStand.ID,0,0,280
CannonStand.x = Object Position x(CannonStand.ID)
CannonStand.y = Object Position y(CannonStand.ID)
CannonStand.z = Object Position z(CannonStand.ID)
BarrelMedium.x = Object Position x(BarrelMedium.ID)
BarrelMedium.y = Object Position y(BarrelMedium.ID)
BarrelMedium.z = Object Position z(BarrelMedium.ID)
BarrelLarge.x = Object Position x(BarrelLarge.ID)
BarrelLarge.y = Object Position y(BarrelLarge.ID)
BarrelLarge.z = Object Position z(BarrelLarge.ID)
Set Shadow Shading On CannonStand.ID
Set Shadow Shading On BarrelLarge.ID
Set Shadow Shading On BarrelMedium.ID
Color Object CannonStand.ID,RGB(0,0,255)
Color Object BarrelLarge.ID,RGB(0,0,255)
Color Object BarrelMedium.ID,RGB(0,0,255)
EndFunction
Function MakeObjects2(InvaderData)
For x = 0 To 10
For z = 0 To 4
Alien(x,z).ID = 5
Repeat
Inc Alien(x,z).ID,1
Alien(x,z).Dead = 0
Until Object Exist(Alien(x,z).ID) = 0
Ship = Alien(x,z).ID
Make Object Box Ship,20,50,15
Position Object Ship,175-(x*40),CannonStand.y,0-(z*30)
Alien(x,z).x = Object Position x(Alien(x,z).ID)
Alien(x,z).y = Object Position y(Alien(x,z).ID)
Alien(x,z).z = Object Position z(Alien(x,z).ID)
Select z
Case 0
Color Object Ship,RGB(255,50,50)
EndCase
Case 1
Color Object Ship,RGB(50,255,25)
EndCase
Case 2
Color Object Ship,RGB(100,125,30)
EndCase
Case 3
Color Object Ship,RGB(125,75,150)
EndCase
Case 4
Color Object Ship,RGB(200,200,100)
EndCase
EndSelect
Next z
Next x
EndFunction
Function MakeObjects5(InvaderData)
If Alien.NextWave = 55 And Alien.NextLvl = 0
For x = 0 To 10
For z = 0 To 4
Alien1(x,z).ID = 105
Repeat
Inc Alien1(x,z).ID,1
Alien1(x,z).Dead = 0
Until Object Exist(Alien1(x,z).ID ) = 0
Ship1 = Alien1(x,z).ID
Make Object Sphere Ship1,30
Position Object Ship1,175-(x*40),CannonStand.y,0-(z*30)
Alien1(x,z).x = Object Position x(Alien1(x,z).ID)
Alien1(x,z).y = Object Position y(Alien1(x,z).ID)
Alien1(x,z).z = Object Position z(Alien1(x,z).ID)
Select z
Case 0
Color Object Ship1,RGB(255,50,99)
EndCase
Case 1
Color Object Ship1,RGB(0,255,85)
EndCase
Case 2
Color Object Ship1,RGB(50,50,150)
EndCase
Case 3
Color Object Ship1,RGB(150,150,150)
EndCase
Case 4
Color Object Ship1,RGB(0,0,255,)
EndCase
EndSelect
Next z
Next x
Alien.NextLvl = 1
Endif
EndFunction
Function MakeObjects3(CameraData)
Camera.ID = 1
Make Camera Camera.ID
Position Camera Camera.ID,0,-750,-150
Point Camera Camera.ID,0,0,0
Camera.x = Camera Position x(Camera.ID)
Camera.y = Camera Position y(Camera.ID)
Camera.z = Camera Position z(Camera.ID)
EndFunction
Function MakeObjects4(BoundaryData)
Ground.ID = 4
Make Object Plain Ground.ID,1500,200,30
Position Object Ground.ID,0,0,300
Set Shadow Shading On Ground.ID
Color Object Ground.ID,RGB(0,125,0)
Background.ID = 5
Make Object Plain Background.ID,2500,4000,0
Position Object Background.ID,0,0,-650
Rotate Object Background.ID,65,0,0
Color Object Background.ID,RGB(0,0,0)
Set Shadow Shading On Background.ID
LeftWall.ID = 200
Make Object Box LeftWall.ID,10,500,40
Position Object LeftWall.ID,-400,0,40
Rotate Object LeftWall.ID,270,0,0
RightWall.ID = 201
Make Object Box RightWall.ID,10,500,40
Position Object RightWall.ID,400,0,40
Rotate Object RightWall.ID,270,0,0
TopWall.ID = 202
Make Object Box TopWall.ID,1000,10,40
Position Object TopWall.ID,0,0,-275
EndFunction
Function MakeBullet(BulletData)
If SpaceKey() = 1
If Object Exist(Bullet.ID) = 0
Bullet.ID = Bullet.ID
Make Object Sphere Bullet.ID,10
Color Object Bullet.ID,RGB(0,0,255)
Position Object Bullet.ID,0,0,BarrelLarge.z
Bullet.x = Object Position x(BarrelLarge.ID)
Bullet.y = Object Position y(BarrelLarge.ID)
Bullet.z = Object Position z(BarrelLarge.ID)
ShootBullet(BulletData)
Endif
Endif
EndFunction
Function ShootBullet(BulletData)
If Object Exist(Bullet.ID) = 1
Dec Bullet.z,5
Position Object Bullet.ID,Bullet.x,Bullet.y,Bullet.z
If Object Collision(Bullet.ID,TopWall.ID) = 1
Delete Object Bullet.ID
Endif
Endif
For x = 0 To 10
For z = 0 To 4
If Alien(x,z).Dead = 0
If Object Exist(Bullet.ID) = 1
If Object Collision(Bullet.ID,Alien(x,z).ID) = 1
Hide Object Alien(x,z).ID
Alien(x,z).Dead = 1
Delete Object Bullet.ID
Inc Score.Total,25
Inc Alien.NextWave,1
Endif
Endif
Endif
Next z
Next x
EndFunction
Function PlayerControl()
If LeftKey() = 1
Dec BarrelLarge.x,5
Dec BarrelMedium.x,5
Dec CannonStand.x,5
Endif
If RightKey() = 1
Inc BarrelLarge.x,5
Inc BarrelMedium.x,5
Inc CannonStand.x,5
Endif
If Object Collision(BarrelMedium.ID,RightWall.ID) = 1
Dec BarrelLarge.x,10
Dec BarrelMedium.x,10
Dec CannonStand.x,10
Endif
If Object Collision(BarrelMedium.ID,LeftWall.ID) = 1
Inc BarrelLarge.x,10
Inc BarrelMedium.x,10
Inc CannonStand.x,10
Endif
Position Object BarrelLarge.ID,BarrelLarge.x,BarrelLarge.y,BarrelLarge.z
Position Object BarrelMedium.ID,BarrelMedium.x,BarrelMedium.y,BarrelMedium.z
Position Object CannonStand.ID,CannonStand.x,CannonStand.y,CannonStand.z
EndFunction
Function ScoreText(ScoreData)
Ink RGB(255,0,0),RGB(255,0,0)
Text 0,0,Version.char
Text 170,0,Lives.char
Text 320,0,Score.char + str$(Score.Total)
Text 450,0, " Aliens dead : " + Str$(Alien.NextWave)
EndFunction
Function InvaderMove(InvaderData)
For x = 0 To 10
For z = 0 To 4
If Alien(x,z).Direct = 1
Inc Alien(x,z).x
Endif
If Alien(x,z).Direct = 0
Dec Alien(x,z).x
Endif
If Object Collision(Alien(x,z).ID,LeftWall.ID) = 1
Alien(x,z).z = (Alien(x,z).z + 10)
Alien(x,z).Direct = 1
Endif
If Object Collision(Alien(x,z).ID,RightWall.ID) = 1
Alien(x,z).z = (Alien(x,z).z + 10)
Alien(x,z).Direct = 0
Endif
Position Object Alien(x,z).ID,Alien(x,z).x,Alien(x,z).y,Alien(x,z).z
Next z
Next x
EndFunction
Function InvaderBomb(InvaderData)
If Object Exist(Alien(0,0).Bomb) = 0
Make Object Sphere Alien(0,0).Bomb,10
Repeat
x = RND(10)
z = RND(4)
Until Alien(0,0).Dead = 1
Bomb.x = Object Position x(Alien(x,z).ID)
Bomb.y = Object Position y(Alien(x,z).ID)
Bomb.z = Object Position z(Alien(x,z).ID)
Endif
If Object Collision(Ground.ID,Alien(0,0).Bomb)
Repeat
x = RND(10)
z = RND(4)
Until Alien(0,0).Dead = 1
Endif
Position Object Alien(0,0).Bomb,Bomb.x,Bomb.y,Bomb.z
If Object Exist(Alien(0,0).Bomb) = 1
Inc Bomb.z,2
Endif
If Object Collision (BarrelMedium.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
If Object Collision (BarrelLarge.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
If Object Collision (CannonStand.ID,Alien(0,0).Bomb) = 1
Game.Trigger = 1
Position Object BarrelLarge.ID,-500,-500,-500
Position Object BarrelMedium.ID,-500,-500,-500
Position Object CannonStand.ID,-500,-500,-500
Endif
EndFunction
Function GameWinLose(GameData)
Text -60,-60,Str$(Game.trigger)
If Object Collision (Alien(x,z).ID,Ground.ID) = 1 And Alien(x,z).Dead = 0
Game.Trigger = 1
Endif
If Game.Trigger = 1
Center Text Screen Width()/2,Screen Height()/2,"You have lost! Aliens have taken over and killed everyone on earth"
Center Text Screen Width()/2,Screen Height()/2+50,"Press any key to use your time machine and attempt to fix this Ordeal "
Sync
Wait key
ResetLevel1()
Endif
EndFunction
Function ResetLevel1()
Version.char = " Invader Engine V2.0 |"
Lives.char = " Lives ? **** Off!|"
Score.char = "Score : "
Score.Total = 0
Bullet.ID = 4000
Alien(0,0).Bomb = 2000
Game.Trigger = 0
Alien.NextWave = 0
Alien1(x,z).Direct = 0
Alien1(x,z).Dead = 0
Alien.NextLvl = 0
For x = 0 To 10
For z = 0 To 4
Alien(x,z).Direct = 0
Alien(x,z).Dead = 0
Show Object Alien(x,z).ID
Alien(x,z).x = 175-(x*40)
Alien(x,z).y = CannonStand.y
Alien(x,z).z = 0-(z*30)
Bomb.x = Object Position x(Alien(x,z).ID)
Bomb.y = Object Position y(Alien(x,z).ID)
Bomb.z = Object Position z(Alien(x,z).ID)
Next z
Next x
CannonStand.x = 0
CannonStand.y = 0
CannonStand.z = 280
BarrelMedium.x = 0
BarrelMedium.y = 0
BarrelMedium.z = 230
BarrelLarge.x = 0
BarrelLarge.y = 0
BarrelLarge.z = 260
EndFunction
Function Levels()
EndFunction
Space
Rem ***** Included Source File *****
DataSetup:
Type BoundaryData
ID as Integer
EndType
Type LightData
x as Float
y as Float
z as Float
ID as Integer
EndType
Type PlayerData
x as Float
y as Float
z as Float
ID as Integer
EndType
Type InvaderData
x as Float
y as Float
z as Float
ID as Integer
Direct as Boolean
Speed as Float
Dead as Boolean
Bomb as Integer
NextWave as Integer
NextLvl as Integer
EndType
Type BulletData
y as Float
x as Float
z as Float
ID as Integer
EndType
Type ScoreData
y as Float
x as Float
z as Float
Total as Integer
Char as String
EndType
Type CameraData
x as Float
y as Float
z as Float
ID as Integer
EndType
Type GameData
Trigger as Integer
EndType
Global Light as LightData
Global CannonStand as PlayerData
Global BarrelLarge as PlayerData
Global BarrelMedium as PlayerData
Global Alien1 as InvaderData
Dim Alien1(10,4) as InvaderData
Global Alien as InvaderData
Dim Alien(10,4) as InvaderData
Global Bullet as BulletData
Global Points as ScoreData
Global Camera as CameraData
Global Version as ScoreData
Global Lives as ScoreData
Global Score as ScoreData
Global Ground as BoundaryData
Global LeftWall as BoundaryData
Global RightWall as BoundaryData
Global Background as BoundaryData
Global TopWall as BoundaryData
Global Game as GameData
Global Bomb as InvaderData
Return
Space:
Sync On
Sync Rate 60
Randomize Timer()
BackDrop Off
AutoCam Off
Return
And also in case anyone is wondering why I keep asking questions in this forum about space invaders is because I had made a space invaders game but it was over 2000 lines of code and it did not have arrays in it, I wanted to repeat the project so I could learn about arrays and how i could use them.
Thanks to anyone who even has the patience to look over this
Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee