Programme Flow.

Community Forums/Monkey Talk/Programme Flow.

Paul "Taiphoz"(Posted 2011) [#1]
would like to chat about program flow in monkey..

Currently I have just beed dumping all of my update code in the OnUpdate and all my rendering code in OnRender, any game images I have just pakced into fields of the main class bar a few globals.

In short, messy as hell.

Wondering if those of you who have been using it for a while, could share some of your setups, in relation to how you control the flow of your code and where you put stuff, like loading images and media, or declaring variables.


Leon Brown(Posted 2011) [#2]
You should make your code modular and have OnUpdate call upon the relevant methods and objects for processing and OnRender to call up the relevant code to render.

Look into MVC and n-tier development - they will give you ideas for better programming patterns. I've taken this type of approach myself and have coded a system that allows me to create scenes and place game objects in the scenes - the OnRender system then takes care of drawing the scenes based on what objects are in them and their status.


AdamRedwoods(Posted 2011) [#3]
What he said. It's fun to start out prototyping and keeping all the code packed into your main file, but when the project gets BIG, I can't find anything and it takes too long to find bugs.

I don't use a version control system. I just increment my files with a "name_v02.monkey" and revise the imports accordingly.

My main file, the one I lock the build to "bigbugs" is this:
''Big bugs tower defense

Import bigbugs_main_v11

Alias Game= bigbugs_main_v11.Game

Function Main()
	New Game

End


As for loading images, I put all that in a separate "load_images.monkey" file and its own class:
Class InitImages
   Field imageBug:Image
   Field imageTank:Image
   Method LoadAll()
      imagebug = LoadImage("etc")
   End
End

I create the instance in the main OnCreate() and pass that instance to the other functions as needed. I suppose I could just make all the images globals and forget about passing.

My other files are divided into game entities:
- enemies
- player
- bullets, damage, fx
- map
- ui
- game utils (loading/saving/tweens/etc)

Each handle their own rendering, called from OnRender().

I could go on for days about how I set this stuff up... But I just want to add that I don't try to divide it up into TOO many files, because then you're just searching around for files. I've seen people do this and I find that you end up jumping around from file to file trying to dissect what they did.

Last edited 2011


Paul "Taiphoz"(Posted 2011) [#4]
Yeah with b3d and max I am guilty of really splitting my files up, each type with withs own file and any function that deals with that type goes into its file, it makes it easier to find stuff, I know if something goes wrong with a player, to look in the player type.

But I think after my first monkey game I realized that things might be a little different.

To be honest I have not done anything yet with more than one class, I think my next monkey game, a port from an old b3d title i had is going to need more than one class tho, so im gona need to srot this sort of stuff out.