using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace PFCTour
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class PFMain : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
Graphics gfx; // Draws to the backbuffer.
Graphics formgfx; // Draws to the form.
Bitmap backbuffer; // Empty bitmap.
bool updateartwork; // Determines if we need to redraw everything. Set this to true to redraw.
const int themapwidth = 800;
const int themapheight = 600;
private System.Windows.Forms.Timer clock;
// 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 int thelandheight = 568;
// 600 - 32 = 568... I like 32.
// Constants are good for you.
public PFMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
// Windows Form Designer generated code
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new PFMain());
}
private void PFMain_Load(object sender, System.EventArgs e)
{
// Setup clock interval.
clock.Interval = 100;
clock.Enabled = true;
this.Size = new Size(themapwidth + 8, themapheight + 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(themapwidth, themapheight);
// gfx is aimed at the backbuffer.
gfx = Graphics.FromImage(backbuffer);
// formgfx is aimed at the form.
formgfx = this.CreateGraphics();
// Make our drawing when the timer ticks.
updateartwork = true;
}
private void clock_Tick(object sender, System.EventArgs e)
{
if (updateartwork)
{
/* 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, themapwidth, thelandheight));
// And the remainder of the area is theland, starting from thelandheight.
gfx.FillRectangle(Brushes.ForestGreen, Rectangle.FromLTRB(0, thelandheight, themapwidth, themapheight));
// 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.
}
this.drawonform();
}
private void drawonform()
{
formgfx.DrawImage(backbuffer, 0, 0);
// The backbuffer was drawn on by the gfx.
}
private void PFMain_Paint(object sender, PaintEventArgs e)
{
updateartwork = true;
}
}
} |