Hi,
I'm on my second day of DarkBasic and I'm trying to make a simple Shoot'em Up game based on Reaperman's tutorial. I managed to add some enemies but I'm having a problem making them move. For some reason only one of the enemy sprites (20 total) will move. I'm trying to make them all scroll down the way (the game is space invader style, enemies come from the top of the screen and should move down the way). Here is my code so far:
rem Sprite 1 is the Ship
rem Sprites 3 - 102 are Bullets
rem Sprites 150 - 170 are Enemies
Sync On
Sync Rate 30
Hide Mouse
Set Display Mode 800,600,32
Set Image ColorKey 255,0,255
Load Image "ship.bmp",1
Load Image "enemy.bmp",2
Load Image "bullet.bmp",3
Dim BulletX(500)
Dim BulletY(500)
Dim EnemyX(20)
Dim EnemyY(20)
ShipX = 400
ShipY = 550
Do
Cls
If LeftKey() = 1 And ShipX > 20
ShipX = ShipX - 20
Endif
If RightKey() = 1 And ShipX < 760
ShipX = ShipX + 20
Endif
If Inkey$() = "a"
Gosub Shoot
Endif
Gosub AddEnemy
Gosub UpdateShip
Gosub UpdateBullet
Gosub UpdateEnemies
Sync
Loop
Shoot:
For i = 1 to 500
If BulletX(i) = 0
BulletX(i) = ShipX + 17
BulletY(i) = ShipY - 9
Sprite 2 + i,BulletX(i),BulletY(i),3
Exit
Endif
Next i
Return
UpdateShip:
Sprite 1,ShipX,ShipY,1
Return
UpdateBullet:
For i = 1 to 500
If BulletX(i) > 0
If BulletY(i) < 0
BulletY(i) = 0
BulletX(i) = 0
rem Hide Sprite 2 + i
FirePressed = 0
Endif
BulletY(i) = BulletY(i) - 25
Sprite 2 + i,BulletX(i),BulletY(i),3
Endif
Next i
Return
AddEnemy:
For i = 1 to 20
If EnemyX(i) = 0
EnemyX(i) = Rnd(700) + 40
EnemyY(i) = 10
Sprite 149 + i,EnemyX(i),EnemyY(i),2
Exit
Endif
Next i
Return
UpdateEnemies:
For i = 1 to 20
If EnemyX(i) > 0
EnemyY(i) = EnemyY(i) + 10
EnemyX(i) = EnemyX(i)
Sprite 149 + 1,EnemyX(i),EnemyY(i),2
Endif
Next i
Return
Thanks for reading!