Advertisement

Is this code a good beginning for a game?

Started by April 13, 2001 09:58 AM
7 comments, last by MindWipe 23 years, 10 months ago
I have made a few games. The first I made was just one long cpp file and a header. The second had all the directx stuff in different files, but the game was in one long file. Now I'm trying to make a good system for my game. And now I have many differne files. Window, Audio, Visual, Init, WinProc, Menu, GameProcess. So I think the code looks pretty good. I also have a settings.h that includes many #defines like, NAME "name" MUSIC_THEME "Themesong.mid" #define BOOL_SHOWFPS true. In that file I have also defined different states: #define STATE_MENU 1 This is the main file:
    


#include "Globals.h"

bool ProgramActive = false;
int GameState = STATE_START_UP;

int PASCAL

WinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpCmdLine,
        int nCmdShow)
{
    MSG                         msg;

	Init();

    while (TRUE)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if (!GetMessage(&msg, NULL, 0, 0))
                return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if (ProgramActive)
        {	
			GameProcess();	
		}
        else
        {
            WaitMessage();
        }
    }
}

  

And this is the game process file:

      
#include "Globals.h"


void GameProcess()
{

	switch(GameState)
	{

	case STATE_START_UP:
		break;

	case STATE_MENU:
		MenuProcess();
		break;

	}

	VEng->Flip(false);
}
    
Would you say this is good coding? Are there something I have forgot. And how any of you got any good tips & trix. I'm greatful for any comments & help. EDIT: I forgot to say that this is not a "beta-code" - it works! /MindWipe "If it doesn't fit, force it; if it breaks, it needed replacement anyway." Edited by - MindWipe on April 13, 2001 11:02:02 AM
"To some its a six-pack, to me it's a support group."
You''ll need a way to track how much time has passed between each call to your GameProcess function. You could either perform a calculation to determine that at the beginning of GameProcess, or (I like this method better) pass the elapsed time as a parameter to GameProcess.

As for your file separation system, some other worthwhile modules might be:
Input (keyboard, mouse, joysticks, etc.)
Memory (if you write your own memory handlers)
Sprites (if you''re using 2d sprites)
Meshes (if you''re doing 3d stuff)

Try to keep everything as general as possible, and not specialized for the game you''re writing now. That way you don''t have to rewrite it all again for the next game you start.

Good luck,
Jesse Chounard
Advertisement
BTW: If you want to paste your code as a SOURCE message to gamedev and you are using MSVS 6.0, you can get a better text adjustment by selecting the text in MSVS and choose "Untabify Selection" in the "Edit- Advanced" menu.
Thanks for all the advice

I''m thinking of making a engine that loads scripts and act after that. An RPG game, where you ie. load map1.map, and map1.map contains links to ie. map2.map, map5.map

But that''s not the essential thing now. It''s just the basic cod I want perfect. That''s the big problem I have had when I wanted to make big projects. They end up in one HUGE cpp, and it takes ages to find anything. And after a week or so, I just don''´t understand it any more

Keep the advice & comments comming

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Well, my advice is to split your program into as many files as you can (don''t take that overly literally). I have over 30 files in my ~7,000 line project, and I still think it is stuffed into to few files.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
I meant to write "too" in that last post (it was having errors letting me edit it for some unknown reason), and I just counted, and there''s 46 files in just the Rune Iso engine (the one I''m going to release on my website when it''s finished), that''s without counting any game specific files...

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
Advertisement
quote:
Original post by MindWipe

      #include "Globals.h"bool ProgramActive = false;int GameState = STATE_START_UP;int PASCAL <--WinMain(HINSTANCE hInstance,        HINSTANCE hPrevInstance,        LPSTR lpCmdLine,        int nCmdShow)[/quote]The only thing I would change is where the arrow is, int PASCAL WinMain(... ) isn''t recognised as a standard anymore, I would use:int WINAPI WinMain( ... )anyhow, these are simply my views. Feel free to do as you like.   


"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Product Activation Technology!
[Cyberdrek | ]
Guys is this code alright?

10 PRINT "Me ummm duhhh DUMMMMMMMMMMMBO!:
20 PRINT "I JUST NEED print?"
30 GOTO 10


Guys how come my computer is still printing after 1 year?
Ok, I will start to use "int WINAPI" from now on.

And, spacemadness, hope that was a joke and not some sarcastic post. It''s important to have a good design on the code. As "Null and Void" you should split your files in as many files as possible, else it will be way to complicated in the end.

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."

This topic is closed to new replies.

Advertisement