Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#
Article

Game with planes in C#

Rate me:
Please Sign up or sign in to vote.
1.07/5 (19 votes)
10 Jun 2007CDDL 26.1K   529   11   4
Nice game with planes

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; //sus

                    break;
                case 40:
                    p.y = p.y + 2; //jos   

                    break;
                case 37:
                    p.x = p.x - 2; //stanga
                    break;
                case 39:
                    p.x = p.x + 2; //dreapta
                    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 :)

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Web Developer
Romania Romania
Programming in all language.

Comments and Discussions

 
QuestionWhere have all the articles gone? Pin
jconwell11-Jun-07 5:26
jconwell11-Jun-07 5:26 
AnswerRe: Where have all the articles gone? Pin
Ionescu Marius11-Jun-07 6:34
Ionescu Marius11-Jun-07 6:34 
GeneralGood Effort Pin
Moim Hossain10-Jun-07 4:54
Moim Hossain10-Jun-07 4:54 
GeneralRe: Good Effort Pin
Ben Daniel10-Jun-07 22:12
Ben Daniel10-Jun-07 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.