user53670
user53670

Reputation:

How to make a circle to move in C#?

I want to write a simple game like pacman in C# in order to learn the new language. However, I don't know how to make a circle move? Which part of knowledge in C# is needed?

Upvotes: 3

Views: 3537

Answers (7)

Ian
Ian

Reputation: 34489

Well, for a simple single player game like that, some of the most important things you need to know about are data structures and GDI.

Data structures are important because you need to store information such as what does a map look like? Where are the walls? Can you go from one end to the other? How does the map draw itself?

GDI is used in C# to draw. This uses the Graphics context. You'll find lots of examples online, and I'd suggest checking out BobPowell.Net GDI+ FAQ to avoid some of the common mistakes.

Upvotes: 2

Filip Ekberg
Filip Ekberg

Reputation: 36287

If you want to learn a new language stay away from all fuss and just look into the most essential parts.

Having knowledge about previous programming languages helps a lot, espesially if one of those are Java.

You don't need to look into XNA for this, all you really do need is to Start Visual Studio, create a new Windows Form, drag over an PictureBox and start playing with the KeyEvents.

Your game does not have to be awesome for you to learn the very basics of C# and .NET. And you certainly don't need to dig down in the deep jungle of XNA!

Once you have your form up and running with a PictureBox or two and you have conqured the Event-system, take a look at the other fundamental parts of .NET that makes your life easier. Properties, Generics, Data Sources and much much more.

Upvotes: 2

Toad
Toad

Reputation: 15925

if you mean how to move an object around in a circular movement, then you just need math knowledge:

 int circlePosX = centerX + Math.Cos(degrees) * radius;
 int circlePosY = centerY + Math.Sin(degrees) * radius;

radius is here how big you want the circle to be, and degrees is the position ion the circle the object is moving.

Upvotes: 1

MusiGenesis
MusiGenesis

Reputation: 75296

Here's an answer to a question about a radar-type game that demonstrates generally how to do this in C#/WinForms using GDI+ (with a sample and source code):

What would be the best way to simulate Radar in C#?

Upvotes: 0

mauris
mauris

Reputation: 43619

You probably want to look into XNA - http://creators.xna.com/

Simply download the studio, install, then run Visual Studio C# (mine is Express Edition).

So when you run, you create a new Windows Game Project and you've created your first game.

Good to read up some books and articles on XNA.

Book: Microsoft XNA Game Studio 2.0: Learn Programming Now! by Rob Miles.

Upvotes: 1

Galwegian
Galwegian

Reputation: 42227

The simplest way would be to move your circle a small bit with every tick of a timer control.

Upvotes: 4

bzlm
bzlm

Reputation: 9727

You should check out XNA Game Studio from Microsoft. It's a version of Visual Studio that's targetted especially for writing games. You use C# but get a lot of things for free - graphics, sound, timing...

Here's a tutorial for making a ball move in XNA.

Upvotes: 6

Related Questions