Actions

Difference between revisions of "Gameboard"

From Future Skill

Line 15: Line 15:
 
from gameboard import GameBoard
 
from gameboard import GameBoard
 
from gameboard_helpers import CommonSetups, Style
 
from gameboard_helpers import CommonSetups, Style
 +
 +
tiles = {
 +
  'grass': {'color': 'green', 'line_color': 'darkgreen'},
 +
  'mud': {'color': 'brown','line_color': 'darkgrey'}
 +
}
  
 
class Challenge:
 
class Challenge:
Line 21: Line 26:
 
     board = GameBoard()
 
     board = GameBoard()
 
     CommonSetups.square(board)
 
     CommonSetups.square(board)
     Style.topdown(board, context.canvas)
+
     Style.topdown(board, context.canvas, tiles)
     board.fill(10, 10)
+
     board.fill(10, 10, {'tile_id'='grass'})
 +
    board.add_cell(2, 3, {'tile_id'='mud'})
 
</nowiki>
 
</nowiki>
 
</div>
 
</div>
  
 
The ''CommonSetups'' class configures the board to use a square tiled grid with four directions.
 
The ''CommonSetups'' class configures the board to use a square tiled grid with four directions.
The ''Styles'' class then configures how the board is displayed, with what tiles and how they are laid out.
+
The ''Styles'' class then configures how the board is displayed: the look of the tiles and how they are laid out.
 
[TODO] add link to documentation for ''CommonSetups'' and ''Styles''.
 
[TODO] add link to documentation for ''CommonSetups'' and ''Styles''.
  

Revision as of 12:16, 8 April 2021

[DRAFT] The GameBoard library

A reusable and configurable system for game-like challenges.

[TODO]

  • Board quick setup
  • Creating and placing a gamepiece
  • Pathfinding
  • Styling concepts
  • Custom board setup

GameBoard quick setup

Here's an example to quickly get up and running:

from gameboard import GameBoard
from gameboard_helpers import CommonSetups, Style

tiles = {
  'grass': {'color': 'green', 'line_color': 'darkgreen'},
  'mud': {'color': 'brown','line_color': 'darkgrey'}
}

class Challenge:
  fn __init__(self, context):
    ...
    board = GameBoard()
    CommonSetups.square(board)
    Style.topdown(board, context.canvas, tiles)
    board.fill(10, 10, {'tile_id'='grass'})
    board.add_cell(2, 3, {'tile_id'='mud'})

The CommonSetups class configures the board to use a square tiled grid with four directions. The Styles class then configures how the board is displayed: the look of the tiles and how they are laid out. [TODO] add link to documentation for CommonSetups and Styles.

You can fit the board into view with the function fit_board_into(board, x, y, w, h), provided in the gameboard_helpers module.

GamePiece

The GamePiece class should be used for anything that can be placed on the GameBoard. You'll mainly control which cell on the board it's located on.

from gameboard import GameBoard, GamePiece

class Challenge:
  def __init__(self, context):
    board = GameBoard()
    actor = GamePiece(context.canvas.new_circle(1.0, '#FF00FF'))
    board.place_game_piece(actor, 1, 1)

You can use it as-is for many cases or create your own derived class from it for more flexibility.