Cubiscape – core gameplay

This is the first post in a series i plan to write about making my latest Android game. The first thing I want to write about are the elements of the core gameplay – how the game works and why I designed it that way.

If you haven’t checked out the game yet let me quickly describe it to you. Cubiscape is a puzzle game where in each level your goal is to get the blue ball to the exit (marked with a green tile). A picture is worth a thousand words, so here is a screenshot of one such level:

Cubiscape level example

You can see the blue ball being chased by the red cube. The game is turn based, so each round both the ball and the cube can move by one tile. In this case, the player (in the role of the ball) wins easily. But we are not here to discuss the solutions to particular levels, but rather how the game works.

When I was designing the game I realized that there are two main things in the game: Tiles are the stationary stuff that you can walk on and that might react to you walking on them (like the Exit, which will cause you to win the game when you reach it). Actors are those who do the walking – the player (blue ball) and the enemies (red cubes).

There are many types of tiles in the game – walls, teleports, buttons, traps and so on. Each of these react differently to Actors stepping on them or even prevent them from doing so, but other than that they are very similar. This suggests that we can implement a base class that will handle the core behavior of a Tile and then create derived classes to implement the differences.

This is exactly how it is done. The base Tile class handles all the boring stuff that is the same for every Tile – keeping track of whether there is someone standing on it or not, where in the world it is placed and so on. The important stuff is handled in 5 methods that have to be overloaded in derived classes: CanEnter, OnEnter, CanLeave, OnLeave and Activate. It turns out that just by changing the behavior in these five functions one can implement a large variety of Tiles!

Let me first briefly describe what each method does (Note: i have ommited a few details for clarity, the true interface is slightly more complicated):

  • bool CanEnter(Actor a) – this one is pretty simple. It returns whether given Actor can step on this tile. For example the Wall tile always returns false because noone can go through walls in Cubiscape.
  • void OnEnter(Actor a) – here its a bit more complicated. This function does whatever is needed to do when an Actor actually steps on the tile. This can be a wide variety of things – for example the Teleport tile immediatelly moves the Actor a to another tile (lets call it X) if X.CanEnter(a) returns true.
  • bool CanLeave(Actor a) – again pretty simple. Returns true if given Actor can leave this tile. The Trap tile will return false for a few turns after the Actor steps on it.
  • bool OnLeave(Actor a) – this is mostly important to allow Tiles to keep track whether there is someone standing on them or not.
  • void Activate() – this activates the Tile. At first glance it might seem that it does the same as OnEnter, however this does something else. Several Tiles are inactive at first, so stepping on them does nothing. They have to be activated first. That’s precisely what this function does.

The main game loop then goes through all Actors and does something like this:

if (next_tile.CanEnter (actor) && current_tile.CanLeave (actor)) {
    current_tile.OnLeave (actor);
    enemy.Move ();
    next_tile.OnStep (actor);

Pretty straightforward. All the logic is hidden in the four magic functions! Again I have simplified this a bit to make it clear – for example the way an Actor chooses it’s next tile (where it wants to go) is not shown here. In the next post I will shed more light on that and also tell you more about the fifth core function (Activate) and explain what can be done with it.

2 thoughts on “Cubiscape – core gameplay”

  1. Hi saw your game review video on a youtube channel an d i think the channel is using bots to increase their view count because the views does not equal the like and comment in the video. the video has over 18,000 views but only 70 likes which in not possible a t all. Please keep me anonymous but I think the channel said it is paid content which means you paid for the review but they might be using bots which is highly possible

Leave a Reply

Your email address will not be published. Required fields are marked *