Imports System.IO
Public Class frmArena1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContai
ner
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents picMoney As System.Windows.Forms.PictureB
ox
Friend WithEvents picRedMechCollision As System.Windows.Forms.PictureB
ox
Friend WithEvents imlRedMech As System.Windows.Forms.ImageLis
t
Friend WithEvents tmrMove As System.Windows.Forms.Timer
Friend WithEvents pnlLevel As System.Windows.Forms.Panel
Friend WithEvents lblHealthRed As System.Windows.Forms.Label
Friend WithEvents lblHealthGreen As System.Windows.Forms.Label
Friend WithEvents picCollisionMask As System.Windows.Forms.PictureB
ox
Friend WithEvents tmrGameClock As System.Windows.Forms.Timer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureB
ox
Friend WithEvents picGraphicMask As System.Windows.Forms.PictureB
ox
Friend WithEvents picRedMech As System.Windows.Forms.PictureB
ox
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerSt
epThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Contain
er
Dim resources As System.Resources.ResourceMana
ger = New System.Resources.ResourceMana
ger(GetType(frmArena1))
Me.pnlLevel = New System.Windows.Forms.Panel
Me.picRedMech = New System.Windows.Forms.PictureB
ox
Me.picGraphicMask = New System.Windows.Forms.PictureB
ox
Me.Label2 = New System.Windows.Forms.Label
Me.picCollisionMask = New System.Windows.Forms.PictureB
ox
Me.picMoney = New System.Windows.Forms.PictureB
ox
Me.picRedMechCollision = New System.Windows.Forms.PictureB
ox
Me.imlRedMech = New System.Windows.Forms.ImageLis
t(Me.components)
Me.tmrMove = New System.Windows.Forms.Timer(Me.components)
Me.tmrGameClock = New System.Windows.Forms.Timer(Me.components)
Me.lblHealthRed = New System.Windows.Forms.Label
Me.lblHealthGreen = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.PictureBox1 = New System.Windows.Forms.PictureB
ox
Me.pnlLevel.SuspendLayout()
Me.SuspendLayout()
'
'pnlLevel
'
Me.pnlLevel.BackColor = System.Drawing.Color.White
Me.pnlLevel.BorderStyle = System.Windows.Forms.BorderSt
yle.Fixed3D
Me.pnlLevel.Controls.Add(Me.picRedMech)
Me.pnlLevel.Controls.Add(Me.picGraphicMask)
Me.pnlLevel.Controls.Add(Me.Label2)
Me.pnlLevel.Controls.Add(Me.picCollisionMask)
Me.pnlLevel.Controls.Add(Me.picMoney)
Me.pnlLevel.Controls.Add(Me.picRedMechCollision)
Me.pnlLevel.Location = New System.Drawing.Point(0, 0)
Me.pnlLevel.Name = "pnlLevel"
Me.pnlLevel.Size = New System.Drawing.Size(480, 480)
Me.pnlLevel.TabIndex = 3
'
'picRedMech
'
Me.picRedMech.BackColor = System.Drawing.Color.Transpar
ent
Me.picRedMech.Image = CType(resources.GetObject("picRedMech.Image"), System.Drawing.Image)
Me.picRedMech.Location = New System.Drawing.Point(192, 224)
Me.picRedMech.Name = "picRedMech"
Me.picRedMech.Size = New System.Drawing.Size(16, 16)
Me.picRedMech.TabIndex = 15
Me.picRedMech.TabStop = False
'
'picGraphicMask
'
Me.picGraphicMask.BackColor = System.Drawing.Color.Transpar
ent
Me.picGraphicMask.BackgroundI
mage = CType(resources.GetObject("picGraphicMask.BackgroundImag
e"), System.Drawing.Image)
Me.picGraphicMask.Image = CType(resources.GetObject("picGraphicMask.Image"), System.Drawing.Image)
Me.picGraphicMask.Location = New System.Drawing.Point(0, 0)
Me.picGraphicMask.Name = "picGraphicMask"
Me.picGraphicMask.Size = New System.Drawing.Size(480, 480)
Me.picGraphicMask.TabIndex = 14
Me.picGraphicMask.TabStop = False
'
'Label2
'
Me.Label2.BackColor = System.Drawing.Color.White
Me.Label2.Location = New System.Drawing.Point(248, 128)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 48)
Me.Label2.TabIndex = 12
Me.Label2.Text = "Label2"
'
'picCollisionMask
'
Me.picCollisionMask.BackColor = System.Drawing.Color.Transpar
ent
Me.picCollisionMask.Image = CType(resources.GetObject("picCollisionMask.Image"), System.Drawing.Image)
Me.picCollisionMask.Location = New System.Drawing.Point(0, 0)
Me.picCollisionMask.Name = "picCollisionMask"
Me.picCollisionMask.Size = New System.Drawing.Size(480, 480)
Me.picCollisionMask.TabIndex = 9
Me.picCollisionMask.TabStop = False
Me.picCollisionMask.Visible = False
'
'picMoney
'
Me.picMoney.Image = CType(resources.GetObject("picMoney.Image"), System.Drawing.Image)
Me.picMoney.Location = New System.Drawing.Point(-80, 16)
Me.picMoney.Name = "picMoney"
Me.picMoney.Size = New System.Drawing.Size(80, 32)
Me.picMoney.TabIndex = 0
Me.picMoney.TabStop = False
'
'picRedMechCollision
'
Me.picRedMechCollision.BackCo
lor = System.Drawing.Color.Transpar
ent
Me.picRedMechCollision.Locati
on = New System.Drawing.Point(32, 32)
Me.picRedMechCollision.Name = "picRedMechCollision"
Me.picRedMechCollision.Size = New System.Drawing.Size(16, 16)
Me.picRedMechCollision.TabInd
ex = 5
Me.picRedMechCollision.TabSto
p = False
Me.picRedMechCollision.Visibl
e = False
'
'imlRedMech
'
Me.imlRedMech.ImageSize = New System.Drawing.Size(16, 16)
Me.imlRedMech.ImageStream = CType(resources.GetObject("imlRedMech.ImageStream"), System.Windows.Forms.ImageLis
tStreamer)
Me.imlRedMech.TransparentColo
r = System.Drawing.Color.Brown
'
'tmrMove
'
Me.tmrMove.Enabled = True
Me.tmrMove.Interval = 5
'
'tmrGameClock
'
Me.tmrGameClock.Enabled = True
Me.tmrGameClock.Interval = 1
'
'lblHealthRed
'
Me.lblHealthRed.BackColor = System.Drawing.Color.DarkRed
Me.lblHealthRed.Location = New System.Drawing.Point(8, 488)
Me.lblHealthRed.Name = "lblHealthRed"
Me.lblHealthRed.Size = New System.Drawing.Size(100, 16)
Me.lblHealthRed.TabIndex = 4
'
'lblHealthGreen
'
Me.lblHealthGreen.BackColor = System.Drawing.Color.Green
Me.lblHealthGreen.Location = New System.Drawing.Point(8, 488)
Me.lblHealthGreen.Name = "lblHealthGreen"
Me.lblHealthGreen.Size = New System.Drawing.Size(100, 16)
Me.lblHealthGreen.TabIndex = 5
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(192, 512)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(184, 16)
Me.Label1.TabIndex = 6
Me.Label1.Text = "-65281 = Magenta"
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(368, 528)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(2, 2)
Me.PictureBox1.TabIndex = 11
Me.PictureBox1.TabStop = False
'
'frmArena1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(594, 560)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lblHealthGreen)
Me.Controls.Add(Me.lblHealthRed)
Me.Controls.Add(Me.pnlLevel)
Me.Controls.Add(Me.PictureBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBord
erStyle.FixedToolWindow
Me.Name = "frmArena1"
Me.StartPosition = System.Windows.Forms.FormStar
tPosition.CenterScreen
Me.TransparencyKey = System.Drawing.Color.Transpar
ent
Me.pnlLevel.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim RedMoveUp As Boolean = False
Dim RedMoveDown As Boolean = False
Dim RedMoveLeft As Boolean = False
Dim RedMoveRight As Boolean = False
Dim RedHealth As Integer = 100
Dim RedSpeed As Integer = 2
Dim RedPowerup As Integer = 0
Dim RedBackground As Bitmap
Dim RedX As Integer = 0
Dim RedY As Integer = 0
Dim tempVar As String = ""
Dim PixelColor As Color
Dim CollisionMask As Bitmap
Dim GraphicsMask As Bitmap
Dim fromrect As New Rectangle
Dim torect As New Rectangle
Dim fromcopy As New Bitmap(picGraphicMask.Image)
Dim topaste As New Bitmap(picGraphicMask.Image)
Dim gr As Graphics = Graphics.FromImage(topaste)
Private Function Collide(ByVal ObjA As Object, ByVal ObjB As Object) As Boolean
If ObjA.bounds.intersectswith(ObjB.bounds) Then
Collide = True
Else
Collide = False
End If
End Function
'Private Function NotCollideWithWall() As Boolean
' NotCollideWithWall = True
' PixelColor = CollisionMask.GetPixel(RedX + 33, RedY + 0)
' If PixelColor.ToArgb <> -1 Then
' NotCollideWithWall = False
' End If
' PixelColor = CollisionMask.GetPixel(RedX - 1, RedY + 0)
' If PixelColor.ToArgb <> -1 Then
' NotCollideWithWall = False
' End If
' PixelColor = CollisionMask.GetPixel(RedX + 0, RedY + 33)
' If PixelColor.ToArgb <> -1 Then
' NotCollideWithWall = False
' End If
' PixelColor = CollisionMask.GetPixel(RedX + 0, RedY - 1)
' If PixelColor.ToArgb <> -1 Then
' NotCollideWithWall = False
' End If
'End Function
Private Function NotCollideWithWallUp() As Boolean
NotCollideWithWallUp = True
PixelColor = CollisionMask.GetPixel(RedX + 0, RedY - RedSpeed)
If PixelColor.ToArgb = -65281 Then
NotCollideWithWallUp = False
End If
End Function
Private Function NotCollideWithWallDown() As Boolean
NotCollideWithWallDown = True
PixelColor = CollisionMask.GetPixel(RedX + 0, RedY + RedSpeed + 15)
If PixelColor.ToArgb = -65281 Then
NotCollideWithWallDown = False
End If
End Function
Private Function NotCollideWithWallLeft() As Boolean
NotCollideWithWallLeft = True
PixelColor = CollisionMask.GetPixel(RedX - RedSpeed, RedY + 0)
If PixelColor.ToArgb = -65281 Then
NotCollideWithWallLeft = False
End If
End Function
Private Function NotCollideWithWallRight() As Boolean
NotCollideWithWallRight = True
PixelColor = CollisionMask.GetPixel(RedX + RedSpeed + 15, RedY + 0)
If PixelColor.ToArgb = -65281 Then
NotCollideWithWallRight = False
End If
End Function
Private Sub frmArena1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEvent
Args) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
picRedMechCollision.Left = picRedMech.Left + (RedSpeed)
If NotCollideWithWallRight() = True And picRedMech.Left + picRedMech.Width < pnlLevel.Width - 2 Then
RedMoveRight = True
RedMoveLeft = False
RedMoveUp = False
RedMoveDown = False
picRedMech.Image = imlRedMech.Images(1)
End If
End If
If e.KeyCode = Keys.Left Then
picRedMechCollision.Left = picRedMech.Left - (RedSpeed)
If NotCollideWithWallLeft() = True And picRedMech.Left > 2 Then
RedMoveRight = False
RedMoveLeft = True
RedMoveUp = False
RedMoveDown = False
picRedMech.Image = imlRedMech.Images(0)
End If
End If
If e.KeyCode = Keys.Up Then
picRedMechCollision.Top = picRedMech.Top - (RedSpeed)
If NotCollideWithWallUp() = True And picRedMech.Top > 2 Then
RedMoveRight = False
RedMoveLeft = False
RedMoveUp = True
RedMoveDown = False
picRedMech.Image = imlRedMech.Images(2)
End If
End If
If e.KeyCode = Keys.Down Then
picRedMechCollision.Top = picRedMech.Top + (RedSpeed)
If NotCollideWithWallDown() = True And picRedMech.Top + picRedMech.Height < pnlLevel.Height - 2 Then
RedMoveRight = False
RedMoveLeft = False
RedMoveUp = False
RedMoveDown = True
picRedMech.Image = imlRedMech.Images(3)
End If
End If
If e.KeyCode = Keys.NumPad1 Then
RedSpeed += 1
End If
If e.KeyCode = Keys.NumPad0 Then
RedSpeed -= 1
End If
End Sub
Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
If RedMoveUp Then
picRedMechCollision.Top = picRedMech.Top - (RedSpeed)
If NotCollideWithWallUp() = True And picRedMech.Top > 2 Then
picRedMech.Top = picRedMech.Top - RedSpeed
End If
End If
If RedMoveDown Then
picRedMechCollision.Top = picRedMech.Top + (RedSpeed)
If NotCollideWithWallDown() = True And picRedMech.Top + picRedMech.Height < pnlLevel.Height - 2 Then
picRedMech.Top = picRedMech.Top + RedSpeed
End If
End If
If RedMoveLeft Then
picRedMechCollision.Left = picRedMech.Left - (RedSpeed)
If NotCollideWithWallLeft() = True And picRedMech.Left > 2 Then
picRedMech.Left = picRedMech.Left - RedSpeed
End If
End If
If RedMoveRight Then
picRedMechCollision.Left = picRedMech.Left + (RedSpeed)
If NotCollideWithWallRight() = True And picRedMech.Left + picRedMech.Width < pnlLevel.Width - 2 Then
picRedMech.Left = picRedMech.Left + RedSpeed
End If
End If
picRedMechCollision.Top = picRedMech.Top
picRedMechCollision.Left = picRedMech.Left
End Sub
Private Sub frmArena1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEvent
Args) Handles MyBase.KeyUp
If e.KeyCode = Keys.Right Then
RedMoveRight = False
End If
If e.KeyCode = Keys.Left Then
RedMoveLeft = False
End If
If e.KeyCode = Keys.Up Then
RedMoveUp = False
End If
If e.KeyCode = Keys.Down Then
RedMoveDown = False
End If
End Sub
Private Sub tmrGameClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGameClock.Tick
RedX = picRedMech.Left
RedY = picRedMech.Top
fromrect.X = RedX
fromrect.Y = RedY
fromrect.Width = 16
fromrect.Height = 16
'
http://www.vb-helper.com/howto_net_drawimage_copy_part.html - gr.DrawImage
gr.DrawImage(topaste, fromrect.X, fromrect.Y)
RedBackground = picRedMech.Image
RedBackground.Clone()
picRedMech.BackgroundImage = topaste
End Sub
Private Sub frmArena1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CollisionMask = picCollisionMask.Image
GraphicsMask = picGraphicMask.Image
End Sub
Private Sub picCollisionMask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCollisionMask.Click
End Sub
Private Sub picRedMech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub picRedMech_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picRedMech.Click
End Sub
Private Sub picGraphicMask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picGraphicMask.Click
End Sub
End Class