Public Class Form1
Inherits System.Windows.Forms.Form
Dim pac1, pac2 As Bitmap
Dim pac As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\open.bmp")
Dim vijand2 As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\vijand2.bmp")
Dim vijand As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\vijand.bmp")
Dim Laser As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\laser.bmp")
Dim torpedo As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\torpedo.bmp")
Dim plof As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\plof.bmp")
Dim dood As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\dood.bmp")
Dim door1 As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\door1.bmp")
Dim door2 As Bitmap = System.Drawing.Bitmap.FromFile("c:\pacman\door2.bmp")
Dim a As Integer = 0
Dim q As Integer = 0
'H staat voor horizontaal en V voor vertikaal
Dim H, V, H2, V2, oldh, oldv, VijandH, vijand2V, TH, TV, TTH, TTV As Integer
Dim bots As Boolean = False
Dim richtingV As Boolean = False
Dim richtingV2 As Boolean
Dim t, oldt As String
Dim Paclaser As Boolean = False
Dim doodhuh As Boolean = False
Dim doodhuh2 As Boolean = False
Protected Overrides Sub onpaint(ByVal e As System.windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim pen As Pen = New Pen(Color.Blue, 2)
g.DrawLine(pen, 50, 100, 50, 300) 'muur1
g.DrawLine(pen, 50, 0, 50, 50) 'muur2
g.DrawLine(pen, 50, 50, 150, 50) 'muur3
g.DrawLine(pen, 100, 150, 100, 200) 'muur4
g.DrawLine(pen, 150, 100, 300, 100) 'muur5
g.DrawLine(pen, 100, 150, 250, 150) 'muur6
g.DrawLine(pen, 100, 250, 100, 300) 'muur7
g.DrawLine(pen, 150, 200, 150, 250) 'muur8
g.DrawLine(pen, 150, 200, 200, 200) 'muur9
g.DrawLine(pen, 150, 250, 200, 250) 'muur10
g.DrawLine(pen, 200, 200, 200, 250) 'muur11
g.DrawLine(pen, 200, 0, 200, 100) 'muur12
g.DrawLine(pen, 250, 200, 250, 300) 'muur13
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pac1 = System.Drawing.Bitmap.FromFile("c:\pacman\open.bmp")
pac2 = System.Drawing.Bitmap.FromFile("c:\pacman\dicht.bmp")
PBvijand1.Image = vijand
PBvijand1.Location = New System.Drawing.Point(150, 125)
PBvijand2.Image = vijand2
PBvijand2.Location = New System.Drawing.Point(120, 175)
PBdoor1.Location = New System.Drawing.Point(240, 140)
PBdoor1.Image = door1
PBlaser.Image = Laser
Laser.MakeTransparent()
vijand.MakeTransparent()
vijand2.MakeTransparent()
pac1.MakeTransparent()
pac2.MakeTransparent()
plof.MakeTransparent()
dood.MakeTransparent()
door1.MakeTransparent()
door2.MakeTransparent()
focus.Focus()
H = 20
V = 150
VijandH = 125
vijand2V = 175
torpedo.MakeTransparent()
PBtorpedo.Image = torpedo
PBtorpedo.Visible = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim z As Integer
z += 1
a += 1
If a = 1 Then pac = pac1
If a = 2 Then pac = pac2
If a = 2 Then a = 0
PBpacman.Image = pac
Invalidate()
End Sub
Private Sub focus_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles focus.LostFocus
focus.Focus()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
TXTtest.Text = "V= " & CStr(V) & "V2= " & CStr(V2)
TXTtest2.Text = "H= " & CStr(H) & "H2= " & CStr(H2)
If botsing() = False Then
PBpacman.Location = New System.Drawing.Point(H, V)
Else
If t = oldt Then
Else
botsing()
PBpacman.Location = New System.Drawing.Point(H, V)
End If
End If
If vijand1_dood() = False Then
If richtingvijand1() = False Then
VijandH += 1
End If
If richtingvijand1() = True Then
VijandH -= 1
End If
End If
If vijand2_dood() = False Then
If richtingvijand2() = False Then
vijand2V += 1
End If
If richtingvijand2() = True Then
vijand2V -= 1
End If
End If
vijand1_dood()
PBvijand1.Location = New System.Drawing.Point(VijandH, 115)
PBvijand2.Location = New System.Drawing.Point(120, vijand2V)
If vuur = False Then PBtorpedo.Location = New System.Drawing.Point(H, V)
If vuur = True Then PBtorpedo.Location = New System.Drawing.Point(oldh + TH, oldv + TV)
TTH = oldh + TH
TTV = oldv + TV
End Sub
Public draai1 As Integer = 1
Public vuur As Boolean = False
Private Function vijand1_dood()
If vuur = True And TTH < VijandH + 15 And TTH > VijandH - 15 And TTV > 108 And TTV < 123 Then PBvijand1.Image = dood : doodhuh = True
Return doodhuh
End Function
Private Function vijand2_dood()
If vuur = True And TTH < 130 And TTH > 110 And TTV > vijand2V - 15 And TTV < vijand2V + 15 Then PBvijand2.Image = dood : doodhuh2 = True
Return doodhuh2
End Function
Private Function richtingvijand1()
PBvijand1.Image = vijand
If VijandH > 250 Then richtingV = True : vijand.RotateFlip(RotateFlipType.RotateNoneFlipX)
If VijandH < 120 Then richtingV = False : vijand.RotateFlip(RotateFlipType.RotateNoneFlipX)
Return richtingV
End Function
Private Function richtingvijand2()
If vijand2V > 280 Then richtingV2 = True
If vijand2V < 170 Then richtingV2 = False
Return richtingV2
End Function
Private Function botsing()
If (H = 50 And V > 81 And V < 300) Or _
(H2 = 50 And V > 81 And V < 300) Or _
(H2 = 50 And V > 0 And V < 50) Or _
(H = 50 And V > 0 And V < 50) Or _
(H2 > 50 And H < 150 And V = 50) Or _
(H2 > 50 And H < 150 And V2 = 48) Or _
(H = 100 And V2 > 150 And V < 200) Or _
(H2 = 100 And V2 > 150 And V < 200) Or _
(H2 > 150 And H < 300 And V = 100) Or _
(H2 > 150 And H < 300 And V2 = 98) Or _
(H2 > 100 And H < 250 And V2 = 150) Or _
(H2 > 100 And H < 250 And V = 150) Or _
(H2 > 150 And H < 200 And V2 = 200) Or _
(H2 > 150 And H < 200 And V = 200) Or _
(H2 > 150 And H < 200 And V2 = 250) Or _
(H2 > 150 And H < 200 And V = 250) Or _
(H = 100 And V2 > 250 And V < 300) Or _
(H2 = 100 And V2 > 250 And V < 300) Or _
(H = 150 And V2 > 200 And V < 250) Or _
(H2 = 150 And V2 > 200 And V < 250) Or _
(H = 200 And V2 > 200 And V < 250) Or _
(H2 = 200 And V2 > 200 And V < 250) Or _
(H = 200 And V2 > 0 And V < 100) Or _
(H2 = 200 And V2 > 0 And V < 100) Or _
(H = 250 And V2 > 200 And V < 300) Or _
(H2 = 250 And V2 > 200 And V < 300) Then
bots = True
Else
bots = False
End If
If (H2 > 0 And H < 50 And V < 50) Then
pacman_got_laser()
End If
Return bots
End Function
Private Function pacman_got_laser()
pac1 = System.Drawing.Bitmap.FromFile("c:\pacman\openL.bmp")
pac2 = System.Drawing.Bitmap.FromFile("c:\pacman\dichtL.bmp")
pac1.MakeTransparent()
pac2.MakeTransparent()
rotL = 0
rotR = 1
rotD = 0
rotU = 0
PBlaser.Visible = False
Paclaser = True
End Function
Private Function botsing_torp()
stop_plof.Enabled = True
End Function
Private Sub focus_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles focus.KeyDown
t = focus.Text
If botsing() = True And t = oldt Then
Else
Select Case t
Case "z"
V -= 1
If rotU = 0 Then pacman_boven()
Case "s"
V += 1
If rotD = 0 Then pacman_onder()
Case "d"
H += 1
If rotR = 0 Then pacman_rechts()
Case "q"
H -= 1
If rotL = 0 Then pacman_links()
Case "f"
If Paclaser = True Then
If vuur = False Then
PBtorpedo.Image = torpedo
Pacman_vuur.Enabled = True
RotRoud = rotR : Rotloud = rotL : RotDoud = rotD : RotUoud = rotU
oldh = H : oldv = V
End If
End If
End Select
End If
H2 = H + 23
V2 = V + 23
botsing()
oldt = t
focus.Clear()
End Sub
Public rotL As Integer = 0
Public rotR As Integer = 1
Public rotU As Integer = 0
Public rotD As Integer = 0
Dim Rotloud, RotRoud, RotDoud, RotUoud As Integer
Public Function pacman_links()
If rotU = 0 And rotD = 0 And rotR = 1 Then
pac1.RotateFlip(RotateFlipType.Rotate180FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate180FlipNone)
End If
If rotU = 1 And rotD = 0 And rotR = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate270FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
If rotU = 0 And rotD = 1 And rotR = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate90FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate90FlipNone)
End If
rotL = 1
rotR = 0
rotD = 0
rotU = 0
End Function
Public Function pacman_rechts()
If rotU = 0 And rotD = 0 And rotL = 1 Then
pac1.RotateFlip(RotateFlipType.Rotate180FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate180FlipNone)
End If
If rotU = 0 And rotD = 1 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate270FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
If rotU = 1 And rotD = 0 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate90FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate90FlipNone)
End If
rotL = 0
rotR = 1
rotD = 0
rotU = 0
End Function
Public Function pacman_onder()
If rotU = 1 And rotD = 0 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate180FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate180FlipNone)
End If
If rotU = 0 And rotR = 0 And rotL = 1 Then
pac1.RotateFlip(RotateFlipType.Rotate270FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
If rotU = 0 And rotR = 1 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate90FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate90FlipNone)
End If
rotL = 0
rotR = 0
rotD = 1
rotU = 0
End Function
Public Function pacman_boven()
If rotD = 1 And rotR = 0 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate180FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate180FlipNone)
End If
If rotD = 0 And rotR = 0 And rotL = 1 Then
pac1.RotateFlip(RotateFlipType.Rotate90FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate90FlipNone)
End If
If rotD = 0 And rotR = 1 And rotL = 0 Then
pac1.RotateFlip(RotateFlipType.Rotate270FlipNone)
pac2.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
rotL = 0
rotR = 0
rotD = 0
rotU = 1
End Function
Dim kans As Integer = 0
Private Sub Pacman_vuur_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pacman_vuur.Tick
If kans = 0 Then
PBtorpedo.Visible = True
vuur = True
If RotRoud = 1 Then TH += 3
If Rotloud = 1 Then TH -= 3
If RotUoud = 1 Then TV -= 3
If RotDoud = 1 Then TV += 3
If TH > 150 Or TH < (-150) Or TV < (-150) Or TV > 150 Then
vuur = False : PBtorpedo.Visible = False : Pacman_vuur.Enabled = False
kans += 1
stop_plof.Enabled = True
End If
End If
If kans = 1 Then PBtorpedo.Visible = False : kans += 1 : Pacman_vuur.Enabled = False
If kans = 2 Then kans = 0
End Sub
Dim ploftijd As Integer = 0
Private Sub stop_plof_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stop_plof.Tick
If ploftijd = 1 Then PBtorpedo.Visible = False
ploftijd = 0 : stop_plof.Enabled = False : TH = 0 : TV = 0 : vuur = False
Pacman_vuur.Enabled = False
ploftijd += 1
End Sub
Public doorklap As Integer = 0
Private Sub Deur_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Deur.Tick
doorklap += 1
If doorklap = 1 Then PBdoor1.Image = door1
If doorklap = 2 Then PBdoor1.Image = door2 : doorklap = 0
End Sub
End Class