Skip to content

Instantly share code, notes, and snippets.

@annibal
Created June 25, 2013 14:51
Show Gist options
  • Save annibal/5859080 to your computer and use it in GitHub Desktop.
Save annibal/5859080 to your computer and use it in GitHub Desktop.
Tank source code 2. it's bigger so this might not work less than Tank 1
Public Class Form1
WithEvents t As New Timer With {.Interval = 30}
Dim p As New Panel With {.Width = 500}
Dim g As Graphics
Dim kp(20) As Boolean
Dim canshoot As Integer = 0, canshoot2 As Integer = 0
Dim blow1, blow2, blow1x, blow1y, blow2x, blow2y As Integer
Dim AI As Boolean = False
Public power1, power2, speed1, speed2, delay1, delay2 As Integer
Dim iz As Integer = 0, jz As Integer = 0
Dim p1 As New obj(p.Width / 4, p.Height / 2, 0, 80, 80, 90, 100, 100)
Dim p2 As New obj(3 * p.Width / 4, p.Height / 2, 0, 80, 80, 90, 100, 100)
Dim h1 As New obj(p.Width / 4, p.Height / 2, 0, 40, 40, 0, 0, 35)
Dim h2 As New obj(p.Width / 4, p.Height / 2, 0, 40, 40, 0, 0, 35) '// h of Head stays top of p (Player), the tank
Dim pt As New extra_graphics
Dim sh1(10) As obj
Dim sh2(10) As obj
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.W Then kp(1) = True 'tank 1 move front
If e.KeyCode = Keys.S Then kp(2) = True 'tank 1 move back
If e.KeyCode = Keys.A Then kp(3) = True 'tank 1 turn left
If e.KeyCode = Keys.D Then kp(4) = True 'tank 1 turn right
If e.KeyCode = Keys.C Then kp(9) = True 'tank 1 head anti-horario
If e.KeyCode = Keys.V Then kp(10) = True 'tank 1 head horario
If e.KeyCode = Keys.Space Then kp(13) = True 'tank 1 shoot
If e.KeyCode = Keys.I Then kp(5) = True 'tank 2 move front
If e.KeyCode = Keys.K Then kp(6) = True 'tank 2 move behind
If e.KeyCode = Keys.J Then kp(7) = True 'tank 2 move left
If e.KeyCode = Keys.L Then kp(8) = True 'tank 2 move right
If e.KeyCode = 189 Then kp(11) = True 'tank 2 head anti-horario
If e.KeyCode = 187 Then kp(12) = True 'tank 2 head horario
If e.KeyCode = Keys.Enter Then kp(14) = True 'tank 2 shoot
If e.KeyCode = Keys.Y Then
If AI Then AI = Not AI Else
AI = True
kp(8) = False
kp(7) = False
kp(5) = False
kp(14) = False
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.W Then kp(1) = Not True 'tank 1 move front
If e.KeyCode = Keys.S Then kp(2) = Not True 'tank 1 move back
If e.KeyCode = Keys.A Then kp(3) = Not True 'tank 1 turn left
If e.KeyCode = Keys.D Then kp(4) = Not True 'tank 1 turn right
If e.KeyCode = Keys.C Then kp(9) = Not True 'tank 1 head anti-horario
If e.KeyCode = Keys.V Then kp(10) = Not True 'tank 1 head horario
If e.KeyCode = Keys.Space Then kp(13) = Not True 'tank 1 shoot
If e.KeyCode = Keys.I Then kp(5) = Not True 'tank 2 move front
If e.KeyCode = Keys.K Then kp(6) = Not True 'tank 2 move behind
If e.KeyCode = Keys.J Then kp(7) = Not True 'tank 2 move left
If e.KeyCode = Keys.L Then kp(8) = Not True 'tank 2 move right
If e.KeyCode = 189 Then kp(11) = Not True 'tank 2 head anti-horario
If e.KeyCode = 187 Then kp(12) = Not True 'tank 2 head horario
If e.KeyCode = Keys.Enter Then kp(14) = Not True 'tank 2 shoot
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True
Call Form1_Resize(Me, Nothing)
p1.setMovementData(10, 5, 3, 2, 1)
p2.setMovementData(10, 5, 3, 2, 1)
h1.setMovementData(0, 7, 0, 3, 0)
h2.setMovementData(0, 7, 0, 3, 0)
For i As Integer = 0 To 10
sh1(i) = New obj(0, 0, 0, power1 + 10, power1 + 10, 0, 0, 0)
sh2(i) = New obj(0, 0, 0, power2 + 10, power2 + 10, 0, 0, 0)
Next
Me.Controls.Add(p)
t.Start()
h1.delay = 2 * delay1 + 5
h2.delay = 2 * delay2 + 5
End Sub
Private Sub t_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles t.Tick
Try
g.Clear(Color.Black)
If p1.hp < 1 Then
g.Clear(Color.Red)
g.DrawString("Player 2 has won!", New Font("Comic Sans MS", 30), Brushes.Black, 15, 15)
p1.hp = 10
t.Stop()
Exit Sub
'g.Flush()
End If
If p2.hp < 1 Then
g.Clear(Color.Blue)
g.DrawString("Player 1 has won!", New Font("Comic Sans MS", 30), Brushes.Black, 15, 15)
p2.hp = 10
t.Stop()
Exit Sub
'g.Flush()
End If
If kp(1) And p1.speed < 10 Then p1.speed += p1.accel 'speed up
If kp(2) And p1.speed > -10 Then p1.speed -= p1.accel 'speed down
If kp(3) And p1.turnSpeed < p1.maxTurnSpeed Then p1.turnSpeed += p1.agility 'spin direction wheel left
If kp(4) And p1.turnSpeed > -p1.maxTurnSpeed Then p1.turnSpeed -= p1.agility 'spin dir wheel right
p1.dir += p1.turnSpeed 'spin car according to direction wheel
p1.x = p1.posx(p1.dir, p1.speed) 'move
p1.y = p1.posy(p1.dir, p1.speed) 'move
If p1.turnSpeed > 0 And Not (kp(3) Or kp(4)) Then p1.turnSpeed -= p1.agility 'release turnwheel
If p1.turnSpeed < 0 And Not (kp(3) Or kp(4)) Then p1.turnSpeed += p1.agility 'release turnwheel
If p1.speed > 0 And Not (kp(1) Or kp(2)) Then p1.speed -= p1.grip 'speed down if not accelerating
If p1.speed < 0 And Not (kp(1) Or kp(2)) Then p1.speed += p1.grip 'speed down if not accelerating
h1.x = p1.x 'head must stay at same position of body
h1.y = p1.y 'y as well xD
If kp(9) And h1.turnSpeed < h1.maxTurnSpeed Then h1.turnSpeed += h1.agility 'spin head
If kp(10) And h1.turnSpeed > -h1.maxTurnSpeed Then h1.turnSpeed -= h1.agility 'spin head
h1.dir += h1.turnSpeed 'same direction wheel fisics
If h1.turnSpeed > 0 And Not (kp(9) Or kp(10)) Then h1.turnSpeed -= h1.agility 'stop spinning head
If h1.turnSpeed < 0 And Not (kp(9) Or kp(10)) Then h1.turnSpeed += h1.agility 'stop spinning head
If canshoot > 0 Then canshoot -= 1 'delay between shoots
If p1.x > p.Width - 5 Then p1.x = 10 'wrap on intersect boundary right
If p1.x < 5 Then p1.x = p.Width - 10 'wrap on intersect boundary left
If p1.y > p.Height - 5 Then p1.y = 10 'wrap on intersect boundary bottom
If p1.y < 5 Then p1.y = p.Height - 10 'wrap on intersect boundary top
If kp(13) And (canshoot < 1) Then 'if key of shoot is press, if shoot is loaded and theres no shoot in scene
canshoot = h1.delay 'grow the delay
sh1(iz).x = h1.posx(h1.dir, h1.w) 'create shoot at end of cannon
sh1(iz).y = h1.posy(h1.dir, h1.h) 'create shoot at end of cannon
sh1(iz).speed = 3 * speed1 + 3 'set speed of shoot
sh1(iz).dir = h1.dir 'set direction of shoot = cannon direction
sh1(iz).exist = True 'make the program understand that there is a shoot xD
iz += 1
If iz > 10 Then iz = 0
End If
Me.Text = "P1: " & h1.delay & " " & p1.delay & " " & canshoot & " P2: " & h2.delay & " " & p2.delay & " " & canshoot2
If kp(5) And p2.speed < 10 Then p2.speed += p2.accel 'speed up
If kp(6) And p2.speed > -10 Then p2.speed -= p2.accel 'speed down
If kp(7) And p2.turnSpeed < p2.maxTurnSpeed Then p2.turnSpeed += p2.agility 'turn direction wheel left
If kp(8) And p2.turnSpeed > -p2.maxTurnSpeed Then p2.turnSpeed -= p2.agility 'right
p2.dir += p2.turnSpeed 'turn car according to direction wheel
p2.x = p2.posx(p2.dir, p2.speed) 'move
p2.y = p2.posy(p2.dir, p2.speed) 'move
If p2.turnSpeed > 0 And Not (kp(7) Or kp(8)) Then p2.turnSpeed -= p2.agility 'release turn wheel
If p2.turnSpeed < 0 And Not (kp(7) Or kp(8)) Then p2.turnSpeed += p2.agility 'release turn wheel
If p2.speed > 0 And Not (kp(5) Or kp(6)) Then p2.speed -= p2.grip 'Atrito
If p2.speed < 0 And Not (kp(5) Or kp(6)) Then p2.speed += p2.grip 'Grip
h2.x = p2.x 'head = body
h2.y = p2.y 'ehad = body
If kp(11) And h2.turnSpeed < h2.maxTurnSpeed Then h2.turnSpeed += h2.agility 'turn head's spinning wheel
If kp(12) And h2.turnSpeed > -h2.maxTurnSpeed Then h2.turnSpeed -= h2.agility 'same for the other side
h2.dir += h2.turnSpeed 'turn head according to it's spin wheel
If h2.turnSpeed > 0 And Not (kp(11) Or kp(12)) Then h2.turnSpeed -= h2.agility 'release head's spinning wheel
If h2.turnSpeed < 0 And Not (kp(11) Or kp(12)) Then h2.turnSpeed += h2.agility 'it must return to no spin xD
If canshoot2 > 0 Then canshoot2 -= 1 'in real life this would be the action of put another bomb in the cannon
If p2.x > p.Width - 5 Then p2.x = 10 'wrap left
If p2.x < 5 Then p2.x = p.Width - 10 'wrap right
If p2.y > p.Height - 5 Then p2.y = 10 'wrap bottom
If p2.y < 5 Then p2.y = p.Height - 10 'wrap top
If kp(14) And (canshoot2 < 1) Then 'if player 2 shooting key is pressed, if the bomb is charged and theres no other bomb around
canshoot2 = h2.delay 'start charging another bomb
sh2(jz).x = h2.posx(h2.dir, h2.w) 'create the bomb at the end of cannon
sh2(jz).y = h2.posy(h2.dir, h2.h) '||
sh2(jz).speed = 3 * speed2 + 3 'set the bomb speed
sh2(jz).dir = h2.dir 'bomb direction = cannon direction
If AI Then sh2(jz).dir -= 5
If AI Then sh2(jz).dir += 10 * Rnd()
sh2(jz).exist = True 'IT'S ALIVE!
jz += 1
If jz > 10 Then jz = 0
End If
If p1.dir > 360 Then p1.dir = 0
If p1.dir < 0 Then p1.dir = 360
If p2.dir > 360 Then p2.dir = 0
If p2.dir < 0 Then p2.dir = 360
If h1.dir > 360 Then h1.dir = 0
If h1.dir < 0 Then h1.dir = 360
If h2.dir > 360 Then h2.dir = 0
If h2.dir < 0 Then h2.dir = 360
ReDim p1.pt(3) 'the main square of player 1 ship
p1.sp(1, p1.posx(p1.posx(p1.dir, p1.w / 2), p1.dir + 90, p1.h / 4), p1.posy(p1.posy(p1.dir, p1.h / 2), p1.dir + 90, p1.w / 4))
p1.sp(0, p1.posx(p1.posx(p1.dir, p1.w / 2), p1.dir - 90, p1.h / 4), p1.posy(p1.posy(p1.dir, p1.h / 2), p1.dir - 90, p1.w / 4))
p1.sp(2, p1.posx(p1.posx(p1.dir + 180, p1.w / 2), p1.dir + 90, p1.h / 4), p1.posy(p1.posy(p1.dir + 180, p1.h / 2), p1.dir + 90, p1.w / 4))
p1.sp(3, p1.posx(p1.posx(p1.dir + 180, p1.w / 2), p1.dir - 90, p1.h / 4), p1.posy(p1.posy(p1.dir + 180, p1.h / 2), p1.dir - 90, p1.w / 4))
ReDim pt.p1front(3) 'detail on player 1 front
pt.sp_p1front(0, p1.posx(p1.posx(p1.dir, p1.w / 2.3), p1.dir + 90, p1.h / 4.5), p1.posy(p1.posy(p1.dir, p1.h / 2.3), p1.dir + 90, p1.w / 4.5))
pt.sp_p1front(1, p1.posx(p1.posx(p1.dir, p1.w / 2.3), p1.dir - 90, p1.h / 4.5), p1.posy(p1.posy(p1.dir, p1.h / 2.3), p1.dir - 90, p1.w / 4.5))
pt.sp_p1front(2, p1.posx(p1.posx(p1.dir, p1.w / 2.6), p1.dir - 90, p1.h / 4.2), p1.posy(p1.posy(p1.dir, p1.h / 2.6), p1.dir - 90, p1.w / 4.2))
pt.sp_p1front(3, p1.posx(p1.posx(p1.dir, p1.w / 2.6), p1.dir + 90, p1.h / 4.2), p1.posy(p1.posy(p1.dir, p1.h / 2.6), p1.dir + 90, p1.w / 4.2))
ReDim h1.pt(7) 'player 1 cannon
h1.sp(0, h1.posx(h1.posx(h1.dir, h1.w), h1.dir + 90, h1.h / 4), h1.posy(h1.posy(h1.dir, h1.h), h1.dir + 90, h1.w / 4))
h1.sp(1, h1.posx(h1.posx(h1.dir, h1.w), h1.dir - 90, h1.h / 4), h1.posy(h1.posy(h1.dir, h1.h), h1.dir - 90, h1.w / 4))
h1.sp(2, h1.posx(h1.posx(h1.dir, h1.w / 1.5), h1.dir - 90, h1.h / 4), h1.posy(h1.posy(h1.dir, h1.h / 1.5), h1.dir - 90, h1.w / 4))
h1.sp(3, h1.posx(h1.posx(h1.dir, h1.w / 1.5), h1.dir - 90, h1.h / 8), h1.posy(h1.posy(h1.dir, h1.h / 1.5), h1.dir - 90, h1.w / 8))
h1.sp(4, h1.posx(h1.posx(h1.dir, h1.w / 4), h1.dir - 90, h1.h / 8), h1.posy(h1.posy(h1.dir, h1.h / 4), h1.dir - 90, h1.w / 8))
h1.sp(5, h1.posx(h1.posx(h1.dir, h1.w / 4), h1.dir + 90, h1.h / 8), h1.posy(h1.posy(h1.dir, h1.h / 4), h1.dir + 90, h1.w / 8))
h1.sp(6, h1.posx(h1.posx(h1.dir, h1.w / 1.5), h1.dir + 90, h1.h / 8), h1.posy(h1.posy(h1.dir, h1.h / 1.5), h1.dir + 90, h1.w / 8))
h1.sp(7, h1.posx(h1.posx(h1.dir, h1.w / 1.5), h1.dir + 90, h1.h / 4), h1.posy(h1.posy(h1.dir, h1.h / 1.5), h1.dir + 90, h1.w / 4))
ReDim p2.pt(3) 'the main square of player 2 ship
p2.sp(1, p2.posx(p2.posx(p2.dir, p2.w / 2), p2.dir + 90, p2.h / 4), p2.posy(p2.posy(p2.dir, p2.h / 2), p2.dir + 90, p2.w / 4))
p2.sp(0, p2.posx(p2.posx(p2.dir, p2.w / 2), p2.dir - 90, p2.h / 4), p2.posy(p2.posy(p2.dir, p2.h / 2), p2.dir - 90, p2.w / 4))
p2.sp(2, p2.posx(p2.posx(p2.dir + 180, p2.w / 2), p2.dir + 90, p2.h / 4), p2.posy(p2.posy(p2.dir + 180, p2.h / 2), p2.dir + 90, p2.w / 4))
p2.sp(3, p2.posx(p2.posx(p2.dir + 180, p2.w / 2), p2.dir - 90, p2.h / 4), p2.posy(p2.posy(p2.dir + 180, p2.h / 2), p2.dir - 90, p2.w / 4))
ReDim pt.p2front(3) 'detail on player 2 ship body front
pt.sp_p2front(0, p2.posx(p2.posx(p2.dir, p2.w / 2.3), p2.dir + 90, p2.h / 4.5), p2.posy(p2.posy(p2.dir, p2.h / 2.3), p2.dir + 90, p2.w / 4.5))
pt.sp_p2front(1, p2.posx(p2.posx(p2.dir, p2.w / 2.3), p2.dir - 90, p2.h / 4.5), p2.posy(p2.posy(p2.dir, p2.h / 2.3), p2.dir - 90, p2.w / 4.5))
pt.sp_p2front(2, p2.posx(p2.posx(p2.dir, p2.w / 2.6), p2.dir - 90, p2.h / 4.2), p2.posy(p2.posy(p2.dir, p2.h / 2.6), p2.dir - 90, p2.w / 4.2))
pt.sp_p2front(3, p2.posx(p2.posx(p2.dir, p2.w / 2.6), p2.dir + 90, p2.h / 4.2), p2.posy(p2.posy(p2.dir, p2.h / 2.6), p2.dir + 90, p2.w / 4.2))
ReDim h2.pt(7) 'the cannon of player 2
h2.sp(0, h2.posx(h2.posx(h2.dir, h2.w), h2.dir + 90, h2.h / 4), h2.posy(h2.posy(h2.dir, h2.h), h2.dir + 90, h2.w / 4))
h2.sp(1, h2.posx(h2.posx(h2.dir, h2.w), h2.dir - 90, h2.h / 4), h2.posy(h2.posy(h2.dir, h2.h), h2.dir - 90, h2.w / 4))
h2.sp(2, h2.posx(h2.posx(h2.dir, h2.w / 1.5), h2.dir - 90, h2.h / 4), h2.posy(h2.posy(h2.dir, h2.h / 1.5), h2.dir - 90, h2.w / 4))
h2.sp(3, h2.posx(h2.posx(h2.dir, h2.w / 1.5), h2.dir - 90, h2.h / 8), h2.posy(h2.posy(h2.dir, h2.h / 1.5), h2.dir - 90, h2.w / 8))
h2.sp(4, h2.posx(h2.posx(h2.dir, h2.w / 4), h2.dir - 90, h2.h / 8), h2.posy(h2.posy(h2.dir, h2.h / 4), h2.dir - 90, h2.w / 8))
h2.sp(5, h2.posx(h2.posx(h2.dir, h2.w / 4), h2.dir + 90, h2.h / 8), h2.posy(h2.posy(h2.dir, h2.h / 4), h2.dir + 90, h2.w / 8))
h2.sp(6, h2.posx(h2.posx(h2.dir, h2.w / 1.5), h2.dir + 90, h2.h / 8), h2.posy(h2.posy(h2.dir, h2.h / 1.5), h2.dir + 90, h2.w / 8))
h2.sp(7, h2.posx(h2.posx(h2.dir, h2.w / 1.5), h2.dir + 90, h2.h / 4), h2.posy(h2.posy(h2.dir, h2.h / 1.5), h2.dir + 90, h2.w / 4))
If AI Then
If GUI.firingAIbox.Checked Then kp(14) = True
If GUI.movingAIbox.Checked Then kp(5) = True
Dim a As Integer = p2.ptAngle(p1)
If h2.dir > a And h2.dir < a + 90 Then
kp(8) = True
kp(7) = Not True
End If
If h2.dir < a And h2.dir > a - 90 Then
kp(7) = True
kp(8) = Not True
End If
If h2.dir > a + 90 And h2.dir < a + 180 Then
kp(8) = True
kp(7) = Not True
End If
If h2.dir < a - 90 And h2.dir > a - 180 Then
kp(7) = True
kp(8) = Not True
End If
For i As Integer = 0 To 10
If sh1(i).exist And GUI.evasionAIbox.Checked Then
If p2.ptDistance(sh1(i)) < 300 Then
kp(5) = True
Dim b As Double = p2.ptAngle(sh1(i))
If p2.dir - a > -90 And p2.dir + a < 90 Then
If b > a Then
kp(8) = True
kp(7) = Not True
Else
kp(7) = True
kp(8) = Not True
End If
Else
If b > a Then
kp(7) = True
kp(8) = Not True
Else
kp(8) = True
kp(7) = Not True
End If
End If
End If
Else
If Not GUI.movingAIbox.Checked Then kp(5) = Not True
End If
Next
h2.dir = h2.ptAngle(p1) 'aim at you always =D
' i could do a movement foreseener, so it would aim at where you'll be when you try to evade.
' but i won't.
' =D
If p2.ptDistance(p1) < 300 And GUI.fearAIbox.Checked Then p2.dir = p2.ptAngle(p1) - 180
End If
For i As Integer = 0 To 10
If sh1(i).exist Then 'player 1 SHoot
sh1(i).x = sh1(i).posx(sh1(i).dir, sh1(i).speed)
sh1(i).y = sh1(i).posy(sh1(i).dir, sh1(i).speed) 'move
If sh1(i).x < 0 Or sh1(i).x > p.Width Then sh1(i).exist = False
If sh1(i).y < 0 Or sh1(i).y > p.Height Then sh1(i).exist = False 'destroy if is out of bounds
g.FillEllipse(Brushes.Azure, CSng(sh1(i).x - sh1(i).w / 2), CSng(sh1(i).y - sh1(i).h / 2), CSng(sh1(i).w), CSng(sh1(i).h))
If sh1(i).hitTest(p2) Then
blow1 = 1
sh1(i).exist = False
blow1x = sh1(i).x
blow1y = sh1(i).y
p2.x = p2.posx(p2.ptAngle(sh1(i)), -10)
p2.y = p2.posy(p2.ptAngle(sh1(i)), -10)
p2.hp -= (power1 * 2 + 5)
End If
End If
If sh2(i).exist Then 'same for player 2 shoot
sh2(i).x = sh2(i).posx(sh2(i).dir, sh2(i).speed)
sh2(i).y = sh2(i).posy(sh2(i).dir, sh2(i).speed) 'move
If sh2(i).x < 0 Or sh2(i).x > p.Width Then sh2(i).exist = False
If sh2(i).y < 0 Or sh2(i).y > p.Height Then sh2(i).exist = False 'destroy instead of wrap
g.FillEllipse(Brushes.LightSalmon, CSng(sh2(i).x - sh2(i).w / 2), CSng(sh2(i).y - sh2(i).h / 2), CSng(sh2(i).w), CSng(sh2(i).h))
If sh2(i).hitTest(p1) Then
blow2 = 1
sh2(i).exist = False
blow2x = sh2(i).x
blow2y = sh2(i).y
p1.x = p1.posx(p1.ptAngle(sh2(i)), -10)
p1.y = p1.posy(p1.ptAngle(sh2(i)), -10)
p1.hp -= (power2 * 2 + 5)
End If
End If
Next
g.FillPolygon(Brushes.BlueViolet, p1.pt) 'P1 body
g.FillPolygon(Brushes.MediumSeaGreen, pt.p1front) 'P1 front detail
g.FillPolygon(Brushes.Azure, h1.pt) 'P1 cannon
g.FillEllipse(Brushes.Azure, CSng(h1.x - h1.w / 2), CSng(h1.y - h1.h / 2), CSng(h1.w), CSng(h1.h)) 'the ball from where cannon cames out
g.FillPolygon(Brushes.IndianRed, p2.pt) 'same for P2
g.FillPolygon(Brushes.Coral, pt.p2front)
g.FillPolygon(Brushes.LightSalmon, h2.pt) 'colors change
g.FillEllipse(Brushes.LightSalmon, CSng(h2.x - h2.w / 2), CSng(h2.y - h2.h / 2), CSng(h2.w), CSng(h2.h))
If GUI.CheckBox1.Checked Then
g.DrawRectangle(Pens.Gainsboro, CSng(p1.x - p1.w / 2), CSng(p1.y - p1.h / 1.5), CSng(p1.w), CSng(p1.h / 5))
g.DrawRectangle(Pens.Gainsboro, CSng(p2.x - p2.w / 2), CSng(p2.y - p2.h / 1.5), CSng(p2.w), CSng(p2.h / 5))
g.FillRectangle(Brushes.Green, CSng(p1.x - p1.w / 2), CSng(p1.y - p1.h / 1.5), CSng(p1.w * p1.hp / 100), CSng(p1.h / 5))
g.FillRectangle(Brushes.Green, CSng(p2.x - p2.w / 2), CSng(p2.y - p2.h / 1.5), CSng(p2.w * p2.hp / 100), CSng(p2.h / 5))
End If
If blow1 = 1 Then
g.DrawEllipse(Pens.Azure, blow1x - 50, blow1y - 50, 100, 100)
g.FillEllipse(Brushes.Azure, blow1x - 10, blow1y - 10, 20, 20)
blow1 += 1
ElseIf blow1 = 2 Then
g.DrawEllipse(Pens.Azure, blow1x - 110, blow1y - 110, 220, 220)
g.FillEllipse(Brushes.Azure, blow1x - 25, blow1y - 25, 50, 50)
blow1 += 1
ElseIf blow1 = 3 Then
g.FillEllipse(Brushes.Azure, blow1x - 45, blow1y - 45, 90, 90)
blow1 += 1
ElseIf blow1 = 4 Then
g.FillEllipse(Brushes.Azure, blow1x - 80, blow1y - 80, 160, 160)
g.FillEllipse(Brushes.Black, blow1x - 60, blow1y - 60, 120, 120)
blow1 += 1
ElseIf blow1 = 5 Then
g.DrawEllipse(Pens.Azure, blow1x - 100, blow1y - 100, 200, 200)
blow1 = 0
End If
If blow2 = 1 Then
g.DrawEllipse(Pens.LightSalmon, blow2x - 30, blow2y - 30, 60, 60)
g.FillEllipse(Brushes.LightSalmon, blow2x - 10, blow2y - 10, 20, 20)
blow2 += 1
ElseIf blow2 = 2 Then
g.DrawEllipse(Pens.LightSalmon, blow2x - 60, blow2y - 60, 120, 120)
g.FillEllipse(Brushes.LightSalmon, blow2x - 25, blow2y - 25, 50, 50)
blow2 += 1
ElseIf blow2 = 3 Then
g.FillEllipse(Brushes.LightSalmon, blow2x - 45, blow2y - 45, 90, 90)
blow2 += 1
ElseIf blow2 = 4 Then
g.FillEllipse(Brushes.LightSalmon, blow2x - 80, blow2y - 80, 160, 160)
g.FillEllipse(Brushes.Black, blow2x - 60, blow2y - 60, 120, 120)
blow2 += 1
ElseIf blow2 = 5 Then
g.DrawEllipse(Pens.LightSalmon, blow2x - 100, blow2y - 100, 200, 200)
blow2 = 0
End If
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
p.Location = New Point(0, 0)
p.Size = Me.Size
g = p.CreateGraphics
End Sub
End Class
----------------------------------------------------
Public Class GUI
Dim p1p As Integer = 15, p2p As Integer = 15
Dim g1, g2 As Graphics
Function update()
ptlbl1.Text = "Player 1: " & p1p
ptlbl2.Text = "Player 2: " & p2p
g1.Clear(Color.White)
g2.Clear(Color.White)
Dim pt As New obj
Dim mh As Integer = CSng(Panel1.Width / 2), mv As Integer = CSng(Panel1.Height / 2)
pt.x = mh
pt.y = mv
ReDim pt.pt(2)
pt.sp(0, pt.posx(180, pl1_pwBar.Value * 3 + 8), pt.posy(180, pl1_pwBar.Value * 3 + 8))
pt.sp(1, pt.posx(180 + 120, pl1_delayBar.Value * 3 + 8), pt.posy(180 + 120, pl1_delayBar.Value * 3 + 8))
pt.sp(2, pt.posx(180 + 240, pl1_fsBar.Value * 3 + 8), pt.posy(180 + 240, pl1_fsBar.Value * 3 + 8))
g1.FillPolygon(Brushes.Black, pt.pt)
pt.sp(0, pt.posx(180, pl2_pwBar.Value * 3 + 8), pt.posy(180, pl2_pwBar.Value * 3 + 8))
pt.sp(1, pt.posx(180 + 120, pl2_delayBar.Value * 3 + 8), pt.posy(180 + 120, pl2_delayBar.Value * 3 + 8))
pt.sp(2, pt.posx(180 + 240, pl2_fsBar.Value * 3 + 8), pt.posy(180 + 240, pl2_fsBar.Value * 3 + 8))
g2.FillPolygon(Brushes.Black, pt.pt)
End Function
Private Sub pl1_M_fs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_M_fs.Click
If p1p > 0 And pl1_fsBar.Value < 10 Then
p1p -= 1
pl1_fsBar.Value += 1
update()
End If
End Sub
Private Sub pl1_M_power_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_M_power.Click
If p1p > 0 And pl1_pwBar.Value < 10 Then
p1p -= 1
pl1_pwBar.Value += 1
update()
End If
End Sub
Private Sub pl2_M_firespeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_M_firespeed.Click
If p2p > 0 And pl2_fsBar.Value < 10 Then
p2p -= 1
pl2_fsBar.Value += 1
update()
End If
End Sub
Private Sub pl2_M_delay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_M_delay.Click
If p2p > 0 And pl2_delayBar.Value < 10 Then
p2p -= 1
pl2_delayBar.Value += 1
update()
End If
End Sub
Private Sub pl2_M_power_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_M_power.Click
If p2p > 0 And pl2_pwBar.Value < 10 Then
p2p -= 1
pl2_pwBar.Value += 1
update()
End If
End Sub
Private Sub pl2_L_power_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_L_power.Click
If p2p < 15 And pl2_pwBar.Value > 0 Then
p2p += 1
pl2_pwBar.Value -= 1
update()
End If
End Sub
Private Sub pl2_L_delay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_L_delay.Click
If p2p < 15 And pl2_delayBar.Value > 0 Then
p2p += 1
pl2_delayBar.Value -= 1
update()
End If
End Sub
Private Sub pl2_L_fireSpd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl2_L_fireSpd.Click
If p2p < 15 And pl2_fsBar.Value > 0 Then
p2p += 1
pl2_fsBar.Value -= 1
update()
End If
End Sub
Private Sub pl1_L_pw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_L_pw.Click
If p1p < 15 And pl1_pwBar.Value > 0 Then
p1p += 1
pl1_pwBar.Value -= 1
update()
End If
End Sub
Private Sub pl1_L_delau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_L_delau.Click
If p1p < 15 And pl1_delayBar.Value > 0 Then
p1p += 1
pl1_delayBar.Value -= 1
update()
End If
End Sub
Private Sub pl1_L_fs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_L_fs.Click
If p1p < 15 And pl1_fsBar.Value > 0 Then
p1p += 1
pl1_fsBar.Value -= 1
update()
End If
End Sub
Private Sub pl1_M_delay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pl1_M_delay.Click
If p1p > 0 And pl1_delayBar.Value < 10 Then
p1p -= 1
pl1_delayBar.Value += 1
update()
End If
End Sub
Private Sub OKbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKbtn.Click
Form1.power1 = pl1_pwBar.Value
Form1.power2 = pl2_pwBar.Value
Form1.delay1 = 10 - pl1_delayBar.Value
Form1.delay2 = 10 - pl2_delayBar.Value
Form1.speed1 = pl1_fsBar.Value
Form1.speed2 = pl2_fsBar.Value
Form1.Show()
End Sub
Private Sub GUI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
g1 = Panel1.CreateGraphics
g2 = Panel2.CreateGraphics
update()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
pl1_pwBar.Value = 0
pl1_delayBar.Value = 0
pl1_fsBar.Value = 0
p1p = 15
update()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
pl2_pwBar.Value = 0
pl2_delayBar.Value = 0
pl2_fsBar.Value = 0
p2p = 15
update()
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment