I am now tring to make make alien shot when the timer reaches 0 then reset it to a random time between 2-10 seconds but i dont know how to make my variable count down 1 everysecond.
Rem Project: Space Invaders
Rem Created: 16/05/2004 11:04:38
Rem ***** Main Source File *****
Rem Set the screen size and sync rate
Set Display Mode 800,600,32
Sync On : Sync Rate 120 : Hide Mouse
Randomize Timer()
Rem Define Variables
PlayerX = 400-10
PlayerY = 550
BulletX = PlayerX+20
BulletY = 550
EnemyY=100
starquantity = 600
starlayers = 5
speedfactor# = 0.50
SoundSpeed=35000
Score=0
Alpha1=255
Alpha2=255
Alpha3=255
Dim EnemyPositionX(10,3)
Dim EnemyAttack(10,3)
Dim EnemyPositionY(3)
Dim EnemyBulletY(10)
Dim EnemyBulletX(10)
Dim EnemyBulletFire(10)
EnemyPositionY(1)=100
EnemyPositionY(2)=200
EnemyPositionY(3)=300
EnemiesLeft=0
XMove=2
YMove#=2
For EnemyFire=1 to 10
EnemyBulletFire(Enemy)= Rem set to random time to wait
next enemyfire
Rem Type for the move background
type starfield
X AS FLOAT
Y AS FLOAT
Z AS INTEGER
speed AS FLOAT
color AS DWORD
endtype
Rem Array of stars
dim stars(starquantity) as starfield
rem Create the location of the stars
for s=0 to starquantity
stars(s).x = rnd(800)
stars(s).y = rnd(800)
stars(s).z = int(s/(starquantity/starlayers))+1
stars(s).speed = stars(s).z * speedfactor#
temp_col = (255/starlayers) * stars(s).z
stars(s).color = rgb(rnd(255),rnd(255),rnd(255))
next s
Rem our memblock - this is calculated from the following: screen X * screen Y * 4 (bytes per pixel)
make memblock 1,2560000
mem_loc AS DWORD
mem_loc = get memblock ptr(1)
Rem Load media in loop
For t=1 to 1
rem Load image
Load Image "images\ship1.png",1
Load Image "images\bluenemy.png",2
Load Image "images\grnenemy.png",3
Load Image "images\purpenemy.png",4
Load Image "images\Shield.png",5
Load Image "images\bullete.png",6
Load Image "images\bulletp.png",7
Load Image "images\ship2.png",8
rem load Theme Sound
Load Sound "Music\Space Invaders Background.WAV",1
rem Set the sound speed
Set Sound Speed 1,35000
rem Loop Theme Sound
Loop Sound 1
next t
Set text Size 20
Sprite 33,133,450,5
Sprite 34,383,450,5
Sprite 35,633,450,5
Rem Draw Blue Enemies
For Enemy=1 to 10
Sprite Enemy+2,Enemy*67,100,2
Next Enemy
Rem Draw Green Enemies
For Enemy=1 to 10
Sprite Enemy+12,Enemy*67,200,3
Next Enemy
Rem Draw Purple Enemies
For Enemy=1 to 10
Sprite Enemy+22,Enemy*67,300,4
Next Enemy
Rem Create and hide bullet for use in game
Sprite 2,0,0,7
Hide Sprite 2
For Enemy=1 to 10
For Enemy2=3 to 3
EnemyAttack(Enemy,Enemy2)=1
next enemy2
next enemy
For Enemy=1 to 10
For Enemy2=1 to 3
If EnemyAttack(Enemy,Enemy2)=1
EnemyBulletY(Enemy)=EnemyPositionY(Enemy2)+25
endif
next enemy2
next enemy
For Enemy=1 to 10
For Enemy2=1 to 3
If EnemyAttack(Enemy,Enemy2)=1
EnemyBulletX(Enemy)=EnemyPositionX(Enemy,Enemy2)+21
endif
next enemy2
next enemy
Rem main Loop (engine)
Do
Rem Update the Blue Enemies position
For Enemy=1 to 10
EnemyPositionX(Enemy,1)=Sprite X(Enemy+2)
If EnemyDir=1
Sprite Enemy+2,EnemyPositionX(Enemy,1)+XMove,EnemyPositionY(1),2
Endif
If EnemyDir=0
Sprite Enemy+2,EnemyPositionX(Enemy,1)-XMove,EnemyPositionY(1),2
Endif
If Sprite Visible(2)=1 And Sprite Visible(Enemy+2)=1 And Sprite Hit(2,Enemy+2)
Hide Sprite Enemy+2
BulletY=550
Hide Sprite 2
SoundSpeed=SoundSpeed+250
Score=Score+3
EnemiesLeft=EnemiesLeft+1
endif
Next Enemy
Rem Update the Green Enemies position
For Enemy=1 to 10
EnemyPositionX(Enemy,2)=Sprite X(Enemy+12)
If EnemyDir=1
Sprite Enemy+12,EnemyPositionX(Enemy,2)+XMove,EnemyPositionY(2),3
Endif
If EnemyDir=0
Sprite Enemy+12,EnemyPositionX(Enemy,2)-XMove,EnemyPositionY(2),3
Endif
If Sprite Visible(2)=1 And Sprite Visible(Enemy+12)=1 And Sprite Hit(2,Enemy+12)
Hide Sprite Enemy+12
BulletY=550
Hide Sprite 2
SoundSpeed=SoundSpeed+250
Score=Score+2
EnemiesLeft=EnemiesLeft+1
endif
Next Enemy
Rem Update the Purple Enemies position
For Enemy=1 to 10
EnemyPositionX(Enemy,3)=Sprite X(Enemy+22)
If EnemyDir=1
Sprite Enemy+22,EnemyPositionX(Enemy,3)+XMove,EnemyPositionY(3),4
Endif
If EnemyDir=0
Sprite Enemy+22,EnemyPositionX(Enemy,3)-XMove,EnemyPositionY(3),4
Endif
If Sprite Visible(2)=1 And Sprite Visible(Enemy+22)=1 And Sprite Hit(2,Enemy+22)
Hide Sprite Enemy+22
BulletY=550
Hide Sprite 2
SoundSpeed=SoundSpeed+250
Score=Score+1
EnemiesLeft=EnemiesLeft+1
endif
Next Enemy
rem Exit the program
If Escapekey()=1 Then End
rem Create/Repoition Player Ship
Sprite 1,PlayerX,PlayerY,1
rem Move Player Ship
If Leftkey()=1 And PlayerX>=4.5 Then PlayerX = PlayerX-4.5
If Rightkey()=1 And PlayerX<=745.5 Then playerX = PlayerX+4.5
rem Release bullet from ship
If Spacekey()=1 Then Show Sprite 2 : Sprite 2,BulletX,BulletY,7 : Sprite 2,BulletX,BulletY,7
If Sprite Visible(2)=1 Then BulletY=BulletY-8 : Sprite 2,BulletX,BulletY,7
If BulletY<=0
Hide Sprite 2
BulletY=550
Endif
Rem Update Bullet X when bullet is hidden
If Sprite Visible(2)=0
BulletX=PlayerX+20
endif
Rem Change the directional flag if Blue enemies reach edge of screen
For Enemy=1 to 30
If Sprite X(Enemy+2)<=0 And Sprite Visible(Enemy+2)=1
EnemyDir=1
endif
If Sprite X(Enemy+2)>=756 And Sprite Visible(Enemy+2)=1
EnemyDir=0
Endif
Next Enemy
Rem When enemies reach edge of screen increase Y variable so enemies go down
For Enemy=1 to 30
For Enemy2=1 to 3
If Sprite X(Enemy+2)>=756 And Sprite Visible(Enemy+2)=1
EnemyPositionY(Enemy2)=EnemyPositionY(Enemy2)+YMove#
endif
If Sprite X(Enemy+2)<=0 And Sprite Visible(Enemy+2)=1
EnemyPositionY(Enemy2)=EnemyPositionY(Enemy2)+YMove#
Endif
next Enemy2
Next enemy
For Enemy=1 to 30
If Sprite Y(Enemy+2)=>500
Cls
Center Text 400,300,"Game Over!"
Wait 3000
End
Endif
Next enemy
If EnemiesLeft=30
Gosub respawn
For Enemy=1 to 30
If Sprite Visible(Enemy+2)=0
Show Sprite Enemy+2
Endif
next Enemy
EnemiesLeft=0
endif
For Enemy=1 to 10
For Enemy2=1 to 3
If Sprite Visible(Enemy+2)=0
EnemyAttack(Enemy,Enemy2)=0
If Enemy2<3
EnemyAttack(Enemy,Enemy2+1)=1
endif
endif
next enemy2
next enemy
For Enemy=1 to 10
For Enemy2=1 to 3
If EnemyAttack(Enemy,Enemy2)=1
Sprite Enemy+90,EnemyPositionX(Enemy,Enemy2)+20,EnemyPositionY(Enemy2),6
endif
next enemy2
next enemy
For Enemy=1 to 10
EnemyBulletFire(Enemy)=EnemyBulletFire(Enemy)-1
next enemy
For Enemy=1 to 10
If EnemyBulletFire(Enemy)=0
Show Sprite Enemy+90
endif
If EnemyBulletFire(Enemy)=0
EnemyBulletFire(Enemy)= Rem set to random time to wait
endif
next enemy
For Enemy=1 to 10
For Enemy2=1 to 3
If EnemyAttack(Enemy,Enemy2)=1
EnemyBulletY(Enemy)=EnemyPositionY(Enemy2)+25
endif
next enemy2
next enemy
For Enemy=1 to 10
For Enemy2=1 to 3
If EnemyAttack(Enemy,Enemy2)=1
EnemyBulletX(Enemy)=EnemyPositionX(Enemy,Enemy2)+21
endif
next enemy2
next enemy
Rem our CLS equivalent
fill memory mem_loc, 0, 2560000
for s=0 to starquantity
sx# = stars(s).x
Rem works out where in memory to plot our dot!
mem_y = int(stars(s).y)*(800*4)
mem_x = (int(sx#)*4)
mem_location = mem_x + mem_y
Rem plots
if mem_location > 1 and mem_location < 2560000
write memblock dword 1, mem_location, stars(s).color
endif
Rem moves the star
sx# = sx# - stars(s).speed
if sx# < 0 then sx# = 800
stars(s).x = sx#
next s
Rem This copies the pixel data from memory to the screen
lock pixels
copy memory get pixels pointer(), mem_loc, 2560000
unlock pixels
Rem speed up music
Set Sound Speed 1,SoundSpeed
text 10,10,"Score: "+Str$(Score)
Rem refresh screen
Sync
Loop
respawn:
Rem Draw Blue Enemies
For Enemy=1 to 10
Sprite Enemy+2,Enemy*67,100,2
Next Enemy
Rem Draw Green Enemies
For Enemy=1 to 10
Sprite Enemy+12,Enemy*67,200,3
Next Enemy
Rem Draw Purple Enemies
For Enemy=1 to 10
Sprite Enemy+22,Enemy*67,300,4
Next Enemy
EnemyPositionY(1)=100
EnemyPositionY(2)=200
EnemyPositionY(3)=300
XMove=XMove+1
YMove=YMove+0.5
SoundSpeed=35000
Return
Thanx