Game programming basics?

Started by
2 comments, last by oogly 23 years, 11 months ago
Hi! Im just starting to write this Derby game, where you can bet on horses and stuff... I have written a functional main menu, and everything is working fine, BUT.... my code is messy!!!! mouse hit checking is done wherever i need it and I usually end up writing my code over and over again.... I know about OOP, classes and objects and stuff, and I do use it, but it is so hard to know what to put in where... ok.. this is becoming a messy text too... How do I build my "engine" up from scratch so that it will simplify the rest of the production? Now my "engine" is like this: OnFlip code: (somewhat pseudo) Begin If (MouseX > 50) and (MouseY >50) and (MouseX < 100) and (MouseY < 100) then Begin write(''Mouse is within square''); End; WriteStuffOnScreen(Image[0],True) blahblahblah End; when i could really like it to be: Begin Case Level of 0: MainMenuProcedure; 1: OptionScreenProcedure; 2: Level1Procedure; End; End; Procedure MainMenuProcedure; Begin DrawBackground(Image[0]); CalculatePhysics(x,y: Integer); // lots and lots of simple procedure calls DrawMouse; // this calculates mouse position and draws cursor defined. End; hehe... im not good at this.. Ok.. what should a game contain? an event-timebased object? so that certain events happen at certain times... hmm.. im lost... could anyone help me with my problems? Thanks! helpme@oogly.com
Advertisement
Do you want to write OOP in PASCAL?
Because the code you wrote looked like PASCAL to me (The BEGIN and END stuff); or was this just some sample code, which should demonstrate your intensions?

If it´s PASCAL, I can´t help;
because I have forgotten all about OOP in PASCAL and only use C++ (and Java).
ok.. its a little warm here today, so that first post didn''t look very good.

Here''s what I meant:

When I program a simple game, should I first write some event-trigger routines, mouse routines, make my own drawing routines based on the ones contained in the DirectX wrapper I''m using... and THEN create the game... ? well... that looked somewhat obvious to me too...
BUT HOW do I make that event-trigger routine? Should I create a component that captures system clock and triggers events predefined by me after a certain amount of time has passed?

HELP PLZ!

Oogly
helpme@oogly.com
well how about this:

create a class that has a list of pending events.
when you add an event, you will pass a delay and a function pointer.

then every so often you could call .Update() with the class, and it would check the times of the events. if the time is up, it would call the function and remove the event from the list

then you could do something like this:

void Function();

....
Events.Add(Function, 1000); // calls Function after 1 second
....

in your main loop:
Events.Update();

a better solution than polling would actually be to make it multithreaded, but that might be a bit much for a simple game.

you might consider making a class that wraps the mouse..
you could call Mouse.Position() to get the position whenever you wanted...

but for click events, you might pass an array of rectangles and function pointers as the current ''click map''

then whenever the mouse is clicked, the class would check its click map and call the function that goes with that rectangle

for different parts of the game you could just call
Mouse.SetClickMap() with your new click map and it would call all the appropriate functions..

i know this isnt enough to do everything you wanted, but it''s some food for thought

i hope it helps..

good luck!




adamm@san.rr.com
adamm@san.rr.com

This topic is closed to new replies.

Advertisement