Several recent posts on Corona’s forum have mentioned lines-of-code (LOC) metrics for some simple game mechanics, and it got me to wondering about what sort of metrics were “typical” of various little prototypes that I’ve tinkered with.
You can perhaps use these samples as rough guides for answering the question “what can be accomplished with x amount of coding?” Granted that not all coding styles are equivalent – the reader’s may be more/less verbose than my own – so take this as a rough guide only.
Note that all of the following prototypes were done with “plain vanilla out-of-the-box Corona.” None of the following prototypes use any other external plugins or libraries – the metrics given are for their entire set of code.
Also note that the genre of game can potentially be a significant factor to how much effort is needed to accomplish something minimally functional. All of the prototypes below are based on relatively simple genres to begin with.
Finally, note that none of these prototypes are full games. There’s almost always way more work involved in all the other aspects of a finished game, and these prototype metrics make no attempt whatsoever to capture any of those aspects.
~1 LOC
A frequent source of frustration in the forum seems to be the loading Tiled maps since (at present) Corona offers no built-in support. Well, let’s put that to rest, shall we?
With one line of code you can have a tiled map loader. Seriously. Here it is:
1 |
local map = require("your_exported_map") |
Since Tiled will export to Lua format, loading its data is crazy simple. Sure, it’ll take another 40 or so lines to actually render it in some minimal way, and maybe another 30 or so lines to implement a minimal camera for scrolling. (and perhaps many hundreds more lines if you had the lofty goal of implementing every last feature that Tiled supports, rather than just what you actually need) But I’ll leave those as tasks for the reader, or a later post, because it’s off-topic, and there’s really just not that much to it.
~300 LOC
300 lines of code is enough for a skeletal RPG framework, with tiled map loader and renderer, scrolling camera, doors and room-based lighting and a simple character:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
http://cloc.sourceforge.net v 1.64 T=0.02 s (385.0 files/s, 18096.1 lines/s) -------------------------------------------------------------------------------------- File blank comment code -------------------------------------------------------------------------------------- .\code\World.lua 17 6 68 .\code\Player.lua 14 7 60 .\code\Lighting.lua 7 2 36 .\code\KeyControls.lua 6 4 31 .\code\TouchControls.lua 6 1 29 .\code\Camera.lua 6 0 21 .\code\Door.lua 3 4 21 main.lua 7 0 20 -------------------------------------------------------------------------------------- SUM: 66 24 286 -------------------------------------------------------------------------------------- |
~400 LOC
400 lines of code is enough for a simple vertical shooter, with custom collision detection (you could perhaps do something similar, with less code, using the physics library, but it wasn’t appropriate here), pooled entities, and a scrolling camera/background (that really aren’t used here, but are present and ready just the same):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
http://cloc.sourceforge.net v 1.64 T=0.03 s (409.4 files/s, 16600.9 lines/s) ----------------------------------------------------------------------------------- File blank comment code ----------------------------------------------------------------------------------- .\code\EntityPool.lua 10 11 53 .\code\Game.lua 13 3 48 .\code\Player.lua 9 1 45 .\code\Rock.lua 8 1 37 .\code\Bullet.lua 8 2 35 .\code\Controls.lua 8 0 31 .\code\AABB.lua 6 0 25 .\code\Collision.lua 4 2 24 .\code\Background.lua 5 1 21 .\code\Camera.lua 4 1 17 main.lua 4 0 9 ----------------------------------------------------------------------------------- SUM: 79 22 345 ----------------------------------------------------------------------------------- |
~600 LOC
600 lines of code is enough for a one-tap “dash” -type game, with generative level content, scrolling camera, parallax background, some player effects, an AI player for “demo mode”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
http://cloc.sourceforge.net v 1.64 T=0.03 s (376.4 files/s, 29170.5 lines/s) ----------------------------------------------------------------------------------- File blank comment code ----------------------------------------------------------------------------------- .\code\World.lua 45 20 152 .\code\Trail.lua 18 33 125 .\code\Player.lua 9 3 79 .\code\Game.lua 13 4 65 .\code\Background.lua 7 0 47 .\code\Controls.lua 5 0 35 .\code\Autobot.lua 6 2 35 .\code\HUD.lua 6 0 33 .\code\Camera.lua 5 0 18 main.lua 2 0 8 ----------------------------------------------------------------------------------- SUM: 116 62 597 ----------------------------------------------------------------------------------- |
~1000 LOC
1000 lines of code is enough for a Lode Runner -type clone, with most of it being taken up by the enemy AI and supporting movement routines in Player (of which Enemy is a subclass) and Level:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
http://cloc.sourceforge.net v 1.64 T=0.03 s (370.5 files/s, 38474.5 lines/s) ----------------------------------------------------------------------------------- File blank comment code ----------------------------------------------------------------------------------- .\code\Player.lua 58 25 305 .\code\EnemyAI.lua 38 19 152 .\code\Level.lua 18 3 130 .\code\Enemy.lua 23 2 77 .\code\EntityList.lua 15 9 67 .\code\Game.lua 13 1 59 .\code\Controls.lua 7 1 53 .\code\Hole.lua 12 1 43 .\code\Bomb.lua 9 1 42 .\code\Gold.lua 6 0 28 .\code\Preloader.lua 5 0 13 main.lua 3 0 8 ----------------------------------------------------------------------------------- SUM: 207 62 977 ----------------------------------------------------------------------------------- |
~1300 LOC
1300 lines of code is enough for a fairly full-featured scrolling platformer, with a player character having multiple special moves (jump, double-jump, wall-cling/jump/slide), several special map objects (various spike hazards, lava hazard, springs, coins, stars):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
http://cloc.sourceforge.net v 1.64 T=0.05 s (324.9 files/s, 32936.6 lines/s) ----------------------------------------------------------------------------------- File blank comment code ----------------------------------------------------------------------------------- .\code\Player.lua 98 48 478 .\code\Level.lua 41 13 169 .\code\Game.lua 27 2 100 .\code\EntityList.lua 15 9 67 .\code\HUDStars.lua 16 3 64 .\code\HUDCoins.lua 16 2 58 .\code\Camera.lua 17 2 54 .\code\Controls.lua 8 0 51 .\code\BitmapFont.lua 8 1 36 .\code\Preloader.lua 8 1 35 .\code\Lava.lua 6 0 33 .\code\Bouncer.lua 7 2 29 .\code\Coin.lua 6 2 27 .\code\Constants.lua 7 2 22 .\code\Background.lua 1 0 21 main.lua 2 0 8 ----------------------------------------------------------------------------------- SUM: 283 87 1252 ----------------------------------------------------------------------------------- |
Wrapping Up
My hope with this post is, to the extent that you might be aiming to achieve something similar to one of the prototypes above, that the reader might find these code metrics useful to give a reasonable guesstimate of how much effort might be involved. Happy coding! 🙂