How do I make a circle to move in C #?

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

+2


source to share


7 replies


You should check out Microsoft's XNA Game Studio . This is a version of Visual Studio specifically designed for writing games. You are using C # but you get a lot of things for free - graphics, sound, time ...



Here is a tutorial on creating a ball in XNA.

+5


source


The simplest way would be to move your circle a small amount with each tick of the timer control.



+4


source


Good for a simple single-player game, for example, 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 like what does a map look like? Where are the walls? Can you go from one end to the other? How is the map drawn?

GDI is used in C # for drawing. This uses the Graphics context . You will find many examples on the Internet and I would suggest checking the BobPowell.Net GDI + FAQ to avoid some common mistakes.

+2


source


If you want to learn a new language, avoid all the fuss and just look at the most important parts.

Knowledge of previous programming languages ​​helps a lot, especially if one of them is Java.

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

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

After you have your form and a PictureBox or two, and you beat the Event system, take a look at other fundamental parts of .NET that make your life easier. Properties, Generics, Data Sources and more.

+2


source


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

Just download studio, install, then start Visual Studio C # (my Express Edition).

So, when you launch, you create a new game project on Windows, and you've created your first game.

It is good to read some books and articles about XNA.

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

+1


source


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

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

      

Radius

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

+1


source


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

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

0


source







All Articles