Introduction
It's a simple game with planes using a timer tick component.
Background
Using the code
I use 2 class avion and fire with the reference object. Position of each plane have his coordinates.
p = new Avion();
f = new Fire();
p.x = 60;
p.y = 180;
p.x1 = 780;
p.y1 = 180;
p.x2 = 670;
p.y2 = 384;
p.x3 = 760;
p.y3 = 282;
p.x4 = 690;
p.y4 = 100;
When i pressed the arrow key:
if (e.KeyCode == Keys.Escape)
Close();
switch (e.KeyValue)
{
case 38:
p.y = p.y - 2;
break;
case 40:
p.y = p.y + 2;
break;
case 37:
p.x = p.x - 2;
break;
case 39:
p.x = p.x + 2;
break;
case 32:
f.xline = p.x + 30;
f.yline = p.y;
DrawMode = 2;
TimerMode = 2;
break;
case 90:
this.timer1.Enabled = false;
break;
case 88:
this.timer1.Enabled = true;
break;
}
Refresh();
Function override OnPaint:
Bitmap avion1 = new Bitmap("avion1.png");
Bitmap avion2 = new Bitmap("avion2.png");
Bitmap fire = new Bitmap("fire.png");
switch (DrawMode)
{
case 1:
{
e.Graphics.DrawImage(avion1, p.x, p.y, 35, 35);
e.Graphics.DrawImage(avion2, p.x1, p.y1, 35, 35);
e.Graphics.DrawImage(avion2, p.x2, p.y2, 35, 35);
e.Graphics.DrawImage(avion2, p.x3, p.y3, 35, 35);
e.Graphics.DrawImage(avion2, p.x4, p.y4, 35, 35);
break;
}
case 2:
{
.............................
In the Timer Tick function:
switch (TimerMode)
{
case 1:
{
p.x1 -= 1;
p.x2 -= 1;
p.x3 -= 1;
p.x4 -= 1;
break;
}
case 2:
.....................................
Points of Interest
A sample game usefull for an intermediate programmer :)
History
First version with extension in the future ... All ze best :)