Jump to content
Objectivism Online Forum
Sign in to follow this  
Prometheus98876

Advice On C++ Game Programming

Rate this topic

Recommended Posts

I have been asked by a friend of mine to help him create a simple sprite-based game, one without all the cinematic stuff that makes game programming REALLY really hard and time-consuming.

We decided to code the game/engine in C++ as it is a language I am becoming quite good with (and that he knows fairly well), it is a language that is ideal for making the game cross-platform, and because there is a lot of past games coded in C++ that we can get ideas from.

Now, both me and my friend have never coded this sort of game before, so it will be a good learing expereince for us both. And of course, given that we have to figure out how to do this as we go along, it should take quite some time for us to complete.

Can anyone give me some advice, the URL for some good online material, the names of any good book that might help etc?

Share this post


Link to post
Share on other sites

If you're looking to make a cross-platform 2D game then I would wholeheartedly recommend the SDL library. It is very easy to use (and quite powerful), and it has components for graphics, sound, input, etc. You should be able to pick up the basics fairly quickly from the online tutorials.

Gamedev has some decent game tutorials, although it's almost always easier to learn from a book. If you can find a good book on general game programming (that isn't limited in its application to one API), it would definitely be worth the money. Most of the books I've read in the past have been language or API-specific, however, so I can't really recommend anything in particular.

Good luck!

Share this post


Link to post
Share on other sites

Nod, yeah I have thought of that already, but it is still of course good advice, so thanks :) .

I assume by "UI", you mean User Interface?

Edited by Prometheus98876

Share this post


Link to post
Share on other sites
I have been asked by a friend of mine to help him create a simple sprite-based game, one without all the cinematic stuff that makes game programming REALLY really hard and time-consuming.

Could you be more specific on the type of game? A "sprite-based" game could be many things.

Also a couple other things:

1. A cross-platform game is a bit of work because of the graphics code you will need to implement. In Windows, you have DirectD3, DirectDraw (at least if you use an old version of DirectX) or GDI. Or a few other options. You'll need to consider how to redo your graphics routines to work on other platforms. However, a great option you might consider is the SDL (Simple Direct-media Layer). It is a very simple, open source and cross-platform game library. Think of it as a stripped down version of DirectX that also runs on Linux.

2. What about artificial intelligence/path planning and that sort of thing? Will this be some sort of human-vs-human game or will there be an AI opponent?

3. Back to the cross platform issue: what compiler(s) do you plan to use? In my personal experience, Visual C++ doesn't exactly follow standard C++. So if you write something in Visual Studio, there will be all kinds of issues if you try to recompile it in gcc.

Share this post


Link to post
Share on other sites
Could you be more specific on the type of game? A "sprite-based" game could be many things.

.....

3. Back to the cross platform issue: what compiler(s) do you plan to use? In my personal experience, Visual C++ doesn't exactly follow standard C++. So if you write something in Visual Studio, there will be all kinds of issues if you try to recompile it in gcc.

I am sorry that I have been very speciifc at this point, but me and my friend have not decided on all that much yet, so there is little in doing so. The point making this thread at this time was to get some generic advice, and tips on what sort of things we might be forgetting to think about at this stage..

By 'sprite-base', I mean that we will gather sequences of artwork, say .bmps or whatever, and get the engine to move them around in some way. Nothing too tricky, as it is after all a two-man project at this stage.

As for the cross platform graphics stuff you mention, we do realise that making it cross-platform will be somewhat tricky and time-consuming. We do not expect to even even the first version cross-platform neccasarily, we might wait until a later release to do this. We will look into this SDL thing, it sounds like it might be of some help here..

The game will be we are thinking a one-player, human versus the computer, and with nothing too amazing in the AI front. This makes it alot more managable for us.

As for compilers, for C++ I usually use Dev-C++, at least in Windows, and the Windows version is the one we are focusing on at this time. I would think that would do for the game as well, but I will definetely be looking into this and other compilers. We have already realised that Visual C++ might not be the best of choices.

Share this post


Link to post
Share on other sites

It's a good idea to start with a simple 2D sprite game, as you're doing, because game programming is some of the most difficult programming you can do. It takes a great deal of time and study, as you note. Doing 2D will help you learn how to deal with frame rates and rendering, then you can take the plunge into the much more difficult world of 3D, if that's your intent.

In my experience the real work in doing graphics is knowing math. I mean heavy math. Lots of it. For example, geometry, trigonometry, linear algebra, algebra, calculus, etc. In fact, if you have a degree in math, you'd have a big edge in doing graphics programming, especially 3D programming.

Here are some websites:

The best website was www.flipcode.com. Sadly, the site is now dead, but some of their forum archives are still there, so you might want to try them. The guy who ran flipcode recommends http://www.devmaster.net/ as a replacement.

Another great site is http://www.gamasutra.com . Here you'll find papers, video lectures, and even job postings.

http://www.gamedev.net this has papers, forums and general information.

For DirectX these sites are useful:

http://www.32bits.co.uk/ This was my favorite site for learning DX.

http://www.andypike.com/tutorials/directx8/

http://www.riaz.de/tutorials/d3d.html

For OpenGL:

http://nehe.gamedev.net/ NeHe's site is very popular, and great for beginners to OpenGL. He even puts on contests, which are great fun, because you can see some great work done by amateurs.

http://www.opengl.org -- check out their forum for questions you might have.

For Hardware (graphics cards):

http://www.beyond3d.com/

http://www.tomshardware.com/index.html

Both of the above are excellent.

Books:

There are too many to mention them all. Here are some.

Computer Graphics: Principles and Practices by Foley, van Damn, Feiner, Hughes -- this is the bible on the subject. Although it won't get you directly to writing a game, since it's lots of theory.

The Graphics Gems series by Glassner, is expensive, but full of gems, as the title says. I only have one of these books, but everyone tells me that they are worth getting if you're a serious graphics professional.

OpenGL Game Programming by Hawkins and Astle

Intro to 3D Game Programming with DirectX 9.0 by Fank D. Luna

I don't have any book on 2D graphics per say, but I'm sure you can do a search on the web for such a book, or ask around.

Anyway, there is some information for you. Those leads should help you find your way. Ask questions of the guys on the forums, because there are some very knowledgeable experts out there.

Share this post


Link to post
Share on other sites
Doing 2D will help you learn how to deal with frame rates and rendering, then you can take the plunge into the much more difficult world of 3D, if that's your intent.

In my experience the real work in doing graphics is knowing math. I mean heavy math. Lots of it. For example, geometry, trigonometry, linear algebra, algebra, calculus, etc. In fact, if you have a degree in math, you'd have a big edge in doing graphics programming, especially 3D programming.

I dont really have any intention of going into 3D game programming, although I have already been asked to take part in programming another game that might end up beind 3D, if it ever actually gets made.

As it happens I have done/will be doing some Maths Papers at Uni... so I have a fair understanding of some of the stuff I will need to know.

Share this post


Link to post
Share on other sites

I've actually written a small freeware game - not very pretty since I am no graphic artist but it was a good learning experience; e-mail me if you want to know more about it (I think it is still available on Tucows for downloading).

I would jump in and do some coding not expecting that the code is going to be used for the game but just to learn about the libraries you will be using. Then, when you know the capabilities available to you, you can design and then code the project. The hard part isn't the graphics/audio but rather the algorithms and data structures you will be implementing to create the gameplay.

My experience is with DirectX without any layers (like SDL) so I'm not up-to-speed on cross-platform concerns.

You might want to code a tiny shooter to get your hands dirty - an enemy at the top of the screen moving left and right; the player's sprite at the bottom of screen that responds to input and can shoot. This will cover a lot of the basics - loading/rendering images, collision detection between sprites and input management. Throw in some background MIDI music and put in a background image too so that you can deal with those issues. All this can be done in an afternoon ... depending on what you do with collision detection.

When it comes to books, I think a lot of older books that cover DirectX 7 may have more information on 2D sprite style coding than the DirectX 8 and above books, which probably focus on 3D techniques. (Although you can use 3D methods to do 2D style games, which is what I did in my game). So, older books may have good information too. There was an introductory book by a fellow named Parberry (or something similar) that had a simple 2D game using sprites.

Good luck!

- Keith

Share this post


Link to post
Share on other sites
I would jump in and do some coding not expecting that the code is going to be used for the game but just to learn about the libraries you will be using. Then, when you know the capabilities available to you, you can design and then code the project. The hard part isn't the graphics/audio but rather the algorithms and data structures you will be implementing to create the gameplay.

- Keith

I have already learnt that with any big programming task that jumping in and testing out unfamiliar libaries etc is a very good idea. After all, the majority of what you really learn about programiing is from hands on expereince. And I realise that the algorithms will be a challenge, I mean, we do plan to implement some sort of AI, and I know that wont be easy.

I will take your advice on making a small game, although I already intended to do so as game programming practise.

Edited by Prometheus98876

Share this post


Link to post
Share on other sites

Thanks to all of those whom helped me with finding some information on C++ game programming, I have looked at most of that stuff at this stage and have found most of it somewhat useful. However, the project is no longer a C++ project, it is to now a C# project. However, all the stuff I have learnt about C++ game programming should be rather useful as little doubt I will find myself programming a game in C++ at one stage or another.

If anyone has any advice on this it would be much appreciated, as it will complement the stuff I find online (and there seems to be less stuff for C# game programming, though I have a good book on this now at least).

Share this post


Link to post
Share on other sites
Why don't you give Python a glance? Although I haven't tried it for game programming, they do have different engines devoted to 3d game programming (e.g. Soya) and on the first glance it looks good.

I will look into it at some stage over the holidays, once I finish some of my other projects. I am interested in Python for a number of reasons, although game programming was not one of them. This is more because I have not thought too much about game programming in Python, though rather than any dislike of Python as a game programming language. I might as well look into that aspect of Python too I suppose.

Thanks for the tip.

Share this post


Link to post
Share on other sites
Why don't you give Python a glance? Although I haven't tried it for game programming, they do have different engines devoted to 3d game programming (e.g. Soya) and on the first glance it looks good.

Python is interpretive (read slow), not something you want to use for a game engine. It could be used for certain aspects of game design. Certainly it's a valuable scripting language.

I've used both Python and Perl, and I do prefer Perl, but I've probably not had enough experience with Python to make a good comparison.

C++ is blazing fast, and powerful, because of the sheer number of tools. This is why it's the preferred language for writing games. The learning curve is steep, however. C, though, would be a fine alternative for those who don't want to tackle C++ right off the bat. When discussing game programming, C++ is the language almost universally discussed among programmers.

I also note that Delphi, which comes from Pascal, is pretty common in game design. There are websites devoted to its use for game design.

Visual Basic is also used for games, but much less so.

C#, hmm, I've yet to try C#. I know that games are written in it.

Just to be clear, programming is only part of the art of game programming, and in some cases not a big part. It's essential, but there is so much more to be learned about graphics, game logic, etc. I wrote a 3D pool game, and most of my time was spent on the physics, rotational mechanics of the balls, and things like that.

Share this post


Link to post
Share on other sites
the project is no longer a C++ project, it is to now a C# project. ... If anyone has any advice on this it would be much appreciated

You may find this series of MSDN webcasts starting Jan 16 useful:

If you have always wanted to develop cutting-edge video games but are just getting started, tune in to our 11 free webcasts. Learn the concepts of 3-D video game production as instructors from DigiPen Institute of Technology demonstrate the key stages of developing a game engine using Microsoft Visual C# 2005 Express Edition, a new development environment for beginner programmers. Learn how to handle backgrounds, objects, and collisions. In addition, these webcasts provide a primer for handling artificial intelligence in your game, along with multiple levels and additional character functionality.

Mark

Randex - Searchable database of online media references to Ayn Rand and Objectivism

Share this post


Link to post
Share on other sites
Python is interpretive (read slow), not something you want to use for a game engine. It could be used for certain aspects of game design. Certainly it's a valuable scripting language.

I've used both Python and Perl, and I do prefer Perl, but I've probably not had enough experience with Python to make a good comparison.

Just because it is interpreted doesn't mean it is bad for games. Actually many modern games, especially RPG's use interpreted languages to allow the user to customize the game. Personally I think a scripting component is essential for any game of moderate complexity. It makes it easier on the developers and adds a huge amount of replay value for the end user; a vital consideration if you want to make money off a game. Just look at games like Unreal Tournament. There is a whole collection of end user developed mods, so once you beat the original game you can replay it with custom changes to the gameplay.

However, developing an entire game engine in an interpreted language would be a bad idea. Personally C++ is the best language for the development of the engine (as you mentioned). But anything dealing with gameplay, characters, missions, etc should be developed in the game's scripting language so they can easily be customized later on.

Share this post


Link to post
Share on other sites
Just because it is interpreted doesn't mean it is bad for games. Actually many modern games, especially RPG's use interpreted languages to allow the user to customize the game. Personally I think a scripting component is essential for any game of moderate complexity. It makes it easier on the developers and adds a huge amount of replay value for the end user; a vital consideration if you want to make money off a game. Just look at games like Unreal Tournament. There is a whole collection of end user developed mods, so once you beat the original game you can replay it with custom changes to the gameplay.

I agree with you. I hope I didn't give the impression that scripting is useless!

However, developing an entire game engine in an interpreted language would be a bad idea. Personally C++ is the best language for the development of the engine (as you mentioned). But anything dealing with gameplay, characters, missions, etc should be developed in the game's scripting language so they can easily be customized later on.

Right you are. The pool game I did didn't have very many game play complexities. Pool is pool, pretty straight forward from a rules standpoint. However, if you're going to make a more complex sort of rules based game, with many and varied characters and the like, then scripting would be useful. Although, I've never used scripting in this capacity, so I'm not the one to look to for advice on this. :D

My experience with Python was with a free 3D modeling package called "Blender 3D". They allow you to implement scripting for certain kinds of operations. Python is an effective language with some nice features, no doubt about it.

Edited by Thales

Share this post


Link to post
Share on other sites
However, developing an entire game engine in an interpreted language would be a bad idea.

Why? Unless he is writing a cutting edge 3D engine (which he isnt), I dont see why an interpreted language would be too slow. For the sort of game that its possible for a single person to write in under a year, I dont think theres likely to be enough complexity to warrant ruling out 'slower' languages. But in any case, I assume that the graphical parts of his engine will be handled by (fast, compiled) third-party libraries like SDL or DirectX.

The OPs original spec was:

I have been asked by a friend of mine to help him create a simple sprite-based game, one without all the cinematic stuff that makes game programming REALLY really hard and time-consuming.
I would say that Python is perfectly adequate for this, and since I think its a far superior language to C++ in terms of useability, I wouldnt mind recommending it here (although admiittedly I'm biased and would recommend pretty much anything over C++ :D) Edited by Hal

Share this post


Link to post
Share on other sites

Well, I'm not going to argue with you, Hal. You can do slow games, of course. :D

2D games have been around on PCs since the early 1980s, when machines were many times slower.

The best way to solve this issue is to visit some websites and try out some games to observe performance and see it it's up to what you want.

These two websites apparently have pre-made libraries based on python for gaming.

This one mixes c++ with python. I note it has video galleries of rendering done. The C++, of course, gives the library its performance value:

http://www.panda3d.org/

and

Pygame is a set of Python modules designed for writing games. It is written on top of the excellent SDL library. Here they avoid C++, but SDL is written in C:

http://www.pygame.org/news.html

I think it should be noted that C++ and C are used even by serious Python game programmers. I'm not going to belittle any of this, because for all I know those python modules make for great game writing tools.

Share this post


Link to post
Share on other sites
Why? Unless he is writing a cutting edge 3D engine (which he isnt), I dont see why an interpreted language would be too slow. For the sort of game that its possible for a single person to write in under a year, I dont think theres likely to be enough complexity to warrant ruling out 'slower' languages.

Well for a simple 2D game, an interpreted language would be fine. I was just saying that for a complex game with lots of code, you are going to want it to run as fast as possible, which means using a compiled language for the CPU intensive code.

But in any case, I assume that the graphical parts of his engine will be handled by (fast, compiled) third-party libraries like SDL or DirectX.
That's what I was getting at in my other post. Those aspects of the game are best done using compiled code. Then you could combine it with a scripting language to control the other aspects of the game I mentioned.

Share this post


Link to post
Share on other sites

Thanks all of you guys for the advice, it is much appreciated and has given more more to consider and to suggest to my friend. It would seem that I should seriously consider using something like Python at least in part, the reasons given above seem valid to me, but I will look more into it.

It is a simple 2D game, as this will be the first serious (but not overlly complex) graphical game for me and my friend, please keep that in mind people.

As for what graphics system to use, well I would think that given it is a C# project DirectX would be the realistic if not the only real option. If it was still a C++ project I might choose OpenGL or SDL (I dont really know a great deal about SDL, must look further into it) or such.

Edited by Prometheus98876

Share this post


Link to post
Share on other sites
As for what graphics system to use, well I would think that given it is a C# project DirectX would be the realistic if not the only real option. If it was still a C++ project I might choose OpenGL or SDL (I dont really know a great deal about SDL, must look further into it) or such.

Just to let you know, .NET applications can make calls to unmanaged code like the SDL. So don't discount that option entirely just because you are using C#.

http://cs-sdl.sourceforge.net/index.php/Main_Page - This site has the wrappers to allow .NET to easily call the SDL.

Share this post


Link to post
Share on other sites
Just to let you know, .NET applications can make calls to unmanaged code like the SDL. So don't discount that option entirely just because you are using C#.

http://cs-sdl.sourceforge.net/index.php/Main_Page - This site has the wrappers to allow .NET to easily call the SDL.

Oh now that is good to know as I beleive I indicated earlier I do not beleive DirectX is the best graphics tecbnology out there and I am told from a few reliable sources it is harder to learn as well. Though I suppose I will have to master DirectX programming eventually.

Share this post


Link to post
Share on other sites

OpenGL is easier to set up and use than DX, but both APIs are excellent. Both have enormous numbers of features which will let you create highly sophisticated graphical applications.

DX has the benefit that it includes DirectInput and DirectSound/Audio, which means you have most everything you'll need to do a game. Configuring gamepads to your game will be a breeze with DirectInput.

SDL is meant, I believe, to be a more direct competitor to DX, since it also has libraries for sound and gamepad/mouse. It goes with OpenGL. Here's a link http://www.libsdl.org/index.php

You will also need Photoshop (or an equivalent package) to create textures, or someway to find textures. And you'll probably want to find wav and mpg files for sound effects and music.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...