34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from src.agent.map.gameMap import GameMap
|
|
from mesa.visualization.modules import CanvasGrid
|
|
from mesa.visualization.modules.TextVisualization import TextElement
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
|
|
|
|
|
def player_representation(agent):
|
|
portrayal = {"Shape": "sprites/hero.png",
|
|
"Layer": 1}
|
|
if agent.isBox:
|
|
portrayal["Shape"] = "sprites/box.png"
|
|
portrayal["Layer"] = 0
|
|
elif agent.isCreature:
|
|
portrayal["Shape"] = 'sprites/goblin.png'
|
|
return portrayal
|
|
|
|
grid = CanvasGrid(player_representation, 10, 10, 500, 500)
|
|
|
|
class MyTextElement(TextElement):
|
|
def render(self, model):
|
|
hp = str(model.get_hp())
|
|
position = str(model.get_position())
|
|
gold = str(model.get_gold())
|
|
|
|
return "Player hp: {}<br>Current position: {}<br>Player's gold: {}".format(
|
|
hp, position, gold)
|
|
|
|
server = ModularServer(GameMap,
|
|
[grid, MyTextElement()],
|
|
"Map",
|
|
{"x": 10, "y": 10})
|
|
server.port = 8081
|
|
server.launch()
|