SECTION II: BUILD III DESIGN HIGHLIGHTS
Peg Puzzle – Build III – Major Design Highlights
- MULTI-DIMENSIONAL LUA TABLES SUPPORTING GAME OBJECT LOCATIONS AND POTENTIAL HOP PATHS, BY LEVEL – Working from the one-dimensional tables used for a single game level – this build expands those tables to 2 dimensions to accommodate using ‘level’ as a key index.
- SUCCESS BASED TRANSITIONS TO HIGHER LEVELS– The game is now designed to constrain access to higher (more challenging) game levels – dependent upon successful completion of a previous level.
Build III is a close derivative of our Build II project. All changes to support expansion into a multi-level Peg Puzzle Defold game are going to be constrained to the controller.script and mainMenu.gui_script files. Importantly, the main.collection structure and mainMenu structures remain the same, the graphicAssets and textAssets atlases remain the same and the render, font and module components also remain the same. The next section provides a detailed comparison of the new Build III source code as compared with the Build II (single game level) code.
Section III: BUILD III SCRIPT COMPONENT FILES
Peg Puzzle — Build II: Script Enhancements:
The revised controller.script for this final build of the Peg Puzzle Defold Game performs several important primary functions:
- It sets GLOBAL variables for (1) maximum number of levels, (2) maximum number of locations and (3) maximum number of hop paths
- It defines a new local variable for the location of the empty pegHole at the beginning of play for each of the four levels
- The variable phXCoord is expanded to two-dimensions: [level] and [location]; similarly, phYCoord is expanded as well. Geometries for each of the levels are populated into these Lua Tables.
- Similarly, startingPos, middlePos and endingPos (which define the potential hop paths that a peg can take) is expanded into two-dimensional Lua Tables as well.
- All For/Next loops that iterate through these tables have been modified to accommodate the level index reference
The following file comparison highlights each of the line changes made. PS: I’m using the online service DiffNow to conduct these script file comparisons – it’s a pretty handy free utility.
Build III Build II
The revised mainMenu.gui_script for this final build of the Peg Puzzle Defold Game performs several important primary functions:
- A new local variable (remainingPegsToPass) is declared – which defines how many pegs must be remaining on the board to consider the player to have passed that level. Note – these can be adjusted to either make play easier, or harder.
- All For/Next loops that iterate through each of the levels have been modified to reflect the global variable NUM_LEVELS
- Logic has been included to determine if a player has passed a level – aka, is now able to play the next level in the game
The following file comparison highlights each of the line changes made.
Build III Build II
That’s it – really not that many modifications required – the most difficult aspect was probably working through each of the x/y coordinates for the peg holes in each of the level scenarios and also determining each of the possible hop paths that would need to be evaluated.
Completion of the Peg Puzzle Game Tutorial – Build III:
Whew – we’ve covered a lot of ground, but hopefully, the structure of the Defold game project and the three step approach made sense. The Peg Puzzle isn’t quite a market-ready product – but it gets close.
I hope the abbreviated descriptions during this three-part tutorial made it easier to digest all the material. If you think I should add more detail related to any piece of this tutorial – or if you have a question on how it works — please drop me a note in the comment box below. I’ll get right back to you. Also – please let me know if you find these tutorials helpful. I look forward to your feedback.
Here are the hyperlinks to each of the Peg Puzzle Tutorials:
E1 – The Opening SplashScreens and Level Selection Panel (Build I)
E2 – A Full Game focused on a Single Level – a 10 Location Triangle (Build II)
E3 – The final four-level Peg Puzzle Game (Build III)
All the best – Dave