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?
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#?
Related
I'm working on small WPF desktop app to track a robot. I have a Kinect for Windows on my desk and I was able to do the basic features and run the Depth camera stream and the RGB camera stream.
What I need is to track a robot on the floor but I have no idea where to start. I found out that I should use EMGU (OpenCV wrapper)
What I want to do is track a robot and find it's location using the depth camera. Basically, it's for localization of the robot using Stereo Triangulation. Then using TCP and Wifi to send the robot some commands to move him from one place to an other using both the RGB and Depth camera. The RGB camera will also be used to map the object in the area so that the robot can take the best path and avoid the objects.
The problem is that I have never worked with Computer Vision before and it's actually my first, I'm not stuck to a deadline and I'm more than willing to learn all the related stuff to finish this project.
I'm looking for details, explanation, hints, links or tutorials to achieve my need.
Thanks.
Robot localization is a very tricky problem and I myself have been struggling for months now, I can tell you what I have achieved But you have a number of options:
Optical Flow Based Odometery: (Also known as visual odometry):
Extract keypoints from one image or features (I used Shi-Tomashi, or cvGoodFeaturesToTrack)
Do the same for a consecutive image
Match these features (I used Lucas-Kanade)
Extract depth information from Kinect
Calculate transformation between two 3D point clouds.
What the above algorithm is doing is it is trying to estimate the camera motion between two frames, which will tell you the position of the robot.
Monte Carlo Localization: This is rather simpler, but you should also use wheel odometery with it.
Check this paper out for a c# based approach.
The method above uses probabalistic models to determine the robot's location.
The sad part is even though libraries exist in C++ to do what you need very easily, wrapping them for C# is a herculean task. If you however can code a wrapper, then 90% of your work is done, the key libraries to use are PCL and MRPT.
The last option (Which by far is the easiest, but the most inaccurate) is to use KinectFusion built in to the Kinect SDK 1.7. But my experiences with it for robot localization have been very bad.
You must read Slam for Dummies, it will make things about Monte Carlo Localization very clear.
The hard reality is, that this is very tricky and you will most probably end up doing it yourself. I hope you dive into this vast topic, and would learn awesome stuff.
For further information, or wrappers that I have written. Just comment below... :-)
Best
Not sure if is would help you or not...but I put together a Python module that might help.
http://letsmakerobots.com/node/38883#comments
I'm working on a project in C# using XNA. It would be useful to have a way to graph the value of certain variables in real time as the game is running. (Just for debugging, I don't want the graphs in the final project.)
This seems like something that has probably been done before, but I can't find anything other than this:
http://devmag.org.za/2011/02/09/using-graphs-to-debug-physics-ai-and-animation-effectively/
I'm willing to write my own system or use someone else's. If there is an existing released project, I'd like to find it so I don't have to reinvent the wheel. If not, what;s the best way to handle this?
Thanks!
You could probably write a pretty easy system using XNA.
You should have something very basic for plotting lines:
public void DrawLine(Point first, Point second);
Run this system on every frame to collect the variable's value. Keep track of previous value.
Draw a line between previous value to current value.
If the sampling frequency is high enough, you can get a pretty decent looking graph like this.
You could write the values you want to check in a csv file, then draw a graph with excel. Here's a tutorial on writing a csv file writer/parser in C#.
The XNA hasn't support for drawing single line/pixels to screen directly (need to pass through a SpriteBatch). The only thing else I can imagine of is using a texture2D and draw your graph's pixels on it. You'll have to keep the texture in front of the camera though, with some strange matrix magics of which I don't actually know much. :P
The Xen graphics API has this feature. It appears to be for some built in variables, such as FPS, but it's all open source so I suspect it will be easy to add graphs of your own: http://xen.codeplex.com/
EDIT
I just remembered that Farseer physics also has code to do this http://farseerphysics.codeplex.com/. It's probably easier to rip out than the Xen graphs.
I'm trying to implement a simple game - I've written a dial control but having trouble writing a on-screen thumbstick in Silverlight for Windows Phone - this would be a large circle - say 150px wide with a 25px circle which when held down moves round the centre much like a real thumbstick - like the Xbox 360 controller thumbsticks.
I'm finding creating this a little tricky - if there are any examples such as a Joystick one I can shrink down for example? Been trying to create something for ages and can't seem to figure it out - the centre circle is loaded from an Image and the Larger one too so it can be customised - getting the two to be within each other centred is the easy part!
As discussed, i'd suggest using XNA doing it since its considerably easier to do. With Mango you could combine XNA and Silverlight and therefore satisfy your needs for some Silverlight too.
Look at this example:
http://create.msdn.com/en-US/sample/touchthumbsticks
It shows how to easily create a thumbstick control. To restrict the area which you can touch, just create a new Rectangle at the position of the thumbstick with the size you desire and use the .Contains(...) overload to check if the position of the tap is inside it and then act accordingly (update the stick, or ignore input).
Check out the .Contains(...) function and its overloads:
http://msdn.microsoft.com/de-de/library/microsoft.xna.framework.rectangle.contains.aspx
I have learned that many programmers tend to stick to Silverlight for they think XNA is some kind of holy grail and is complex to program. It is not. It just needs a bit of getting used to, but you will surely enjoy the ride to XNA enlightment. I can tell, i did :) It's fun! Just trust a stranger on the internet!
If you need to stick to Silverlight and Pre-Mango, i fear i can offer nothing of value for you, and i fear you will suffer pain in trying to recreate the same functionality XNA already offers programmers for no charge.
So it has been a while since I have done any game programming in C#, but I have had a recent bug to get back into it, and I wanted some opinions on what configuration I should use.
I wanted to use C# as that is what I use for work, and have become vary familiar with. I have worked with both DirectX and OpenGL in the past, but mostly in 3D, but now I am interested in writing a 2D game with all vector graphics, something that resembles the look of Geometry Wars or the old Star Wars arcade game.
Key points I am interested in:
• Ease of use/implementation.
• Easy on memory. (I plan on having a lot going on at once)
• Looks good, I don't want curve to look pixelated.
• Maybe some nice effects like glow or particle.
I am open to any and all suggestions, maybe even something I have not thought of...
Thanks in advance!
If you're just starting out again and already have a C# background, why not try XNA? You'll definitely be able to leverage your C# skills here
http://creators.xna.com
http://creators.xna.com/en-US/downloads
I use SlimDX for C# graphics programming and I prefer it to XNA.
http://slimdx.org/
TBH it doesn't really matter what you use. OpenGL, SlimDX, or XNA. They'll all be about as complex (or not as the case may be) as each other.
You might consider using the Axiom engine, which is a C# port of Ogre3D. It's enough higher level that you can have it render your graphics via XNA or OpenGL with little or no change to your code. It can also handle keyboard and mouse input (which are normally separate -- e.g., via DirectInput on Windows or SDL on Linux).
You also might consider using TAO Framework which is OpenGL based and quite nice. But you have to write the 2D Engine all by yourself tho. It also works on Mono!
I create my OpenGL engine with a C# wrapper because I like C# a lot too. Sadly managed languages are very slow when it comes to graphics and that's why I always make my OpenGL part in C++, compile it as a DLL and get it from C# using interop. If you by any chance dislike DirectX than I suggest you stay away from XNA. Everybody I know is very dissapointed about it and switched back to C++(OpenGL) + C#.
Since you already know C# I'd use XNA or Unity. While there are faster languages and middlewares, they're probably plenty fast enough. Both frameworks would have the necessary features you require.
I'm making a turn-based top-down game in C#. The graphics requirements are pretty simple: it's entirely 2D, requires drawing some images taken from graphics files (perhaps rotating them first), line drawing to make a hex grid and the ability to place text at any position on the screen.
I'm wondering what the best API is for doing these graphics. Is XNA overkill for this, is there something more appropriate? Thanks (I have zero experience of graphics or game development in .net so don't be afraid to dumb-down any answers).
I'd recommend XNA for this. If you don't want some of the overhead of XNA, I've found SlimDX to be a very nice little framework. They also provide some basic game classes to make this type of thing easy.
Doing your drawing directly in WPF is also fairly easy, but more difficult to extend later. XNA and SlimDX give you access to shaders, very fine grained control of alpha blending, as well as the potential to easily extend portions into 3D later if needed.
I've used the Farseer Physics engine before which was pretty cool and extremely easy to pickup (I am an enterprise developer, not a game developer). It works for Silverlight so you could actually make your game web based. I would suggest silverlight or WPF for 2D.
http://www.codeplex.com/FarseerPhysics
I would recommend WPF. Loading your graphics and moving them around should be fairly easy. Since WPF also is vector based, your line drawing is straight forward.
XNA would be the next step. Great support for sprite graphics and also gives you access to shaders.
If it is as simple as it sounds, and not even real-time, maybe you don't need any of this stuff. Drawing a hex grid and some images should not be hard even without a game engine. Maybe WPF would be good for this.
Given your requirement you could just use plain C# and the GDI (for 2d rastering). However learning XNA is easy enough, and it'll serve you well once you decide to make a realtime game (2d or 3d) down the road. Either way have fun, and if XNA seems to complicated when your starting out, just drop back to GDI. Making games should be as fun as playing them :)
XNA sounds like a good choise (it will better than using DirectX SDK !! and it is quite easy to learn)
You can do this by just using classes inside the System.Drawing namespace. And XNA is certainly overkill for this type of stuff. Also you would introduse many dependencies for your small game which might be an unwanted thing for your gamers.
Check out Unity 3D - it's based on C# and it can be used for 2D. It might be overkill (including price), but for game development it's in general HUGE help.