Results 1 to 9 of 9

Thread: C# Samples I would like to see

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    C# Samples I would like to see

    OK if any of you guys are going to be playing around with C# and are looking for some ideas. I drew up a list of game programming 101 topics. I'm having a hard time making any headway with C#. I think if someone could just break it up into individual files that each do a simple thing, then from those basic building blocks you can pretty much do most any game application:


    Make a dot

    Make dot move every time you hit the enter key using a simple loop

    1. Draw new dot each time refreshing the screen

    2. Keep adding dots to existing canvas

    Make a game loop which exits when you hit the Esc key

    Make dot move using arrow keys

    Make it so when dot exits on right side of screen it enters again on the left

    Make it so dot cannot go beyond edge of screen

    Make a square room for dot

    Make dot move around at 45 degree angles and bounce off walls like in Pong

    Make a rectangle paddle and make it move left and right using mouse

    Add collision to paddle

    Make game fill screen

    OK now let's think Space Invaders:
    Change the paddle to a 2D sprite of a spaceship

    Change the dot to 2D animated sprite monster

    Make the ship fire dots every time you click the mouse or hit the spacebar

    Make it so when dot hit's monster,it adds a point to score displayed on screen

    Make monster display an explosion graphic and disappear when hit

    Now think Pac Man:
    Player has 3 lives. Every time a monster touches player, the game halts and you have to start over. After 3 fails, display the end screen with final score and give the option to play again.

    Now, make level 1 with 1 monster, level 2 has 2 monsters, level 3 etc...
    each time you complete a level you get a congratulations screen.

    Add sounds. Exploding monster, firing gun, looping soundtrack.

    Create a high scores list. Allow user to enter their name if they make the top 10.

    Now let's think 3D:

    Make a cube

    1. Rotate cube in x or y using mouse

    2. Rotate camera around cube using mouse

    Make a 3D room with the camera positioned above the room looking down.
    Add textures to walls.
    Add tiled texture to floor.

    Add a teapot and apply a generic color

    Now think Tanks:
    Make the teapot rotate using the left and right arrow keys and move forward using the up arrow key.
    Make the teapot fire a ball when you hit a mouse button or hit the space bar
    Create explosion effect when ball hits wall or object.
    Draw graphic on wall where ball hits.
    Add parablic curve to ball trajectory to simulate gravity.
    Add colored cube Ammo Pickup and give the teapot an Ammo Limit.
    Make pickups appear periodically in random locations.
    Add assorted color obstacles using various DirectX primitives.

    Basic AI
    Make a colored cone with the point facing forward to indicate the front.
    Make the cone a zombie: randomly wandering about, bumping into walls.
    Make a different color zombie. This one still wanders aimlessly, but avoids walls and obstacles.
    Make another color cone which follows you wherever you go.
    Make another color cone which will follow you only if you are within it's field of vision.
    Make another which will only attack if you are within a certain range.
    Make an enemy that shoots back at you.

    Make enemies which will spawn duplicates of themselves if you don't shoot them within a certain amount of time.

    Replace teapot with mesh model
    Make model play an animation when moving forward / shooting

    Make the camera follow the model
    Make objects which get between camera and model transparent
    Make option to switch between First Person and camera views

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    Draw a Dot using C#

    I looked all over but I couldn't find a command to draw a simple dot in C#. The best I could figure out was to draw a 1 X 1 rectangle:

    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace Draw_Dot
    {
        public partial class DrawDot : Form
        {
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new DrawDot());
            }
            protected override void OnPaint(PaintEventArgs pe)
            {
                Rectangle rect = new Rectangle(50, 30, 1, 1);
                SolidBrush lBrush = new SolidBrush(Color.Black);
                pe.Graphics.FillRectangle(lBrush, rect);
            }
    
    
        }
    }
    Last edited by musicalglass; Feb 15th, 2006 at 05:07 PM. Reason: only worked with Visual C# before

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: C# Samples I would like to see

    You could use Set Pixel. It's slow but if you're only drawing 1 pixel, it might work well for you.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# Samples I would like to see

    Drawing a dot is just a degenerate state. I'd think the simplest way would be to just DrawLine with the start and end points the same.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: C# Samples I would like to see

    Quote Originally Posted by jmcilhinney
    Drawing a dot is just a degenerate state. I'd think the simplest way would be to just DrawLine with the start and end points the same.
    If I recall correctly, Drawline won't display anything if the start and end points are the same. I think you can use the pointf overload though with a very, very small line.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    talk talk talk

    Don't just talk about it guys.
    If you think you know another way to do it,
    SHOW ME SOME SAMPLES

  7. #7
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: C# Samples I would like to see

    Or, you could look on MSDN for any of the three methods given, which all show examples.

    SetPixel only works with a bitmap object, so that's more complicated (and slower) than your method, possibly.

    jmcilhinney's idea:
    Code:
    protected override void OnPaint(PaintEventArgs pe)
            {
               // Graphics g = pe.Graphics;//Get rid of this
                pe.Graphics.DrawLine(Pens.Black, 50,30,50,30);
            }
    My idea, using pointf overload is only just that - an idea, I'm not sure if it'll work.

    Code:
    protected override void OnPaint(PaintEventArgs pe)
            {
                // Graphics g = pe.Graphics;//Get rid of this
                pe.Graphics.DrawLine(Pens.Black, 50.0F, 30.0F, 50.1F, 30.1F);
            }
    The best way, if you're setting lots of pixels, is to look into the LockBits method, which requires understanding how to copy pixel data to byte arrays in memory, then manipulate them, then copy the byte arrays back. The examples on MSDN are better than anything I could whip up without alot of coding and testing.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    Make a Dot using C# simplified

    Suggestion 1 gave a blank screen.
    Suggestion 2 worked fine.

    As does this:
    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace Draw_Dot
    {
        public partial class DrawDot : Form
        {
    
    
            protected override void OnPaint(PaintEventArgs pe)
            {
                pe.Graphics.DrawLine(Pens.Black, 50, 30, 50.1F, 30.1F);
            }
    
    
        }
    }
    Thank you, That is exactly what I wanted. You trimmed away the unecessary bits and now I have the bare bones minimum example. Very much appreciated.

    Now who can show me how to make Dot move using a simple while loop? ( event based )
    Last edited by musicalglass; Feb 2nd, 2006 at 04:48 PM. Reason: shortened code even further

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    5

    Make Dot Move?

    OK, so if this were a console app I could just use Console.Read () to make the loop pause. That doesn't seem to work with a form. How do I pause the action in this loop to wait for say, the user to press any key?

    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace Draw_Dot
    {
        public partial class DrawDot : Form
        {
            float x_coords = 50.0F ; 
            float y_coords = 30.0F ; 
            int i = 0 ; 
    
                    protected override void OnPaint(PaintEventArgs pe)
                    {
                        while (i < 1)
                        {
    
                            x_coords = (x_coords + 0.1F);
                            y_coords = (y_coords + 0.1F); 
    
                    Console.ReadLine();
                    pe.Graphics.DrawLine(Pens.Black, x_coords, y_coords, ( x_coords + 0.1F), (y_coords + 0.1F));
                       }
                    }
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width