2D game programming tutorials in C# - c#

I want to learn about programming 2D games in C#. What are the best tutorials that are beginner oriented, written for C#, and preferably use GDI+ (or something equally simple)? I am relying on the experience this community has to direct me towards the best.

Books
Beginning .NET Game Programming
Beginning C# Game Programming
Links
Coding 4 Fun is a great .NET resource that has quite a few user-created games. They also have a book and a 2-D game primer
Tutorial Listing at C# corner
C# Game Tutorial for Beginners (video)
Link to more game programming e-books
Advanced Topics
The Farseer Physics Engine on Codeplex would be a good next step once you get comfortable with programming games. You could even end up contributing to the project if you like it enough. I'm sure they'd appreciate the help.

I watched these DNR TV episodes recently and thought they were very well done and informative.
http://www.dnrtv.com/default.aspx?showNum=165
http://www.dnrtv.com/default.aspx?showNum=166
These focus on XNA, which is definitely where I'd start if I was planning on creating a game. Their tutorial take you through:
creating a 2D game with:
collision detection
texture creation and usage
geometry creation
physics simulation (They use an open-source physics engine and show you how to use it)
If you haven't heard of XNA:
The framework runs on a version of the Common Language Runtime that is optimized for gaming to provide a managed execution environment. The runtime is available for Windows XP, Windows Vista, Windows 7, and Xbox 360 [also can be played on Zune HDs].
XNA attempts to free game developers from writing "repetitive boilerplate code" and to bring different aspects of game production into a single system. wikipedia
Even if you don't want to use XNA, I think these videos will help learn about the concepts and techniques common to most (if not all) game dev. Oh, and it's all C# :)
Good luck!

This link seems reasonable ( if a little verbose ) - it's takes you through how to code a simple tetris-like game in c# using GDI+. I has code listings and links to download the source code.

I would start with learn a little object oriented architecture - this is a key to your ultimate success.
Then learn how to design the model - the entities in the game (characters and etc) in code
and the view - the 2D representation of them, and how to connect the two (data and command binding).
I would try using WPF and not GDI+.
The code project has a lot of good articles for beginners.

I would take a look at SDL.Net it's a pretty good games library for .NET (well a binding to a good library for the pedants ;))
It has a lot of resources on its pages right from beginner stuff to more advanced things like isometric engines etc.
It doesn't seem to have been very active for a while however what is there already is more than enough for even complex 2D games.

Related

Unity with C# for 3D odontogram system

I will like start in 3d programming with Unity and C#, but I would like to know where to start. I want to make a 3D odontogram is possible with Unity and C#, or is it just for games? Thanks!
Regards!
Yes, the short answer is that you can do it greatly. Since it's a 2D/3D engine, it is used for simulations in general.
Look on the official site, there is a gallery of non-games projects created with Unity (also medical projects for simulation and training purposes).
The best way to start is always following the official tutorials (they are oriented at the gaming approach because the typical user want to create games, but it doesn't ruin the generalistic approach to the engine).
Obviously, you should not just learn Unity, but also use a modeling software for creating and importing the 3D models that you're going to use (teeth, mouth, ecc... in your case).

Learn Actionscript 3.0+Flash Vs. C#

I have a background in python and I'm looking for a new language. I am almost only intrested in making games.
I have come to 2 languages. C# and Action Script.
C# because Microsoft allows you to make Indie XBLA games programmed in C# ONLY.
Action Script so I can make flash games for new grounds and ect.
What do you think is better to learn in the long run?
I would say C#. You'll learn the basics and then be able to write games for the Desktop (XNA), XBox (XNA), Mobile Devices (XNA and XNA Touch for the iPhone), the Web (via Silverlight), etc.
Flash only gets you limited exposure to each.
I have zero experience with C#, but I'll speak to AS3/Flash's #1 advantage:
For learning game development, Flash lets you make games very quickly, but more importantly lets you get feedback from a large number of users faster than any other environment (except possibly Ajax only). I started Flash programming a little over two years ago. In my first three months I learned AS3 and wrote a TD-style game that was eventually played by over a million people. During beta testing and after release I was getting constant feedback and tweaking the game mechanics and interface with multiple "releases" a day.
While not every game out there gets that much play, with Flash it is much easier to make something and have a large number of people actually play it and tell you what they like and what they don't. Learning how to make good games is harder than learning a different programming language.
To give a comparison of the two:
Action Script is useable only in Flash games (mostly run through web browser), which may be fun for some time, but it limits what you can do. On the other hand, it is probably the best way for developing web-based games.
C# and .NET allows you to write all sorts of different games (and is also more generally useful language in case you wanted to switch from game development to some other field, including web site development and various business applications). Regarding games, you can use it on:
Web based games (similar to Flash) using Silverlight
Desktop/XBox/Zune games using XNA Game Studio
iPhone games using MonoTouch (although there are some licensing issues recently)
By learning C#, you'll also learn .NET Framework (in general), which is (I think) a useful knowledge that you can benefit from in many situations (e.g. when looking for a job :-))
Why not learn both? I think programming a good game is harder than adapting to a new programming environment.
Also, if you get into Flash game dev, you'll probably want to check out Flixel.
C# is the nicer language (although AS3 and C# are similar) and has a wider range of uses than Flash but since you mentioned games only I would tend to say start with ActionScript 3.0 then move to C#.
Firstly we can ignore the fact that C# is useful for writing business apps since that is not relevant to this question.
C# offers game programming via XNA, SilverLight, and Unity3D compared to ActionScript 3.0 with Flash.
So why do I recommend AS3 to start with? Firstly 2D games are where you should start off and I think this is where Flash excels. The development lifecycle of 2D games is much shorter and tend to produce better gameplay. A lot of indie 3D games suck since they fall short of realising what they started out developing. It is relativly simple to get a 2D game up and running and there is a lot of game engines, physics engines and tutorials available. It is also the platform of choice for artists (that can make all the lovely looking levels, characters etc). Second, the flash platform is the most accessible to your audience. No point making a great game that people never play. Third, AS3 is faily simple to come to terms with.
From my experience the web games that I come across that I think are noteworthy tend to be made in Flash. Checkout Scary Girl and Machinarium.
For 3D or anything that you need the power of the GPU then C# with XNA or Unity3D is what you should be looking at.
I will add that if you are interested in very fast action style 2D games then avoid Flash.

Game programming for windows in C++ or C#

I just learned the basics of c++ and c#,just the simple basics of the language.And I want to pursue game programming can anyone please tell me where to start off I read somewhere that Direct-X is used for game programming and I downloaded it from Microsoft's website but I just didn't understood it.From where did you people started your game programming when you were just beginners or do I need to have a deep knowledge about the language or can I just start now, please suggest me.And I am in the first semester of my cs undergraduate degree.
Start coding now. You won't get deep knowledge without, well, coding! I'd highly recommend XNA. XNA is basically a .NET wrapper for DirectX. It is very clean and well thought out (This means C# of course).
Have fun!
From reading your comments to the original question, it would seem that you have fallen into the trap of setting your sights far too high. The game 'World of Goo' did not happen overnight. It took a long time using lots of third party libraries to do the video/audio/physics/gameplay elements and a very good working knowledge of programming in general and an understanding of the restrictions doing a game often imposes.
Now, this may seem like a negative response but the point is it is better to achieve something small than to fail at something big. Failure generally puts people off doing what they really want to do.
Byron Whitlock's advice of "start coding now" is the best advice. But, start off with something simple: a text based version of Guess the Colours for example, then some easy, non-realtime graphics like Othello / Reversi / Sliding puzzles then try something realtime like Tetris and then branch out into physics, audio, 3D and so on.
The key to becoming a great programmer is to get code finished and working (shipping is a feature!), learn from the code - see if there are better ways to do stuff and so on. Start small, finish some programs, get a morale boost, firm up your foundations and gradually add complexity from there.
Introduction to Game Programming in C++ is a good start.
Introduction to Game Programming with
C++ explores the world of game
development with a focus on C++. This
book begins with an explanation of the
basics of mathematics as it relates to
game programming, covers the
fundamentals of C++, and describes a
number of algorithms commonly used in
games. In addition, it discusses
several libraries that can help you
manage graphics, add audio, and create
installation software so you can get
started on the path to making both 2D
and 3D games.
If you want to start with C#, which is recommended for beginners, you can use XNA, which is quite simple to learn, and a good book is Beginning XNA 2.0 Game Programming: From Novice to Professional
Would you like to create your own
games, but never have the time to dig
into the details of multimedia
programming? Now you don’t have to!
XNA makes it simple to create your own
games, which will run on your PC and
Xbox 360 console. Even if you don’t
know how to program at all, Beginning
XNA 2.0 Game Programming: From Novice
to Professional will teach you the
basics of C# 2005 programming along
the way. Don’t get overwhelmed with
details you don’t need to know— just
learn what you need to start creating
your own games right now!
The fast–paced introduction to XNA and
the C# language provides professional
developers a quick-start guide to
creating a commercial product using
XNA, as well as offering home
enthusiasts or hobbyists everything
they need to begin putting together
games in their spare time. You’ll
discover and understand all the key
concepts required to create smooth,
professional–looking results in a
range of gaming genres. Every reader
will come away with a firm foundation
onto which they can build more
advanced ideas.
I would recommend getting started with XNA, if you know a little C# it is an excellent way to get into game development and learn some important concepts that will help you out with other libraries. creators.xna.com There are several videos and tutorials to walk through, and it is all free when programming for the pc.
Maybe
www.gamedev.net is the best site of resources of game programming
I do not suggest XNA for learning how to do game programming. It hides many concepts that you need to have for a solid understanding of how it works from the inside.
First, learn thoroughly how to program in C++ and to understand how the Component Object Model (COM) works since this is what you will need to use in order to call the different methods in the DirectX SDK. Once this is done, learn how to create a window with C++ in Win32. After, find yourself some books on Direct3D for DirectX 9 SDK, game engines and architecture, multithreaded applications and design patterns. I would suggest DirectX 9 Graphics The Definitive Guide to Direct3D from Alan Thorn for Direct3D. This book is not a definitive guide, but rather a very good introduction to gain a solid base. Of course the book is a bit old, but the concepts remain very similar and it will be a good reference book for later on (plus it is cheap.. your budget might be tight with everything you have to pay for university :P) . Also, look at the documentation and samples from the SDK. Oh and before I forget, you will need some notions in maths (linear and vector algebra comes to mind)!
I suggest try using Silverlight as your game platform.
Check out this site http://dobbschallenge2.com/. It has a full functioning 2D platform game engine with source code and images. You can learn how parallax scrolling works, etc.
This way you can modify the game source code and slowly learn how it works. The game engine is quite simple yet the game is fun and includes awesome soundtrack :)
Check out the torque engine. It's inexpensive and takes care of a lot of the grunt work of making your game so that you can focus on making it fun. It's inexpensive and you can code in C#.

Writing a 2D RTS game in C#: graphics library options?

I am considering writing a 2D RTS in C#/.NET and i was wondering what options are available for a graphics library aside from XNA. What are they?
The answers posted so far (apart from SDL.NET) have all just said to use OpenGL, DirectX or some variant of the 2. Personally, I wouldn't use either of these for a 2D game when you already have XNA. XNA already has some classes for doing 2D graphics (the main one being the SpriteBatch).
If you do use XNA, not only can you make a game that runs on Windows, but also one for XBox, Zune and Silverlight as well (Zune and Silverlight require that you don't use the 3D part of XNA though, but that shouldn't worry you). Basically, XNA will save you the trouble of writting all of the low level management code that DirectX or OpenGL need (such as handling window switching and a plethora of other problems).
I haven't used SDL at all, so I can't give you any personal opinions on it, but I have heard it is quite good for 2D graphics, so I'd recommend looking into SDL.NET or just going with XNA, the other suggestions here require a lot more work with little advantage (most people just want to make the game and not worry about the HAL interfaces and getting everything to play nice with the OS).
Going straight to DirectX is a perfectly valid option, although for only 2D, you probably need to know a bit too much about 3D graphics to effectively use it.
Back when I was into game development, I was quite fond of the Artificial Heart graphics engine, which was somewhat basic but incredibly easy to use. Unfortunately, the website appears to have been replaced with a parked domain. Perhaps the company went out of business. If so, it is a shame.
For a more extensive catalogue, take a look at the DevMaster game engine database
If you are looking for opensource community supported library, you can try
SlimDX
TAO framework -- opengl bindings for .Net framework
But am not sure if they are matured enough.. but its worth giva try..
I'm sure there are other options out there, but you can also take a look at SDL.Net, a .Net implementation for SDL.
To make the most of today's computers' hardware and to keep up with the graphics of other 2D games, I would go with a 2D-in-3D solution, based on DirectX or OpenGL. You would render sprites as so-called quads (two polygons combined to make a square.)
I personally think OpenGL is much more appropriate for a 2D game. You should definitely read through the NeHe tutorials (they're for C++, but the OpenGL parts are still valid. You can find a C# conversion of the code at the bottom of the page of each lesson.) as they are an awesome resource for getting started with making a simple graphics engine for your game.
Furthermore, a lot of the articles on GameDev have helped me a lot when developing games. They've got all sorts of articles that will help you along, ranging from adding lighting effects to your games to adding simple physics.
I use Gorgon (which uses SlimDX).
http://tape-worm.net/?tag=gorgon
There is always Unity. Uses Mono not MS.Net
http://unity3d.com/unity/

Want to learn to write 2d games

Hey stackoverflow Community!
I learned the basics of C# (i can write some Form-Applications) and now I want to learn how to write 2d games. I don't know where to start.
Is there a engine that's good for 2d games? After learning the basics of 2d I'll want to write simple games which work under windows and linux (that whould be cool, linux :) ).
I asked a friend who is into programming and he said I should use XNA with C# (but that would only work on windows). After googleing I found out that OpenGL with C++ whould be best to write games for linux, since there is no DirectX/XNA. And I haven't used C++ yet, that whould take some time to learn, again.
Is there something you can suggest? Maybe an other engine? I just installed XNA and took a look at the demo game (Platformer), that code isn't hard at all. Is XNA good for 2d games?
Take one step at a time. When you're starting out you don't need your code to work on every platform. It doesn't matter whether it uses OpenGL or DirectX, because you're going to have your hands full creating a game to run on one platform with one graphics API.
Second, don't worry too much about "engines". You don't need an engine to make a game, and often, it'll be more trouble than it's worth. The whole obsession with "engines" is fundamentally a bad idea. If you try to get one single software component to support every bit of functionality you need for a game, then it's not going to be worth using for any of them..
All you need is:
a programming language you're comfortable with. It sounds like this is C#, so stick with that.
Some way to put graphics on the screen. The .NET library can do that to some extent, but some higher level library will probably make it easier. You could use XNA or SlimDX or another Direct3D wrapper. Or you can give SDL.NET a shot. Or you can write your own. The capabilities you're going to need are pretty basic and every graphics library, 2d or 3d, will let you do it.
You especially don't need anything which is "good for 2D games". XNA is able to put graphics on the screen, so it does what you need. If you also understand the code required to use it, then XNA is good enough. Don't bother trying to find the "best", or something that has "awesome for 2D games" as a selling point.
Probably the easiest and most accessibly platform is Flash. Easily distributable and rather quick to learn for games (judging by the sheer amount of flash games available on the web).
I agree with jalf. Don't start thinking about engines. Engines are a complex beast and considering your programming experience is small, it can get very overwhelming very quickly. There's a lot of stuff that goes into games and the design patterns that are involved in them tend to be much different from those of say a typical application. And OpenGL type of stuff gets very complex when you start talking about things such as hit detection.
Another direction you could take is instead of starting your own game from the ground up, you could try making a mod to something like Half-Life 2, or Unreal. That gives you a basic platform that you can change and see how it behaves. In the mean time you'd be viewing other people's code and seeing the intricacies of game development.
Here are a quick links I pulled off of a Google search with regards to flash gaming. I'm sure there are probably quite a few books available online as well with regards to creating a game in flash and other languages.
http://www.flash-game-design.com/
http://www.tutorialized.com/tutorials/Flash/Games/1
http://blog.onemorelevel.com/?p=12
Someone mentioned Flash, which is a good suggestion, but a bit expensive. If you'd like to do some Flash/AS3 development for free, I'd recommend playing with Flixel. You'll also need FlashDevelop, which is a nice (also free) IDE. The Flixel site has a lot of good resources to get you started.
If you're thinking about pursuing a future in graphics programming, I would pick OpenGL for the following reasons:
OpenGL is implemented on Windows, Mac, Linux, and even PlayStation 3. (extremely versatile)
Once you're comfortable with 2D programming, you can move onto 3D and stay with OpenGL.
OpenGL is equally as fast in terms of performance compared to DirectX.
C++ is a part of every collegiate-level programming curriculum.*
I think employers respect knowledge of C++ more than any other language.
The learning curve may be higher, but your time will be well-spent.
* If your college doesn't have C++ as a part of their programming curriculum, you are an outlier.
From my experience it's far better writing the basis of your game first in a form of simple application (perhaps text based) and then building graphics on top of that just by trying out bits and pieces from tutorials. That way you will always have a working skeleton that you can play around with and you don't immediately complicate yourself with all the graphics calls.
Other point is motivation: if you always have a working app it's far more satisfying to watch it slowly grow and develop rather than being frustrated by constant "works/doesn't work transitions" and always awaiting all the bits to come together to form something remotely complete.
As far as engines go: DirectX and OpenGL these days are kind of engines themselves. They let you do a lot of primitive work very easily (get a model from 3ds Max and load it into your app in 1-2 lines of code), for a small game you won't need anything else.
I also agree with MunkiPhD: Flash would be a very good platform for a 2d game. It's very simple and lets you get away with all the boring graphic programming. However, ActionScript-programming is not anywhere near "heavy-duty" programming with C-family languages and proper dev. platforms. ActionScript frustrates me every time I see it.
If you want to focus on 2D games and keep using C# for now, AND be able to have your friends play your games on Mac and PC, had you thought about using Silverlight?
Using Silverlight would get around some issues such as installation.
You might try a creating a few games in Silverlight and then after getting your feet wet you'd be in a better position to decide what other tools you'd like to learn next. With Silverlight 3.0 being recently released there is actually an influx of people trying to see how far it can be pushed for gaming, which might help you get questions answered. If you decide on this route you can post here or on sites like Silverlight.net
DISCLAMER: I'm not sure what the status of Silverlight for Linux
Flixel does rock - you can get a 2D game up and running with a minimal amount of code. You can find a detailed tutorial that steps you through the process of creating a simple platform game using Flixel here.

Categories

Resources