Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Game programming basics?

This topic is 6918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post

Link to post
Share on other sites
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?



Share this post

Link to post
Share on other sites
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:

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!


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!