ANOTHER PROGRAMMING CRISIS!!!!

Started by
2 comments, last by node_5r 24 years ago
hey all, I want to thank you on the good job you did helping me on my first programming crisis. Now i have another. I was wondering how i could make my own game function. In one of the examples it had a DoGame() and i could not get this working so could some show me how to do a prototype and then initiallize it in my program?? Thanx again, node_5r
Advertisement
I''m not sure if this is what you mean, but you declare a function prototype like this, somewhere as a global (in c++, btw):

void function(params);

create it:

void function(params)
{
asdfasdfasdf
}

call it:

anotherfunction(params)
{
function(params);
}

Sorry if this wasn''t what you were looking for,
Martin
______________Martin EstevaolpSoftware
Not sure what you mean. Maybe something like:

#include <stdio.h>void initDrivers(){     //your initialization comes here}void renderGraphics(){     //Render the scene}void playAudio(){     //Play sound and music}void renderAI(){     //Calculate all AI movements}void miscFunctions(){     //Whatever I forgot}void main(){     initDrivers();     while(true){          renderGraphics();          playAudio();          renderAI();          miscFunctions();     }} 


Now most games divide the functions up into different files for ease of programming. It is alot easier if all graphics functions are in graphics c or cpp files, while the sound functions are in sound files, etc.

Just create a file like graphics.h

In it you would include function prototypes, etc. (I prefer to use classes, although you could use the c equivilent, structs, or go global).

IE:

#ifndef __MYGRAPHICS__H__INCLUDED#define __MYGRAPHICS__H__INCLUDED#include <iostream.h>class Graphics{private:     int texture;public:     Graphics(){}     ~Graphics(){}     void loadTexture();     int getTexture();     void initGraphics();     void drawBackground();     void drawSprites();     //etc...};//Or outside the classvoid setMode(int mode);#endif 


Then in your main file, remember to:

#include "graphics.h"  //Or whateever the header file is named. 


Remember, none of the functions you see in other files will work unless you actually need the function and have it initialized.

One more thing I forgot. You don't have to declare functions you use if:
1) They are in the same file as where you call them.
2) They are above the functions you call them from.
And remember to return values if they need it.

int calculateFramesPerSecond(){     int FPS;  //Frames per second     //do calculations here     return FPS;}



Edited by - Nytegard on 3/29/00 10:02:03 PM
Just simply:

int DoGame(); //function prototype

int main()
{
//do things....
DoGame();

return 0;
}

int DoGame()
{
//run the game here

//return success
return 1;
}

- Daniel
- DanielMy homepage

This topic is closed to new replies.

Advertisement