# HAC Tutorial #01: The Game object

# Introduction

This first tutorial is all about the Game object!
The Game object is key to game management. It does a lot of things behind your back to keep track of every object you are going to use in your game.

By the end of these tutorials you will be able to do all that by yourself, but right now it ease the learning curve to rely on some (hopefully) robust pre-existing logic.

# hac-game-lib

To follow this tutorial you will need the hac-game-lib on your system.
You can either get it on Github or (this is the preferred solution) install it from PyPi by running:

pip3 install virtualenv --user
virtualenv hgl-tutorial-1
cd hgl-tutorial-1
source bin/activate
pip3 install -i https://test.pypi.org/simple/ hac-game-lib

For some reasons the dependencies seems to be skipped on Test PyPi.

# Video

This first tutorial is done under the form of a code along video available on Youtube (a bad one but bear with us, it'll become better over time).

# Code

Here is the final code of this tutorial.

from gamelib.Game import Game
from gamelib.Board import Board
import gamelib.Utils as Utils
import gamelib.Sprites as Sprites
from gamelib.Characters import Player
import time

mygame = Game(name='Demo game')
board1 = Board(name='Level 1', ui_borders=Sprites.WALL, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[0,0])
board2 = Board(name='Level 2', ui_borders=Utils.RED_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE, player_starting_position=[4,4])

mygame.player = Player(name='DaPlay3r', model=Sprites.UNICORN_FACE)


count = 0 
lvl = 1

while count < 10:
    lvl +=1 
    if lvl > 2:
        lvl = 1
    count += 1

# Share

If you like that content, feel free to share it on social platforms:

# Comments

Last Updated: 5/18/2019, 6:46:55 AM