-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathtiles.py
108 lines (94 loc) · 3.6 KB
/
tiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# SPDX-FileCopyrightText: 2020 FoamyGuy for Adafruit Industries
#
# SPDX-License-Identifier: MIT
from tilegame_assets.states import (
STATE_MAPWIN,
STATE_LOST_SPARKY,
STATE_MINERVA,
)
# pylint: disable=unused-argument
# Minerva before_move. Set game state to STATE_MINERVA
def minerva_walk(to_coords, from_coords, entity_obj, GAME_STATE):
GAME_STATE["STATE"] = STATE_MINERVA
return False
# Sparky before_move. If user does not have a Mho in inventory they lose.
# If user does have Mho subtract one from inventory and consume Sparky.
def sparky_walk(to_coords, from_coords, entity_obj, GAME_STATE):
if GAME_STATE["INVENTORY"].count("mho") > 0:
GAME_STATE["INVENTORY"].remove("mho")
GAME_STATE["ENTITY_SPRITES_DICT"][to_coords].remove(entity_obj)
if len(GAME_STATE["ENTITY_SPRITES_DICT"][to_coords]) == 0:
del GAME_STATE["ENTITY_SPRITES_DICT"][to_coords]
if (-1, -1) in GAME_STATE["ENTITY_SPRITES_DICT"]:
GAME_STATE["ENTITY_SPRITES_DICT"][-1, -1].append(entity_obj)
else:
GAME_STATE["ENTITY_SPRITES_DICT"][-1, -1] = [entity_obj]
return True
else:
GAME_STATE["STATE"] = STATE_LOST_SPARKY
return True
# Robot before_move. If user has all Hearts they win the map.
def robot_walk(to_coords, from_coords, entity_obj, GAME_STATE):
if GAME_STATE["INVENTORY"].count("heart") == GAME_STATE["TOTAL_HEARTS"]:
GAME_STATE["STATE"] = STATE_MAPWIN
return True
return False
# Remove the item from this location and add it to player inventory.
def take_item(to_coords, from_coords, entity_obj, GAME_STATE):
print(entity_obj)
GAME_STATE["INVENTORY"].append(entity_obj["map_tile_name"])
GAME_STATE["ENTITY_SPRITES_DICT"][to_coords].remove(entity_obj)
if len(GAME_STATE["ENTITY_SPRITES_DICT"][to_coords]) == 0:
del GAME_STATE["ENTITY_SPRITES_DICT"][to_coords]
if (-1, -1) in GAME_STATE["ENTITY_SPRITES_DICT"]:
GAME_STATE["ENTITY_SPRITES_DICT"][-1, -1].append(entity_obj)
else:
GAME_STATE["ENTITY_SPRITES_DICT"][-1, -1] = [entity_obj]
return True
# main dictionary that maps tile type strings to objects.
# each one stores the sprite_sheet index and any necessary
# behavioral stats like can_walk or before_move
TILES = {
# empty strings default to floor and no walk.
"": {"sprite_index": 10, "can_walk": False},
"floor": {"sprite_index": 10, "can_walk": True},
"top_wall": {"sprite_index": 7, "can_walk": False},
"top_right_wall": {"sprite_index": 8, "can_walk": False},
"top_left_wall": {"sprite_index": 6, "can_walk": False},
"bottom_right_wall": {"sprite_index": 14, "can_walk": False},
"bottom_left_wall": {"sprite_index": 12, "can_walk": False},
"right_wall": {"sprite_index": 11, "can_walk": False},
"left_wall": {"sprite_index": 9, "can_walk": False},
"bottom_wall": {"sprite_index": 13, "can_walk": False},
"robot": {
"sprite_index": 1,
"can_walk": True,
"entity": True,
"before_move": robot_walk,
},
"heart": {
"sprite_index": 5,
"can_walk": True,
"entity": True,
"before_move": take_item,
},
"mho": {
"sprite_index": 2,
"can_walk": True,
"entity": True,
"before_move": take_item,
},
"sparky": {
"sprite_index": 4,
"can_walk": True,
"entity": True,
"before_move": sparky_walk,
},
"minerva": {
"sprite_index": 3,
"can_walk": True,
"entity": True,
"before_move": minerva_walk,
},
"player": {"sprite_index": 0, "entity": True,},
}