# Shorty #02: Item management

# Introduction

In this video we are taking a look at item management: how to position items on a board, how to move things around, etc.
We are going to cover items placement on the Board, movement of movable objects, retrieving of an object at given coordinates and deletion of items.

# hac-game-lib

To follow this shorty 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-shorty-2
cd hgl-shorty-2
source bin/activate
pip3 install -i https://test.pypi.org/simple/ hac-game-lib

# Video

This second shorty is also done under the form of a code along video available on Youtube (it's getting better, right?).

# Code

Here is the final code of this shorty.

from gamelib.Board import Board
import gamelib.Utils as Utils
import gamelib.Sprites as Sprites
import gamelib.Constants as Constants
from gamelib.Characters import Player, NPC
from gamelib.Structures import Wall
import time

myboard = Board(
    size=[5,5], 
    ui_borders=Utils.WHITE_SQUARE, 
    ui_board_void_cell=Utils.BLACK_SQUARE
    )


myboard.place_item(
    Wall(model=Utils.GREEN_SQUARE),
    3,
    1
    )

myplayer = Player( model=Sprites.COWBOY )
myboard.place_item( myplayer, 0, 4 )

npc1 = NPC( model=Sprites.HAPPY_GHOST )
myboard.place_item( npc1, 2, 2 )

myboard.display()
time.sleep(1)

myboard.move( npc1, Constants.LEFT, 1 )

myboard.display()
time.sleep(1)

myboard.move( npc1, Constants.UP, 1 )

myboard.display()
time.sleep(1)

if npc1 == myboard.item(1,1):
    myboard.move( myboard.item(0,4), Constants.DOWN,1)

myboard.display()
time.sleep(1)

myboard.clear_cell(3,1)

myboard.display()
time.sleep(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