Open Dev Kit Documentation :: Demo - Shape Stacker
The Shape Stacker demo is a 2D game about stacking randomly generated geometric shapes (squares and circles) on a platform, built usingHow it Works
- Game Initialization
- Upon starting the game, the
Start function is triggered. This initializes the camera view based on theWindow's height dimension (UpdateCamera ) and spawns the first shape using theSpawnShape function. - Shape Spawning Mechanics
- The
SpawnShape function selects a shape (either a square or circle) randomly. Shapes are resized (uniformly if a circle, to retain a 1:1 ratio), given a random color, and their orientation is set at random. The shape then starts oscillating horizontally across the platform, guided by a placementTimer (gPlacementTimer ). As theTimer runs, the total score gradually decreases, making the gameplay more engaging this way. - Player Controls
- Interaction with the game is done by pressing the left mouse button. A script located in the
Pressed Event of theKeybinds Resource is then executed. If a shape is currently active and oscillating, pressing the button makes it drop. The shape'sPhysics Type changes to "Dynamic," enabling gravity and collision physics. Dropping a shape successfully onto the platform increases the score. - Tick System and Game Over
- The
PositionTick function runs periodically (every 15ms) to monitor for game-over conditions. If any shape's Y-position drops below a predefined threshold, it is considered to have fallen off the platform, theEndGame function is called, which then transitions to theGame Over Scene and the game ends.
Adding a New Shape
Follow these steps to add a new shape to the demo:
- Create the New Shape:
- Open
.Tools >Resources - Double-click the
Shapes Sprite Resource . - Copy the square tile and paste it over to the blank tile beside the circle, as we'll be using that as a base for the new shape.
- Click on the imported square image to select it.
- Click anywhere on the sequencer to place it. You can confirm you have added it by seeing a new entry on the timeline sequencer located right below the sprite sequencer.
- Click on the newly placed square, which should be right on top of where the first one is.
- On the
Properties panel find the box besideOrientation . - Click and drag the arrow 2 notches either to the left or right to form the new shape: an octagon.
- Now click the
Add Box Collision icon ("Shared with whole Tile") to add a new collision box to the sequencer. - Set its
Size to the same as the other collision box. - Line it up with the other box.
- Rotate it like you did with the
Sprite , except using the arrow besideAxis Orientation this time.
- Open
- Set up the New Shape:
- Open
and select theTools >Globals / API gDefaultShapes variable. - Since there is now a new shape, we will increase the
Default Object count by clicking+ once besideDefault Object - Head down until you find the new entry (labeled "[3]") and add a new layer to it by clicking
+ once besideLayers . - Set the new
entry toSprite Shapes , since that's the name of theSprite Resource the new shape is located in. - If the new shape was created on the 3rd tile, type
2 as a value forTile . The count starts from 0, therefore the 3rd tile's # would be 2. - Set the
Placement Score value to any number similar to the other shapes above, and when configuring itsMin Scale , make sure the first two values (X & Y) are the same as we want uniform scaling for the octagon to properly use 1:1 scaling. Ignore the 3rd value (Z) since the project does not make use of the 3rd dimension. - Lastly, be sure to check
Square Scaling .
- Open
- Increase Platform Size:
- Although this is not a necessary step, it would still be a good idea to make the platform bigger so as to accommodate for the octagon being a more volatile shape.
- Load the
GameScene Scene , select theFloor actor and in theProperties panel set itsScale to something like6 . - With the platform being wider, it would now be a good idea to increase the horizontal oscillating distance when spawning a shape. Open
, select theTools >Globals / API gPlacementSpread variable and set itsDefault value to about300 . Depending on what size you gave the platform you may need to experiment somewhat with values to find something that works.
- Test the Game:
- Run the project to verify the new shape spawns and works as expected.
If you think anything is missing, please feel free to: submit documentation feedback on this page