Actions

You can create a board and design tokens on it until now. But they can’t move yet.

The act() method

The board and all tokens can be controlled by the act() method. This method is called again and again (to be exact: Every board.speed time units) until the game is finished.

First Token

When you create a token, you can use the decorator @register to add an act() method to the field or to your tokens:

 1import miniworldmaker
 2
 3board = miniworldmaker.TiledBoard()
 4board.columns = 20
 5board.rows = 8
 6board.tile_size = 42
 7board.add_background("images/soccer_green.jpg")
 8board.speed = 30
 9player = miniworldmaker.token()
10player.add_costume("images/player_1.png")
11player.direction = 90
12@player.register
13def act(self):
14    self.move()
15
16board.run()

What happens here?

  • Lines 12-14: The decorator @player.register binds the act method to the player object.

In a similar way you will later often register reactions to events on objects (e.g. reactions to keyboard or mouse inputs or collision checks).

Outlook