Imports System.Math
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
' " Windows Form Designer generated code "
Private _Up As Boolean = False
Private _Down As Boolean = False
Private _Right As Boolean = True
Private _Left As Boolean = False
Private a As Integer = 64
Private b As Integer = 48
Private z, m, k, l, p As Integer
Private W As Integer
Private walls(30) As Rectangle
Dim cookie(12) As Rectangle
Dim X_ As Integer = 64
Dim Y_ As Integer = 48
Dim oldsquares(1000) As Point
Dim oldsquaresS(1000) As Rectangle
Dim Segments As Integer = 8
Dim LIVES As Integer = 5
Dim SCORE As Integer
Dim SPEED As Integer = 8
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Level1()
End Sub
Sub Level1()
Panel1.Width = 480
Panel1.Height = 320
Dim g As Graphics = Panel1.CreateGraphics
Dim Gpen As New Pen(Color.FromArgb(255, 100, 255, 100), 1)
Dim GBrush As New SolidBrush(Color.FromArgb(150, 50, 255, 50))
'LEFT OUTER wall
walls(1) = New Rectangle(0, 0, 5, 80)
walls(2) = New Rectangle(0, 120, 5, 140)
walls(3) = New Rectangle(0, 300, 5, 20)
'UPPER OUTER wall
walls(4) = New Rectangle(0, 0, Panel1.Width - 140, 5)
walls(5) = New Rectangle(Panel1.Width - 100, 0, Panel1.Width, 5)
'LOWER OUTER wall
walls(6) = New Rectangle(0, Panel1.Height - 10, Panel1.Width - 140, 5)
walls(7) = New Rectangle(Panel1.Width - 100, Panel1.Height - 10, Panel1.Width, 5)
'RIGHT OUTER wall
walls(8) = New Rectangle(Panel1.Width - 10, 0, 5, 80)
walls(9) = New Rectangle(Panel1.Width - 10, 120, 5, 140)
walls(10) = New Rectangle(Panel1.Width - 10, 300, 5, 20)
'LOWER RIGHT wall
walls(11) = New Rectangle(296, 232, 89, 5) '---
walls(12) = New Rectangle(Panel1.Width - 100, 232, 5, 96) '|
'RIGHT wall
walls(13) = New Rectangle(Panel1.Width - 120, 120, 120, 5) '---
walls(14) = New Rectangle(Panel1.Width - 100, 180, 100, 5) ' --
'UPPER RIGHT wall
walls(15) = New Rectangle(Panel1.Width - 100, 0, 5, 72) ' |
'LEFT wall
walls(16) = New Rectangle(0, 120, 140, 5) ' -----
walls(17) = New Rectangle(70, 60, 5, 60) ' |
'UPPER wall
walls(18) = New Rectangle(164, 0, 5, 96) ' |
'MIDDLE RIGHT wall
walls(19) = New Rectangle(300, 60, 5, 120) ' |
walls(20) = New Rectangle(220, 140, 80, 5) ' --
walls(21) = New Rectangle(220, 100, 5, 40) '|
'MIDDLE LEFT wall
walls(22) = New Rectangle(178, 140, 5, 100) ' |
walls(23) = New Rectangle(60, 180, 5, 90) '----
walls(24) = New Rectangle(60, 180, 118, 5) '|
walls(25) = New Rectangle(60, 250, 78, 5) '--
'LOWER wall
walls(26) = New Rectangle(250, 200, 5, 120) ' |
'DRAW WALLS
For z = 1 To 26
g.FillRectangle(GBrush, walls(z))
g.DrawRectangle(Gpen, walls(z))
Next
'COOKIES yay!
cookie(1) = New Rectangle(130, 24, 6, 6)
cookie(2) = New Rectangle(190, 32, 6, 6)
cookie(3) = New Rectangle(420, 16, 6, 6)
cookie(4) = New Rectangle(240, 124, 6, 6)
cookie(5) = New Rectangle(280, 160, 6, 6)
cookie(6) = New Rectangle(440, 140, 6, 6)
cookie(7) = New Rectangle(20, 240, 6, 6)
cookie(8) = New Rectangle(80, 230, 6, 6)
cookie(9) = New Rectangle(230, 280, 6, 6)
cookie(10) = New Rectangle(265, 300, 6, 6)
cookie(11) = New Rectangle(270, 280, 6, 6)
cookie(12) = New Rectangle(480, 240, 6, 6)
'DRAW COOKIES
For z = 1 To 12
g.FillEllipse(New SolidBrush(Color.FromArgb(255, 100, 0, 100)), cookie(z))
g.DrawEllipse(Pens.Yellow, cookie(z))
Next
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim strKeyPress As String = Nothing
strKeyPress = e.KeyCode.ToString()
Select Case strKeyPress.ToUpper()
Case "UP"
If _Down = False Then
_Up = True
_Down = False
_Right = False
_Left = False
End If
Case "DOWN"
If _Up = False Then
_Up = False
_Down = True
_Right = False
_Left = False
End If
Case "RIGHT"
If _Left = False Then
_Up = False
_Down = False
_Right = True
_Left = False
End If
Case "LEFT"
If _Right = False Then
_Up = False
_Down = False
_Right = False
_Left = True
End If
Case "ENTER"
resetvalues()
End Select
End Sub
Private Sub Caterpillar_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Caterpillar.Tick
Dim G As Graphics = Panel1.CreateGraphics
Dim CPen As New Pen(Color.Red, 1)
p += 1
If _Up = True Then
oldsquares(p) = New Point(X_, Y_)
Y_ -= SPEED
G.FillEllipse(New SolidBrush(Color.FromArgb(150, 200, 50, 50)), X_, Y_, 6, 10)
G.DrawEllipse(CPen, X_, Y_, 8, 8)
End If
If _Down = True Then
oldsquares(p) = New Point(X_, Y_)
Y_ += SPEED
G.FillEllipse(New SolidBrush(Color.FromArgb(150, 200, 50, 50)), X_, Y_, 6, 10)
G.DrawEllipse(CPen, X_, Y_, 8, 8)
End If
If _Left = True Then
oldsquares(p) = New Point(X_, Y_)
X_ -= SPEED
G.FillEllipse(New SolidBrush(Color.FromArgb(150, 200, 50, 50)), X_, Y_, 6, 10)
G.DrawEllipse(CPen, X_, Y_, 8, 8)
End If
If _Right = True Then
oldsquares(p) = New Point(X_, Y_)
X_ += SPEED
G.FillEllipse(New SolidBrush(Color.FromArgb(150, 200, 50, 50)), X_, Y_, 6, 10)
G.DrawEllipse(CPen, X_, Y_, 8, 8)
End If
If X_ <= -1 Then
X_ = Panel1.Width
End If
If X_ >= Panel1.Width + 1 Then
X_ = -8
End If
If Y_ <= -1 Then
Y_ = Panel1.Height
End If
If Y_ >= Panel1.Height + 1 Then
Y_ = -8
End If
Dim mp_ As New Point(X_, Y_)
Dim size_ As New Size(8, 8)
Dim Newrect As New Rectangle(mp_, size_)
Dim intcounter As Integer
For l = 1 To p
oldsquaresS(l) = New Rectangle(oldsquares(l), size_)
Next
For z = 1 To p
If Newrect.IntersectsWith(oldsquaresS(z)) Then
ResetValues()
LIVES -= 1
If LIVES = 0 Then
GameOver()
End If
End If
Next
For z = 1 To 26
If Newrect.IntersectsWith(walls(z)) Then
ResetValues()
LIVES -= 1
If LIVES = 0 Then
GameOver()
End If
End If
Next
For z = 1 To 12
If Newrect.IntersectsWith(cookie(z)) Then
G.FillRectangle(Brushes.Black, cookie(z))
SCORE += 1
Segments += 2
If SCORE = 12 Then
LevelComplete()
End If
End If
Next
If p >= 8 Then
For l = 1 To p - 8
oldsquaresS(p - Segments).Size = New Size(8, 9)
G.FillRectangle(Brushes.Black, oldsquaresS(p - Segments))
G.DrawRectangle(Pens.Black, oldsquaresS(p - Segments))
oldsquares.Clear(oldsquares, p - Segments, 1)
oldsquaresS.Clear(oldsquaresS, p - Segments, 1)
Next
End If
End Sub
Private Sub Panel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.Click
W += 1
If W = 1 Then
Panel1.Refresh()
Level1()
Caterpillar.Enabled = True
End If
If W = 2 Then
Caterpillar.Enabled = False
W = 0
Panel1.Refresh()
X_ = 64
Y_ = 48
_Right = True
_Left = False
_Up = False
_Down = False
End If
End Sub
Sub ResetValues()
Caterpillar.Enabled = False
W = 0
p = 0
oldsquares.Clear(oldsquares, 0, 1000)
oldsquaresS.Clear(oldsquaresS, 0, 1000)
Panel1.Refresh()
Level1()
X_ = 64
Y_ = 48
_Right = True
_Left = False
_Up = False
_Down = False
End Sub
Sub LevelComplete()
Dim g As Graphics = Panel1.CreateGraphics
Dim font_ As New Font("Courier New", 72, FontStyle.Bold, GraphicsUnit.Display)
Dim Brush_ As New HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.Red, Color.Yellow)
Panel1.Refresh()
'Level2()
g.DrawString(" Level 1 Complete ", font_, Brush_, 200, 160)
End Sub
Sub GameOver()
Dim g As Graphics = Panel1.CreateGraphics
Dim font_ As New Font("Times New Roman", FontStyle.Bold, GraphicsUnit.Display)
Dim Brush_ As New HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.Red, Color.DarkRed)
Panel1.Refresh()
g.DrawString(" Game Over ", font_, Brush_, 200, 160)
End Sub
End Class