Click here to Skip to main content
14,297,239 members

Game with planes in C#

Rate this:
1.07 (18 votes)
Please Sign up or sign in to vote.
1.07 (18 votes)
10 Jun 2007CDDL
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)

Share

About the Author

Ionescu Marius
Web Developer
Romania Romania
Programming in all language.

Comments and Discussions

 
QuestionWhere have all the articles gone? Pin
jconwell11-Jun-07 5:26
memberjconwell11-Jun-07 5:26 
We seem to get more and more "articles" with nothing but a bunch of code dumped on this site. Code without any context is nothing. Write an article; what are you trying to solve, how do you do it, how did you come up with it, where could you go with it? That kind of stuff.

Just dumping a pile of code on a web page is fairly useless.

John Conwell

AnswerRe: Where have all the articles gone? Pin
Ionescu Marius11-Jun-07 6:34
memberIonescu Marius11-Jun-07 6:34 
GeneralGood Effort Pin
Moim Hossain10-Jun-07 4:54
memberMoim Hossain10-Jun-07 4:54 
GeneralRe: Good Effort Pin
Ben Daniel10-Jun-07 22:12
memberBen 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.

Article
Posted 10 Jun 2007

Stats

23.9K views
491 downloads
11 bookmarked