|
-
Feb 1st, 2006, 07:56 PM
#1
Thread Starter
New Member
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
-
Feb 1st, 2006, 08:23 PM
#2
Thread Starter
New Member
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
-
Feb 1st, 2006, 08:26 PM
#3
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.
-
Feb 1st, 2006, 08:30 PM
#4
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.
-
Feb 2nd, 2006, 12:38 AM
#5
Re: C# Samples I would like to see
 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
-
Feb 2nd, 2006, 01:09 PM
#6
Thread Starter
New Member
talk talk talk
Don't just talk about it guys.
If you think you know another way to do it,
SHOW ME SOME SAMPLES
-
Feb 2nd, 2006, 04:08 PM
#7
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
-
Feb 2nd, 2006, 04:44 PM
#8
Thread Starter
New Member
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
-
Feb 2nd, 2006, 05:25 PM
#9
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|