开发者

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 knowled开发者_C百科ge in C# is needed?


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.


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


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.


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.


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.


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.


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#?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜