Design Talks - Your Game Module

  1. Are you a new or experienced game developer?  I guess I would say experienced… but not as much of late as I would like
  2. Do you use the concept of a game module? Yes
  3. Do you use some or all of the functions I use? I tend to have a startGame() and perhaps a startLevel() function. Depending on the game, there may be a pause() function depending on the game.
  4. If you do not use a game module, how do you organize your game logic?  As I’ve matured with Corona I’m getting much more complex in code organization. For instance in my side-shooter that I had to back-burner, I had a player.lua module that handled the player’s ship, it’s fire and damage code, etc. The low level enemies had their own .lua file, the bosses had their own .lua file. I’m trying to think more object oriented. The game.lua calls the UI module manages scrolling the background, managing collision, processing game wide events like bombs exploding, etc.
  5. If you do use a game module and it is different from mine, can you describe yours? See above.
  6. Was this an interesting discussion and would you like more discussions like this here? Always!

@roamimggamer  Great topic Ed!

My approach is One Module to Rule them all!

module_forum_small.jpg

In a previous post I brought up some questions about the way I was structuring my modules.  I was getting paranoid that I was going to program myself into a corner but you guys talked me off the ledge :wink:

Basically, to get to any module, you have to go through the master module.  I originally set it up this way to avoid circular references but it turned out to be a structure that allows me to rapidly deploy a whole bunch of unruly modules that don’t always want to get along.

1. So generally, I call SSK and all of the modules in main.lua.  I start with the master module and the other modules populate the master as they are referenced.

2.   From main.lua I call in my scenes using composer, but I only use composer lightly and do all of the heavy lifting through an init module that allows me to interact with the master module and call in the sub modules.  As the game progresses most of the interaction is directly with the master module.

3. So I’ll go to a scene and call in:  the background, the characters, ui and touch, the minimap, the shader, etc.  The master module tracks everything so I destroy objects “manually” instead of using the composer.

4. I do all of my collision detection and movement through the physics engine using a module I call the Trig Engine.

All of my modules, including the Shader and the Trig Engine are under 1,000 lines - it took some work to get them there!

About me:

     I’d call myself a seasoned developer.  I used to do web development with the best years being dedicated to Flash and ActionScript.  As an Artist/ Designer / Programmer, Flash provided me with an active playground where I could rapidly test ideas and make “sketches” with code and art before committing to a structure.  Once Flash declined I went fallow for several years and focused on my design business until I discovered Corona which in an environment that has everything I missed from Flash and A LOT more!  As @SGS says, I win the prize for fewest apps released  :) but now that I closed my design business I’m pushing to get something exciting to market (I’m rewriting everything with IAP in mind instead of going premium).

I always appreciate these types of discussions.  So many ways to peel a potato!

This topic is very interesting :slight_smile: thank you @roaminggamer

From an app to a new one, how much of your code you have in common?(for a same kind of game 85% and for a totally different game 20%)

What’s your average number of code line for the whole app? (mine is ~120k)

What’s your average number of code line for the minimal app? (mine is ~20k)

Which part of coding take you the longest time (game engine, physics, optimization, testing…)?(me it’s optimization ~30% of coding time)

Would you be agree to share your code to a close group of dev to share your methods and tips?(Ask for my code source of gate of heroes or stronghold and I will share you and you can take what ever you want but (not images))

If your game have physics, do you use Corona physics or your own algorithms?(I use mine, firstly because I didn’t know corona physics exist and I prefer to do it by myself)

@remiduchalard  Optimization used to take about 70% of my time but as my library of modules increases that time reduces.  Maybe optimization is 40% of my time now.  * I count play testing revisions as optimization *

@remi, what’s your definition of minimal? 20k seems too much considering my personal record of ~6k for a point & click adventure game. 120k… WOW!

Yeah 20k seems crazy for a small app!  I have less than 50k for my games (and they are kinda big games) and at least 10% of that is comments.

Oh and code sharing is not high on my list… discussing methodologies yeah sure.

For me, testing is the most time-consuming… as my games are time-based and level-based what works on level 50 does not work on level 100 so a full test of my game (prior to upgrade) takes well over a week.  I now have a 20 page test script.

I’ve just finished a cool little word game that is around 2k total - made for Corona Jam but turned into a proper app now

https://itch.io/jam/glitch-jam-1/rate/254805

Very interesting, I don’t know how your minimal apps is done with only a few thousand lines of code.

For example to manage properly the walking of my unit I have a few thousand lines of code. There is an explanation ?

I have attached the 3 files who manage the walking of my units. If someone is a bit crazy and want to have a look on it, I will be really please to have his opinion :slight_smile:

For example, only to display a unit bouncing when it get deadly hit, it’s take one hundred lines. (animdepter line 303 to 400), I see how to reduce but only little number of lines.

the result can be see here : https://youtu.be/2fFyBh5_FQU?t=47 (play the trailer at 0.25 of the normal speed to see the result)

Well for example if you had an array of sequence data you could truncate this

 if image[isoldat[numero].typesoldat].typedep==1 then sequenceData=sequence.cavgent elseif image[isoldat[numero].typesoldat].typedep==-1 then sequenceData=sequence.elf2 elseif image[isoldat[numero].typesoldat].typedep==2 then sequenceData=sequence.golem elseif image[isoldat[numero].typesoldat].typedep==3 then sequenceData=sequence.araigne elseif image[isoldat[numero].typesoldat].typedep==4 then sequenceData=sequence.ours elseif image[isoldat[numero].typesoldat].typedep==5 then sequenceData=sequence.rhino elseif image[isoldat[numero].typesoldat].typedep==6 then sequenceData=sequence.chien end

to

 sequenceData=sequence[image[isoldat[numero].typesoldat].typedep]

@remi  I imagine you have many thousands of lines of code to manage the movement and physics in your apps.  If I didn’t use corona Box2D physics for most of my collisions and movement, my code would be much more bloated.

My apps range from 5k lines to 40k lines.  My largest app, which is on the back burner at the moment, is looking like it will be 60-70k lines by the time I finish (it has extensive AI, math, and genetics modules).  However, with better coding practices I think I can cut it down to 40-50k.  For example, I recently shaved off 80% of a math module by rewriting the entire thing in radians instead of degrees.

Agree with @sporkfin…  always use framework code wherever possible.  There are rare occasions where you can do it better (not using thousands of transitions for example) but not often; and physics is definitely not one of them.

Also, you have zero white space/line breaks - it is just a wall of code.  It must be a nightmare to work on?

about 8.5k of actual code for https://play.google.com/store/apps/details?id=org.davebollinger.dropstack

PS \> ./cloc.exe DropStack 46 text files. 46 unique files. 10 files ignored. http://cloc.sourceforge.net v 1.64 T=0.12 s (386.9 files/s, 101834.9 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Lua 45 1877 1463 8503 ------------------------------------------------------------------------------- SUM: 45 1877 1463 8503 -------------------------------------------------------------------------------

Looking at my code and @remi’s code, it reminds me that I miss the good old fashioned “switch” statement that Lua doesn’t support.  I could especially use that for my AI modules.  There are, of course. workarounds but I’m always thinking someone else must have a better solution for this.  Hmmm. . . maybe a new topic.

Sometimes Box2D physics won’t cut it - for instance if you were making a Sonic-clone, you’d have to roll your own.

But woah there’s a hell of a lot of unformatted if > then > elses there. I now have a rule, any code in a nested if gets refactored out to a separate function, and if any if/else branch has more than one line, that also gets refactored.

I wasn’t expected some fast review. Thank you so much!

@sgs Good idea!

For me it’s quite easy to find my way in my code. With sublime text it’s very easy to find files and function. I need aroud 15 sec to find the code I am looking for.

What do you mean by no space or line break?

@sporkfin Can you explain more how physics could help?

I see how it can reduce some part (for example in the three files send previously, I see only one function, it’s to avoid objects (100 lines))

but how can physics can help for example(I think there is a way but I don’t know how):

  • to know if a moving object can be catch up by an another one and in which way it need to go to catch it the fastest?
  • map are defined with two kind of points. Road and unauthorize walk zone. There is any way to find the shorter way to go back on the road without walking on an unauthorize zone? 

@remi look at SSK as that has simple functions for returning direction vectors - will save you lots of code.

Also look at jumper for path finding (rather than your own implementation).  There is a tutorial here - http://battleofbrothers.com/sirchris/pathfinding-in-corona-with-jumper-and-a-star/

a long series of if-elseif’s can be refactored as a table-lookup, fe see:  http://lua-users.org/wiki/SwitchStatement

His algorithms are for grid map only? For grid it is simpler, I can change my map to work a bit like grid but it will still be a bit weird and use a lot of resources if my tile are small.

To find the shortest way it’s not complicated if the goal don’t move. But when the goal move it’s harder. For example A is going to B and C try to catch A. Which way C need to take to catch A? 

i haven’t looked at your code, but pathfinding in general, as a discrete topic, is not dependent on a grid structure - all it needs is a graph of connected nodes.  true that a grid is often used just as a simple way to imply that graph, but you could just as easily perform pathfinding on something like this.  look for the concept, rather than a specific grid-based implementation.

You may find this discussion/page interesting: http://lua-users.org/wiki/SwitchStatement