Although starting to lag a lot now, here is the new code:
;Graphics
Graphics 640,480,16,2
;Timer.
timer = CreateTimer(30)
;load highscore
If ReadFile("score.dat") = 0 Then
highscore = 100
Else
file_score = ReadFile("score.dat")
highscore = ReadInt(file_score)
CloseFile (file_score)
EndIf
;Load Images.
AutoMidHandle True
img_alien = LoadImage("alien.png")
img_smile = LoadImage("smile.png")
img_bullet = LoadImage("bullet.png")
img_bomb = LoadImage("bomb.png")
img_power = LoadImage("power.png")
;Load sounds.
snd_gameover = LoadSound("Gameover.wav")
snd_Bulletsound = LoadSound("Bulletsound.wav")
snd_Loselife = LoadSound("Loselife.wav")
snd_Bombsound = LoadSound("Bombsound.wav")
snd_Aliendeath = LoadSound("Aliendeath.wav")
;Load background.
img_background = LoadImage("background.png")
;Bullet.
Type bullet
Field x
Field y
End Type
;power
Type power
End Type
x= 300
y= 400
;Bomb.
Type bomb
Field x
Field y
End Type
;Alien.
Type alien
Field x
Field y
End Type
;Lives.
Lives = 3
;Level to start on
level = 0
;set number of aliens at start.
numaliens = 0
;Set alien speed.
aspeed = 2
amx = aspeed
chdir = False
;Reset score.
score = 0
;Buffers.
SetBuffer BackBuffer()
While Not KeyDown(1)
If numaliens = 0 Then
level = level + 1
;Alien number.
For z = 1 To 9
For w = 1 To 2
a.alien = New alien
a\x = 100 + 50*z
a\y = -70 + 120*w
Next
Next
End If
Cls
backdrop=LoadImage("background.png")
TileBlock backdrop
DrawImage img_smile,x,y
;Keys.
If KeyDown(200) Then y = y - 6
If KeyDown(208) Then y = y + 6
If KeyDown(203) Then x = x - 6
If KeyDown(205) Then x = x + 6
; Limit player movement {
tiw = ImageWidth(img_smile) / 2
If x < tiw Then x = tiw
If x >= 640 - tiw Then x = 640 - tiw - 1
If y < tiw Then y = tiw
If y >= 485 - tiw Then y = 485 - tiw - 1
; }
If KeyHit (207) Then End
If KeyDown(2) Then Flip
If KeyDown(3) Then Flip
If KeyDown(4) Then Flip
If KeyDown(5) Then Flip
If KeyDown(6) Then Flip
If KeyDown(7) Then Flip
If KeyDown(8.) Then Flip (ignore the dot after the eight it was only their to disable a smiley)
If KeyDown(9) Then Flip
If KeyDown(10) Then Flip
If KeyDown(11) Then Flip
If KeyDown(17) Then y = y - 6
If KeyDown(30) Then x = x - 6
If KeyDown(31) Then y = y + 6
If KeyDown(32) Then x = x + 6
If KeyHit (57) Then
;About bullets
PlaySound (snd_Bulletsound)
b.bullet = New bullet
b\x = x
b\y = y - 5
EndIf
;More about bullets
For b.bullet = Each bullet
b\y = b\y - 5
DrawImage img_bullet,b\x,b\y
If b\y < 0 Then Delete b
Next
;Extra alien movement.
If chdir = True Then
amx = -amx
EndIf
chdir = False
numaliens = 0
;Alien movement.
For a.alien = Each alien
;Count aliens
numaliens = numaliens + 1
;Main alien movement.
a\x = a\x + amx
If a\x > 620 Then chdir = True
If a\x < 20 Then chdir = True
;Aliens drop.
If Rand(200) = 25 Then
PlaySound(snd_Bombsound)
bombs.bomb = New bomb
bombs\x = a\x
Bombs\y = a\y
EndIf
;Images collide "bullet" with "alien".
DrawImage img_alien,a\x,a\y
For b.bullet = Each bullet
If ImagesCollide (img_bullet,b\x,b\y,0,img_alien,a\x,a\y,0) Then
PlaySound (snd_Aliendeath)
Delete b
Delete a
score = score + 10
If score > highscore Then highscore = score
Exit
EndIf
Next
Next
;About bombs.
For bombs.bomb = Each bomb
bombs\y = bombs\y + 4
DrawImage img_bomb,bombs\x,bombs\y
If bombs\y > 500 Then Delete bombs
;Images colide "bomb" with "smile".
If ImagesCollide (img_bullet,bombs\x,bombs\y,0,img_smile,x,y,0)
PlaySound(snd_Loselife)
Delete bombs
lives = lives - 1
ElseIf bombs\y > 475 Then
Delete bombs
EndIf
Next
;What happens when less lives.
If lives=0 Then
;save highscore
file_score = WriteFile("score.dat")
WriteInt(file_score,highscore)
CloseFile file_scored
PlaySound(snd_Gameover)
Text 320,100,"GAME OVER",1,1
Text 320,115,"Try again!",1,1
Flip
Delay 3000
End
EndIf
Text 50,420,"LIVES: " + Lives
;Draw score.
Text 530,420,"SCORE: " + score
Text 510,430,"Nice score! "
;Draw highscpre.
Text 320,50,"HIGHSCORE: " + highscore,1,1
;Draw level number.
Text 320,440,"LEVEL: " + level,1
;Wait game timer.
WaitTimer(timer)
;Flip screen monitor.
Flip
Wend
;End game.
End
And here is the new attachments (some of them will need overwriting).