Imports System.Drawing
Public Class PFMain
Inherits System.Windows.Forms.Form
Dim GFX As Graphics 'Draws to the backbuffer.
Dim FormGFX As Graphics ' Draws to the form.
Dim Backbuffer As Bitmap 'Empty bitmap.
Dim UpdateArtwork As Boolean 'Determines if we need to redraw everything. Set this to true to redraw.
Const MAPWIDTH As Integer = 800
Const MAPHEIGHT As Integer = 600
'I need to determine a default spot for my land.
'It has to be between 0 and MAPHEIGHT, since that's the height of my backbuffer.
'Preferably closer to 600 as more land equals less playing area.
Const LANDHEIGHT As Integer = 568
'600 - 32 = 568... I like 32.
'Constants are good for you.
'Windows Form Designer Generated Code
Private Sub PFMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Setup our clock interval.
Clock.Interval = 100
Clock.Enabled = True
Me.Size = New Size(MAPWIDTH + 8, MAPHEIGHT + 24)
'Create the backbuffer. This will hold the map information... what you actually will see, because I
'am going to draw it to the form in one fell swoop. Just that I'm going to be drawing onto the backbuffer
'for all of my miscellaneous artworks, and then draw everything that I accumulated onto this backbuffer to the
'form. :)
Backbuffer = New Bitmap(MAPWIDTH, MAPHEIGHT)
'GFX is aimed at the backbuffer.
GFX = Graphics.FromImage(Backbuffer)
'FormGFX is aimed at the form.
FormGFX = Me.CreateGraphics()
'Make our drawing when the timer ticks.
UpdateArtwork = True
End Sub
Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
If UpdateArtwork Then
'I am going to draw a lightblue rectangle for the sky.
'It will go down until it reaches the land, so therefore the bottom of the rectangle has to be
'the LANDHEIGHT.
GFX.FillRectangle(Brushes.LightSkyBlue, Rectangle.FromLTRB(0, 0, MAPWIDTH, LANDHEIGHT))
'And the remainder of the area is LAND, starting from LANDHEIGHT.
GFX.FillRectangle(Brushes.ForestGreen, Rectangle.FromLTRB(0, LANDHEIGHT, MAPWIDTH, MAPHEIGHT))
'I use LTRB instead of New so that I don't have to calculate the height.
'These two will make the 'background' for the form.
UpdateArtwork = False
'Set it back to false.
Debug.WriteLine("Drawn")
End If
Me.DrawOnForm()
'Me.Invalidate(New Rectangle(0, 0, 1, 1))
End Sub
Private Sub DrawOnForm()
FormGFX.DrawImage(Backbuffer, 0, 0)
'The backbuffer was drawn on by the GFX.
End Sub
Private Sub PFMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
UpdateArtwork = True
End Sub
End Class
|