Click here to Skip to main content
Licence CDDL
First Posted 10 Jun 2007
Views 11,324
Downloads 203
Bookmarked 11 times

Game with planes in C#

By | 10 Jun 2007 | Article
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)

About the Author

Ionescu Marius

Web Developer

Romania Romania

Member

Programming in all language.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhere have all the articles gone? Pinmemberjconwell5:26 11 Jun '07  
AnswerRe: Where have all the articles gone? PinmemberIonescu Marius6:34 11 Jun '07  
GeneralGood Effort PinmemberMoim Hossain4:54 10 Jun '07  
GeneralRe: Good Effort PinmemberBen Daniel22:12 10 Jun '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 10 Jun 2007
Article Copyright 2007 by Ionescu Marius
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid