Can I get some basic source code for a simpel game

RESmonkey

Diamond Member
May 6, 2007
4,818
2
0
I want to get an idea of how a simple game is structured. Nothing too complex, I'm noob at C++ and only know how to do nongraphical stuff.

 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
There are a lot of tutorials out there for C++ and quite a few involve simple games. A little Google will go a long way.
 

sao123

Lifer
May 27, 2002
12,653
205
106
Originally posted by: Markbnj
There are a lot of tutorials out there for C++ and quite a few involve simple games. A little Google will go a long way.

whats the point of having a forum if every time someone asks a question all anyone answers is "GOOGLE!"...
If you have something to answer for the man provide it... otherwise... dont waste a post... you have contributed nothing.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: sao123
Originally posted by: Markbnj
There are a lot of tutorials out there for C++ and quite a few involve simple games. A little Google will go a long way.

whats the point of having a forum if every time someone asks a question all anyone answers is "GOOGLE!"...
If you have something to answer for the man provide it... otherwise... dont waste a post... you have contributed nothing.

You're right, Mark should be posting thousands of lines of code into a forum post... :disgust:

Where is your helpful post? I don't see you answering his questions in your post. There's a time and place for using Google to get answers and for using a web forum to get answers. Coming onto a web forum for a "give me code to do this" is a bad way of doing it, especially for something that's not overly simple. People have to be willing to help themselves if they want others to help them.
 

stevf

Senior member
Jan 26, 2005
290
0
0
On the flip side of the same issue - there is tons o' crap out there and sometimes you can do 10 searches using slightly different keywords and never quite find what you need and in those cases sometimes asking for help pointing you in the right direction is a good thing
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
whats the point of having a forum if every time someone asks a question all anyone answers is "GOOGLE!"...
If you have something to answer for the man provide it... otherwise... dont waste a post... you have contributed nothing.

Thanks for your input.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
It might help if you tell us the OS, development tools, and graphics library (OpenGL, DirectX, ...?).

"game source code c++" does give 4+ million hits in Google but including the OS + development tools will narrow it down.

Windows: CodeProject.com has some, MSDN.Microsoft.com has some for the XNA cross platform library (PC + 360 + Zune (next version of XNA)).

There are a bunch of game programming books with source code, often with a simple 2D and/or 3D engine included.

www.Gamasutra.com -- poke around for code links
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
if you are just trying to do something real simple with a keyboard and dont need like real directinput and stuff, you might actually be better off searching for stuff on keyloggers.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
I think you guys are taking it a bit TOO far. Games have a fairly simple structure with all things considered it is basically
Initialize program
-Initialize game engine
--Start Game Loop
--Wait for exit conditions
-Destroy Game engine.
Destroy program

The game loop is where all the magic happens, the rest is just a matter of implimentation.

One question to consider is "How often do I want to update?" If you are doing a text game then you update every time the user sends a command. If you are doing a 2d an up type game, then you update as fast as possible and use timers to calculate where to move things.

That is what makes turn based games fairly easy to do, because you just wait until a turn is up to do any processing, real time games are harder because you have to consider things like timing ect.

Hope this helps a bit
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
A turn-based game is a good idea for baby steps.

Google "wumpus c++" for the 60s classic Hunt the Wumpus.

For something real-time you could simulate the timer interrupts real games use by adding a sleep to your loop:

loop
- poll keyboard (get char without a wait if no press)
- move player
- move other
- if not game over, sleep() ; // 1 second is OK if that's all your sleep / Sleep allows, else 1/10 - 1/30 sec
end loop