Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Design Talks - Your Game Module
Started by roaminggamer May 13 2018 10:05 AM

* * * * * 2 votes
48 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

I'm working on some starter materials for myself and the community and I wanted to talk to new and experienced developers about their best practices.

 

Specially, I want (in this post) to talk about the game module.

 

Game Module

Before I proceed, let me clearly define what I mean by 'game module'.

 

In this discussion, a game module is a single file (usually called game.lua).

 

This file contains/defines a module that has all of the responsibility for creating, destroying, and in general managing game objects, game data, and game-play logic.

 

For all but the simplest games, a game module will often include/require other modules to do its work.  i.e. It is not monolithic.

 

A game module is NOT responsible for:

  • splash screen
  • main menu
  • help screens
  • options
  • ...

 

A game module may however implement/manage, HUDS:

  • score count(s)
  • coin coin
  • hitpoints
  • damage indicators
  • radar
  • ...

 

 

My Game Module(s) Approach

In my games, the game module may have any of the following functions: 

  • init() - One time module initialization.
  • create() - Create the game world/content  + (optionally) start game logic.
  • destroy() - Destroy all groups and game content + (optionally) stop game logic.
  • start() -  Starts game logic.
  • stop() - Stop game logic. Usually as the result of of of these:
    • Level or Game Loss
    • Player Death
    • Level Completion
    • Game Completion
  • continue() - Resumes a game after player death without starting over at the beginning.
  • restart() - Restarts the game afresh from the same coditions as the last create() and/or start().
  • pause( pause ) - Pauses or resumes game interaction and logic.

 

Legend: required optional

 

 

My Questions

  1. Are you a new or experienced game developer?
  2. Do you use the concept of a game module?
  3. Do you use some or all of the functions I use?
  4. If you do not use a game module, how do you organize your game logic?
  5. If you do use a game module and it is different from mine, can you describe yours?
  6. Was this an interesting discussion and would you like more discussions like this here?


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

So far, I've gotten no responses which is... disappointing.  However, maybe I posted this on a bad day for view.

 

I'm really curious to hear what other folks think and do.  

 

Please respond if you have any interest in this topic, something to contribute, and the time to do so.  Just five minutes should do it.

 

Thanks!



[TOPIC: post.html]
#3

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

My games do not really follow a start, stop, restart format so mine are structured somewhat different.

 

I have a single scene (you could call this the game module) and show all other scenes via showOverlay() so I have no scene management and refreshing to really worry about.  In my main scene I only have UI/UX, onFrame(), onKey() and onTouch().

 

Now things get more complicated...  I then instantiate 2D arrays of modules to build my world.  Each module is completely self-contained and only exposes an interface so that the UI can use it.  Otherwise they are responsible for their full lifetime.

 

I then have lots of helper modules for things like networking, IAPs, translations, z buffer, texture/asset managers, static maps, sounds, particle effects, shaders and various vehicle managers.

 

Not sure if this was what you were asking for or not?



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

@SGS - Thanks for the answer.  That was perfectly fine.  

 

Your game architecture seems more like a spider (for lack of a better analogy) with the main scene being the body and the legs being all the modules/helpers.

 

Very interesting.



[TOPIC: post.html]
#5

remiduchalard

[GLOBAL: userInfoPane.html]
remiduchalard
  • Contributor

  • 305 posts
  • Corona SDK

My game is base on a few levels of init.

init the game

   init a party

      init a level

 when my game is finish if the user restart the level it's reload only the level, if he go to the next level it's init again party and level... Like this there is no loading

The rest of the module don't work vertically (play,pause, replay...) they work independently 

I have functions who manage the time. (remove visual effect if under a number of fps etc)

I have a module who manage timer, transition, enterframe (to pause them, x2,x0.5, synchronise when there is hundred of them, resume, finish...)

I have a module who manage sound (to don't have too much sound play at the same time and too loud)

Manage visual effect (filter when you lose life, use spell, particules for blood and dust)

A module with ML who adapt the level to the player in real time.

Something to manage object in 3D isometric.

Function who manage texture memory (release when there is a warning), load on demand and on the availability of the device



[TOPIC: post.html]
#6

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

So to elaborate a bit more....  I try and maintain an OOP approach.

 

For example, I have building.lua which is approx 4k lines of code and this completely handles an instance of a tile/building. 

 

This will expose properties and functions so that the main scene can manipulate it, functions like selectBuilding(), moveBuildingTo(), removeBuilding(), drawBackground(), etc. 

 

I can then define my world as buildings[x][y] = <instance of building.lua>

 

This makes the actual UI coding straightforward.  So if I want to add a road at 13,5 I simply call buildings[x][y]:addRoad().  In that function is all the logic for spawning a road and linking it up with neighbouring roads.



[TOPIC: post.html]
#7

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,810 posts
  • Corona SDK

 

For example, I have building.lua which is approx 4k lines of code

 

 

 

 

Woah, time to refactor ;)

 

Haha, in the Corona version of my game I had modules 10,000 lines long which became a nightmare to debug - now I'm working in Unity I become queasy any time a class goes over 250 lines!



[TOPIC: post.html]
#8

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

now I'm working in Unity I become queasy any time a class goes over 250 lines!

 

But surely most of that is just pointless squiggly brackets?  :lol:



[TOPIC: post.html]
#9

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 563 posts
  • Corona SDK

RG,

 

1. am experienced game developer - longtime corona.

 

2. yes .. always like to use a game module similar to how yours is defined. Mine is just not as elaborate as yours.

I have broke from using a game module a time or two, but I always prefer to use some version of a game module.

 

3. I always call versions of create() & init() from my composer scene:create and scene:show .. but I will normally have several functions handling all the create stuff, like  'createBoard', 'createPlayer', 'createUI', etc..  It then depends on what I need done by init() as to wether it is called from scene:show or scene:create.  I don't call it init(), call it different things depending the game. 

 

4. n/a  I use a game module.

 

5. I do like to break down the action of the gameScene into regular common actions, common to most games..  like you do, I am just not disciplined enough to do it consistently.  But I am working on making myself a template with some of the same function breakouts as you list them, and hope to stat using them consistently.  I have 'classes or modules' that I use for menus, messages,  and effects - those regular and repeated things used in most apps/games. These help keep my gameScene from getting to large.

 

My general app layout is usually close to this

 

main.lua  ( handles all the data setup and services(ads, backend, multiplayer) )

gameServer.lua ( module to handle multiplayer stuff )

constants.lua ( global module for constants and standard things like screen dims that are used repeatedly throughout that app )

mainScene.lua ( main menu - each menu item will call a scene or overlay )

setupScene.lua(  customize choices of game play for player - avatar selection, game speed,  etc..)

gameScene.lua ( all game mechanics and action )

 

 

 

then I have a few standard overlay templates I use for help-info, options, credits, game promos etc...

 

 

6. I like this discussion. It is good to see how others tackle these common situations. There seems endless ways to do most things.

 

Thanks for posting the topic!

Bob



[TOPIC: post.html]
#10

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

I tend to miss out so much on forums lately. Glad you posted this also to the Slack channel.

 

I'm developing games professionally for 7 years(6 of it is with Corona) now so I guess you can call me experienced.

 

- For casual games, I use a single gameLevel.lua file(a Composer scene actually) and fit all the related functions in this single file. Since it doesn't get cluttered so much when developing casual games, I still prefer this approach.

 

- For point & click adventure games I did in the past, I was using that gameLevel.lua file to call another file where there are many functions like loadLevel(), createLayers() etc. Looking back, it doesn't seem necessary and probably could have done it like the casual games I make today but that's what I did for those games. By the way, that file I called for functions was somewhere near 6k lines of code so :)

 

I can't say I got a naming standart like yours since I'm the sole developer for all my projects but I have something similar to yours. I prefer using a createX(), destroyX(), moveX(), endGame() kind of naming scheme for the games I make. When I need to fix or add some stuff, I search for those keywords(create, destroy, move, end) in the code.

 

 

This is not some concept I got from somewhere but the way I come to terms after developing many games. This is working as expected for the casual games at the moment but I don't know if things will change if I dive into a relatively bigger game.

 

I would really love to see more discussions like this here which means I have to keep following the forums more often. :)



[TOPIC: post.html]
#11

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

@bgmadclown

 

 You can have the forums email you all updates immediately like I do. :)    Then you'll never miss out.



[TOPIC: post.html]
#12

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

Other than the topics I follow, that would be too much for me :P



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,895 posts
  • Enterprise

  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!


[TOPIC: post.html]
#14

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

@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 ;)

 

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!


Edited by sporkfin, 16 May 2018 - 06:42 PM.


[TOPIC: post.html]
#15

remiduchalard

[GLOBAL: userInfoPane.html]
remiduchalard
  • Contributor

  • 305 posts
  • Corona SDK

This topic is very interesting :) 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)



[TOPIC: post.html]
#16

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

@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 *



[TOPIC: post.html]
#17

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

@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!



[TOPIC: post.html]
#18

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

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



[TOPIC: post.html]
#19

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

This topic is very interesting :) 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%)

 

>> I can't give exact percentages, but SSK2 goes in most of my projects and that weighs in at ~15K lines.

 

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)

>> All numbers are MINUS SSK and MINUS COMMENTS (comments typically add 10..30%)

>> Big non-game app  : 30K 

>> Typical client game: 7K .. 10K 

>> My own games: 10K .. 30K

>> Typical template (as sold on marketplace) 0.5K .. 1K

 

 

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

>> Game-play prototyping, tuning, and polishing take me the longest.  All other parts are less than 10% combined.

 

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))

>> Most of my code is freely shared. 

>> As for the paid content, Ask me again in about a month.  I've got a series of new templates, tools, and starters coming.

 

 

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)

>> Corona physics mostly.  


Edited by roaminggamer, 17 May 2018 - 07:13 PM.


[TOPIC: post.html]
#20

remiduchalard

[GLOBAL: userInfoPane.html]
remiduchalard
  • Contributor

  • 305 posts
  • Corona SDK

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 :)

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)

Attached Files



[TOPIC: post.html]
#21

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

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]



[TOPIC: post.html]
#22

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

@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.


Edited by sporkfin, 18 May 2018 - 04:29 AM.


[TOPIC: post.html]
#23

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,108 posts
  • Corona SDK

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?



[TOPIC: post.html]
#24

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,345 posts
  • Enterprise

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
-------------------------------------------------------------------------------



[TOPIC: post.html]
#25

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

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.




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]