From Scalable Game Design wiki
Jump to navigation Jump to search

Another common behavior is pushing. In the game of Sokoban a person is supposed to push boxes around a maze onto targets. The box should only move if it could move onto a target spot or a regular ground tile. If the box is blocked because it is facing a wall in the direction of the push then neither it not the person pushing it should move.

A simple solution pattern distributes the responsibility of checking for walls and moving between the person and the box agent


. Our situation from left to right is a person, a box and a target. The user tries to push the box via the person agent to the right. First the person checks if it sees a box to the right. If so it sends a “push_right” message to the box. The box reacts by checking to its right if there is a target. There is a target to the right. The box moves itself to the right and sends a “move_right” message to the person making the person moving to the right as well.

A simple modification will allow the person to move more boxes. When a box receives the “push_right” message it could check for another box to the right. If there is another box then it would recursively propagate the “push_right” to all the boxes to the right. When the right most box receives the message it could start moving the box to its left to move right making all the boxes move including the person. The scheme can be further refined to limit the number of boxes that can be pushed. A numerical attribute called strength defined by the person can be propagated and decremented from left to right. If the number of boxes exceeds the strength then the boxes cannot be pushed.

Games/Simulations that use this pattern