Heh paráda, hra mě jde ubíraní životů také.
Mám tedy poslední 2 problémy :)
Tank2 když vystřelí doleva, sekne se kulka chvíli po výstřelu. viz. fotka. Na všechny ostatní směry je to v pořádku je to pro mě docela velký hlavolam. Děkuji všem za radu. PS kod je trochu delší tak neleknout.
Public Class Form2
Dim HP1 As Integer = 3
Dim HP2 As Integer = 3
Dim konec1 As String
Dim Msg1 As String = ("Zelený hráč vyhrál! Zkusit znova?")
Dim konec2 As String
Dim Msg2 As String = ("Modrý hráč vyhrál!Zkusit znova?")
Dim X1, Y1, X2, Y2, Smer, Smer2, Xstrela, Xstrela2, Ystrela, Ystrela2, Strela, Strela2, Vystreleno, Vystreleno2, Konecvystrelu, Konecvystrelu2 As Integer
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal klavesa As Keys) As Boolean
X1 = Me.Tank1.Location.X
Y1 = Me.Tank1.Location.Y
X2 = Me.Tank2.Location.X
Y2 = Me.Tank2.Location.Y
REM Tank1
If (Me.Tank1.Location.Y > 41) And ((Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height + 2) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 8) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 1) Or (Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 1)) Then
If klavesa = Keys.Up Then
Me.Tank1.Image = Me.Tanknahoru.Image
Me.Tank1.Height = 29
Me.Tank1.Width = 24
Y1 = Y1 - 3
Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
Smer = 1
End If
End If
If (Me.Tank1.Location.Y < Me.Height - 69) And ((Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 8) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height - 1) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 1) Or (Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 1)) Then
If klavesa = Keys.Down Then
Me.Tank1.Image = Me.Tankdolu.Image
Me.Tank1.Height = 29
Me.Tank1.Width = 24
Y1 = Y1 + 3
Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
Smer = 2
End If
End If
If (Me.Tank1.Location.X > 0) And ((Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width + 2) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width + 8) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 1) Or (Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 1)) Then
If klavesa = Keys.Left Then
Me.Tank1.Image = Me.Tankvlevo.Image
Me.Tank1.Height = 24
Me.Tank1.Width = 29
X1 = X1 - 3
Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
Smer = 3
End If
End If
If (Me.Tank1.Location.X < Me.Width - 48) And ((Me.Tank1.Location.X > Me.Tank2.Location.X + Me.Tank2.Width - 8) Or (Me.Tank1.Location.X < Me.Tank2.Location.X - Me.Tank1.Width - 1) Or (Me.Tank1.Location.Y < Me.Tank2.Location.Y - Me.Tank1.Height + 1) Or (Me.Tank1.Location.Y > Me.Tank2.Location.Y + Me.Tank2.Height - 1)) Then
If klavesa = Keys.Right Then
Me.Tank1.Image = Me.Tankvpravo.Image
Me.Tank1.Height = 24
Me.Tank1.Width = 29
X1 = X1 + 3
Me.Tank1.Location = New System.Drawing.Point(X1, Y1)
Smer = 4
End If
End If
REM proměnná Vystreleno pro zakázání dalšího výstřelu během letu kulky tanku1
If Vystreleno = 0 Then
If klavesa = Keys.Space Then
Xstrela = Me.Tank1.Location.X
Ystrela = Me.Tank1.Location.Y
Strela = Smer
Timer1.Start()
Vystreleno = 1
End If
End If
REM proměnná Vystreleno pro zakázání dalšího výstřelu během letu kulky tanku2
If Vystreleno2 = 0 Then
If klavesa = Keys.C Then
Xstrela2 = Me.Tank2.Location.X
Ystrela2 = Me.Tank2.Location.Y
Strela2 = Smer2
Timer3.Start()
Vystreleno2 = 1
End If
End If
REM Tank2
If (Me.Tank2.Location.Y > 41) And ((Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height + 2) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 8) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 1) Or (Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 1)) Then
If klavesa = Keys.W Then
Me.Tank2.Image = Me.Tank2nahoru.Image
Me.Tank2.Height = 29
Me.Tank2.Width = 24
Y2 = Y2 - 3
Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
Smer2 = 5
End If
End If
If (Me.Tank2.Location.Y < Me.Height - 69) And ((Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 8) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height - 1) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 1) Or (Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 1)) Then
If klavesa = Keys.S Then
Me.Tank2.Image = Me.Tank2dolu.Image
Me.Tank2.Height = 29
Me.Tank2.Width = 24
Y2 = Y2 + 3
Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
Smer2 = 6
End If
End If
If (Me.Tank2.Location.X > 0) And ((Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width + 2) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width + 8) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 1) Or (Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 1)) Then
If klavesa = Keys.A Then
Me.Tank2.Image = Me.Tank2vlevo.Image
Me.Tank2.Height = 24
Me.Tank2.Width = 29
X2 = X2 - 3
Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
Smer2 = 7
End If
End If
If (Me.Tank2.Location.X < Me.Width - 48) And ((Me.Tank2.Location.X > Me.Tank1.Location.X + Me.Tank1.Width - 8) Or (Me.Tank2.Location.X < Me.Tank1.Location.X - Me.Tank2.Width - 2) Or (Me.Tank2.Location.Y < Me.Tank1.Location.Y - Me.Tank2.Height + 1) Or (Me.Tank2.Location.Y > Me.Tank1.Location.Y + Me.Tank1.Height - 1)) Then
If klavesa = Keys.D Then
Me.Tank2.Image = Me.Tank2vpravo.Image
Me.Tank2.Height = 24
Me.Tank2.Width = 29
X2 = X2 + 3
Me.Tank2.Location = New System.Drawing.Point(X2, Y2)
Smer2 = 8
End If
End If
Return MyBase.ProcessCmdKey(msg, klavesa)
End Function
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Smer = 4
Smer2 = 7
Me.BackColor = Color.White
Vystreleno = 0
Vystreleno2 = 0
End Sub
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
REM strela nahoru
If Strela = 1 Then
Me.Kulka.Width = 7
Me.Kulka.Height = 10
Me.Kulka.Image = Me.Kulkanahoru.Image
Me.Kulka.Show()
Me.Kulka.Location = New System.Drawing.Point(Xstrela + 9, Ystrela - 19)
If Me.Kulka.Location.Y < 41 Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela - 19)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 3) And (Me.Kulka.Location.X > Me.Tank2.Location.X - 4) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela - 16)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
Me.HP2 = HP2 - 1
If HP2 = 2 Then
Me.zivot4.Hide()
End If
If HP2 = 1 Then
Me.zivot5.Hide()
End If
If HP2 = 0 Then
Me.zivot6.Hide()
Me.konec1 = MsgBox("Zelený hráč vyhrál chcete zkusit znova?", vbYesNo)
If konec1 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Ystrela = Ystrela - 5
Strela = 1
End If
REM strela dolu
If Strela = 2 Then
Me.Kulka.Width = 7
Me.Kulka.Height = 10
Me.Kulka.Image = Me.Kulkadolu.Image
Me.Kulka.Show()
Me.Kulka.Location = New System.Drawing.Point(Xstrela + 10, Ystrela + 39)
If Me.Kulka.Location.Y > Me.Height - 59 Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 3, Ystrela + 39)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka.Location.Y > Me.Tank2.Location.Y - Me.Kulka.Height) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) And (Me.Kulka.Location.X > Me.Tank2.Location.X - 4) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 2, Ystrela + 26)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
Me.HP2 = HP2 - 1
If HP2 = 2 Then
Me.zivot4.Hide()
End If
If HP2 = 1 Then
Me.zivot5.Hide()
End If
If HP2 = 0 Then
Me.zivot6.Hide()
Me.konec1 = MsgBox(Msg1, vbYesNo)
If konec1 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Ystrela = Ystrela + 5
Strela = 2
End If
REM strela doleva
If Strela = 3 Then
Me.Kulka.Width = 10
Me.Kulka.Height = 7
Me.Kulka.Image = Me.Kulkavlevo.Image
Me.Kulka.Show()
Me.Kulka.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 10)
If Me.Kulka.Location.X < 3 Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela - 20, Ystrela + 3)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka.Location.X > Me.Tank2.Location.X) And (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 4) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela - 18, Ystrela + 2)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
Me.HP2 = HP2 - 1
If HP2 = 2 Then
Me.zivot4.Hide()
End If
If HP2 = 1 Then
Me.zivot5.Hide()
End If
If HP2 = 0 Then
Me.zivot6.Hide()
Me.konec1 = MsgBox(Msg1, vbYesNo)
If konec1 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Xstrela = Xstrela - 5
Strela = 3
End If
REM strela doprava
If Strela = 4 Then
Me.Kulka.Width = 10
Me.Kulka.Height = 7
Me.Kulka.Image = Me.Kulkavpravo.Image()
Me.Kulka.Show()
Me.Kulka.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 9)
If Me.Kulka.Location.X > Me.Width - 38 Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 40, Ystrela + 2)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka.Location.X < Me.Tank2.Location.X + Me.Tank2.Width) And (Me.Kulka.Location.X > Me.Tank2.Location.X - Me.Kulka.Width) And (Me.Kulka.Location.Y > Me.Tank2.Location.Y - 4) And (Me.Kulka.Location.Y < Me.Tank2.Location.Y + Me.Tank2.Height) Then
Timer1.Stop()
Me.Kulka.Hide()
Me.Vybuch.Location = New System.Drawing.Point(Xstrela + 27, Ystrela + 2)
Me.Vybuch.Show()
Vystreleno = 0
Timer2.Start()
Me.HP2 = HP2 - 1
If HP2 = 2 Then
Me.zivot4.Hide()
End If
If HP2 = 1 Then
Me.zivot5.Hide()
End If
If HP2 = 0 Then
Me.zivot6.Hide()
Me.konec1 = MsgBox(Msg1, vbYesNo)
If konec1 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Xstrela = Xstrela + 5
Strela = 4
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
REM strela nahoru
If Strela2 = 5 Then
Me.Kulka2.Width = 7
Me.Kulka2.Height = 10
Me.Kulka2.Image = Me.Kulkanahoru2.Image
Me.Kulka2.Show()
Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 9, Ystrela2 - 19)
If Me.Kulka2.Location.Y < 41 Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 - 19)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 3) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - 4) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 - 15)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
Me.HP1 = HP1 - 1
If HP1 = 2 Then
Me.zivot1.Hide()
End If
If HP1 = 1 Then
Me.zivot2.Hide()
End If
If HP1 = 0 Then
Me.zivot3.Hide()
Me.konec2 = MsgBox(Msg2, vbYesNo)
If konec2 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Ystrela2 = Ystrela2 - 5
Strela2 = 5
End If
REM strela dolu
If Strela2 = 6 Then
Me.Kulka2.Width = 7
Me.Kulka2.Height = 10
Me.Kulka2.Image = Me.Kulkadolu2.Image
Me.Kulka2.Show()
Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 10, Ystrela2 + 39)
If Me.Kulka2.Location.Y > Me.Height - 59 Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 3, Ystrela2 + 39)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - Me.Kulka2.Height) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - 4) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 2, Ystrela2 + 25)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
Me.HP1 = HP1 - 1
If HP1 = 2 Then
Me.zivot1.Hide()
End If
If HP1 = 1 Then
Me.zivot2.Hide()
End If
If HP1 = 0 Then
Me.zivot3.Hide()
Me.konec2 = MsgBox(Msg2, vbYesNo)
If konec2 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Ystrela2 = Ystrela2 + 5
Strela2 = 6
End If
REM strela doleva
If Strela2 = 7 Then
Me.Kulka2.Width = 10
Me.Kulka2.Height = 7
Me.Kulka2.Image = Me.Kulkavlevo2.Image
Me.Kulka2.Show()
Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 - 20, Ystrela2 + 10)
If Me.Kulka2.Location.X < 3 Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 - 20, Ystrela2 + 3)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka2.Location.X > Me.Tank1.Location.X) And (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 4) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 - 17, Ystrela2 + 2)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
Me.HP1 = HP1 - 1
If HP1 = 2 Then
Me.zivot1.Hide()
End If
If HP1 = 1 Then
Me.zivot2.Hide()
End If
If HP1 = 0 Then
Me.zivot3.Hide()
Me.konec2 = MsgBox(Msg2, vbYesNo)
If konec2 = vbYes Then
Application.Restart()
Else
End
End If
End If
Xstrela2 = Xstrela2 - 5
Strela2 = 7
End If
End If
REM strela doprava
If Strela2 = 8 Then
Me.Kulka2.Width = 10
Me.Kulka2.Height = 7
Me.Kulka2.Image = Me.Kulkavpravo2.Image()
Me.Kulka2.Show()
Me.Kulka2.Location = New System.Drawing.Point(Xstrela2 + 40, Ystrela2 + 9)
If Me.Kulka2.Location.X > Me.Width - 38 Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 40, Ystrela2 + 2)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
End If
REM podminka pro zasahnuti tanku kulkou
If (Me.Kulka2.Location.X < Me.Tank1.Location.X + Me.Tank1.Width) And (Me.Kulka2.Location.X > Me.Tank1.Location.X - Me.Kulka2.Width) And (Me.Kulka2.Location.Y > Me.Tank1.Location.Y - 4) And (Me.Kulka2.Location.Y < Me.Tank1.Location.Y + Me.Tank1.Height) Then
Timer3.Stop()
Me.Kulka2.Hide()
Me.Vybuch2.Location = New System.Drawing.Point(Xstrela2 + 26, Ystrela2 + 2)
Me.Vybuch2.Show()
Vystreleno2 = 0
Timer4.Start()
Me.HP1 = HP1 - 1
If HP1 = 2 Then
Me.zivot1.Hide()
End If
If HP1 = 1 Then
Me.zivot2.Hide()
End If
If HP1 = 0 Then
Me.zivot3.Hide()
Me.konec2 = MsgBox(Msg2, vbYesNo)
If konec2 = vbYes Then
Application.Restart()
Else
End
End If
End If
End If
Xstrela2 = Xstrela2 + 5
Strela2 = 8
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
'Konecvystrelu = Konecvystrelu + 1
'If Konecvystrelu = 2 Then
Me.Vybuch.Hide()
Timer2.Stop()
'Konecvystrelu = 0
'End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Konecvystrelu2 = Konecvystrelu2 + 1
If Konecvystrelu2 = 2 Then
Me.Vybuch2.Hide()
Timer4.Stop()
Konecvystrelu2 = 0
End If
End Sub
End Class