by berndnoetscher » Wed Sep 21, 2011 2:27 pm
This is a fixed version, problems happend due to variant data type:
- Code: Select all
option oldbasic
option explicit off
Dim x as integer
Dim y as integer
Dim Schuss as integer
Dim SchussX as integer
Dim SchussY as integer
Dim Cnt as integer
Dim Cnt2 as integer
Dim ETorpX as integer
Dim ETorpY as integer
Dim ETorp_Running as boolean
/*
Sub Play_Explosion()
sound1.FileName = "explode.wav"
sound1.Command = "close"
sound1.Command = "Open"
sound1.Command = "Play"
End Sub
*/
' Private Sub Form_OnOpen/*Form_Load*/()
' ' Me.ShowFullScreen
' Energy.value=100
' 'Form33 = Me
' randomize timer
' text1.text=""
' End Sub
Private Sub Form_OnKeyDown(KeyCode As Integer, Shift As Boolean, Control As Boolean, Alt As Boolean)
If KeyCode = Key.Escape Then
Application.CloseAll
Application.Stop
End If
If KeyCode = Key.Right Then
x = x + 15
End If
If KeyCode = Key.Left Then
x = x - 15
End If
if x < 0 then
x=0
endif
if x > (500-64) then
x = 500-64
endif
If KeyCode = Key.Space And Schuss = 0 Then
Schuss = 1
SchussX = Ship.X + (Ship.Width / 2) - (Torpedo.Width / 2)
SchussY = Ship.Y - Torpedo.Height
Torpedo.X = SchussX
Torpedo.Y = SchussY
Torpedo.Visible = True
End If
Ship.X = x
'Text1.Text = ""
End Sub
Private Sub Timer1_OnEvent/*_Timer*/()
/* the Bonus-Object */
w1=abs(bonus.x - ship.x)
w2=abs(bonus.y - ship.y)
if w1 < 64 and w2 < 64 then
e=energy.value+rnd(100)
if e < 100 then
e=100
endif
energy.value=e
bonus.x = rnd*1200-100
bonus.y = -1 * rnd*1500+50
endif
bonus.y = bonus.y+15
if bonus.y > (Energy.y-50) then
bonus.x = rnd*1200+100
bonus.y = -1 * rnd*1500+50
endif
If Cnt <> 0 Then
Cnt = Cnt + 1
If Cnt > 10 Then
Cnt = 0
Explosion.Visible = False
Enemy.Visible = True
End If
End If
If Cnt2 <> 0 Then
Cnt2 = Cnt2 + 1
If Cnt2 > 10 Then
Cnt2 = 0
Explosion.Visible = False
Ship.Visible = True
End If
End If
If Schuss <> 0 Then
SchussY = SchussY - (Torpedo.Height / 2)
Torpedo.Y = SchussY
Torpedo.X = SchussX
w1= abs(Torpedo.X - Enemy.X)
w2 = abs(Torpedo.y - Enemy.y)
If w1 < 20 And w2 < 20 then
Enemy.Visible = False
Explosion.Y = Enemy.Y
Explosion.X = Enemy.X
Explosion.Visible = True
Schuss = 0
Torpedo.Visible = False
Cnt = 1
Hits.Caption = "" & (val(hits.caption) + 1)
' Call Play_Explosion
End If
End If
If SchussY < -Torpedo.Height Then
Schuss = 0
Torpedo.Visible = False
End If
If ETorp_Running = True Then
ETorpY = ETorpY + (ETorp.Height / 2)+val(Hits.Caption)*5
ETorp.X = ETorpX
ETorp.Y = ETorpY
ETorp.Visible = True
If ETorpY > Form1.Height Then
ETorp.Visible = False
ETorp_Running = False
End If
If ETorpX + ETorp.Width >= Ship.X And ETorpX <= (Ship.X + Ship.Width) And ETorpY >= Ship.Y And ETorpY <= (Ship.Y + Ship.Height) Then
Cnt2 = 1
Ship.Visible = False
Explosion.Y = Ship.Y
Explosion.X = Ship.X
Explosion.Visible = True
ETorp_Running = False
ETorp.Visible = False
Energy.Value=Energy.value-5
if energy.value < 1 then
Application.CloseAll
Application.Stop
endif
End If
End If
If Abs(Enemy.X - Ship.X) < 20 And ETorp_Running = False And Cnt2 = 0 Then
ETorp_Running = True
ETorpY = Enemy.Y + Enemy.Height
ETorpX = Enemy.X + (Enemy.Width / 2) - (ETorp.Width / 2)
End If
If Enemy.X < Ship.X Then
If Abs(Enemy.X - Ship.X) > 10 Then
Enemy.X = Enemy.X + 10
Else
Enemy.X = Enemy.X + Abs(Enemy.X - Ship.X)
End If
End If
If Enemy.X > Ship.X Then
If Abs(Enemy.X - Ship.X) > 10 Then
Enemy.X = Enemy.X - 10
Else
Enemy.X = Enemy.X - Abs(Enemy.X - Ship.X)
End If
End If
End Sub