-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_types.py
116 lines (88 loc) · 3.58 KB
/
tile_types.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
109
110
111
112
113
114
115
116
'''
Tiles are parts of the map that can be interacted with. They represent doors/pits/entrances, etc.
- Additional tile properties can be added for other effects ('does_damage = bool', etc.)
- Tiles are generated with the 'procgen.py' module and passed to the GameMap class to be rendered by the engine.
'''
#_______________________________________________________________________// MODULES
from typing import Tuple
import numpy as np
from colors import *
#_______________________________________________________________________// DATA (TYPES)
# Structures the datatype for tile graphics (Using Numpy datatypes/dtype)
# This is for the "dark" property of the of the tile_datatype
graphic_symbol = np.dtype(
[
("ch", np.int32), # Unicode / symbol for tile
("fg", "3B"), # Reserves 3 unsigned bytes for setting foreground ('fg') RGB values
("bg", "3B"), # Same thing for background ('bg') RGB color
]
)
# Tile struct for statically defined tiles
tile_datatype = np.dtype(
[
("walkable", np.bool), # True if this tile can be walked over.
("transparent", np.bool), # True if this tile doesn't block FOV.
("dark", graphic_symbol), # Symbol, foreground color, background color (not explored)
("light", graphic_symbol), # Symbol, foreground color, background color (explored)
]
)
#_______________________________________________________________________// FUNCTION
# Pass in values to return an array - renders as a tile on the game map
def new_tile(
*, # Enforces keyword usage so parameter order doesn't matter
walkable : int, # Can pass through (True/False)
transparent : int, # Display background color or not (True/False)
dark : Tuple[ # Symbol and RGB colors for foreground and background
int,
Tuple[int, int, int],
Tuple[int, int, int]
],
light : Tuple[
int,
Tuple[int, int, int],
Tuple[int, int, int],
]
) -> np.ndarray:
'''
Helper function for defining individual tile types
'''
return np.array(
(walkable, transparent, dark, light),
dtype=tile_datatype,
)
#_______________________________________________________________________// VARIABLES (TUPLES)
#'SHROUD' represents unexplored, unseen tiles.
SHROUD = np.array((ord(" "), (255, 255, 255), (0, 0, 0)), dtype=graphic_symbol)
#_______________________________________________________________________// DATA (TUPLES) - TILES
grass = new_tile(
walkable =True,
transparent =True,
dark =(ord(" "), green, dark_green),
light =(ord("`"), light_green, green), # No difference when explored
)
dirt = new_tile(
walkable =True,
transparent =True,
dark =(ord(" "), dark_brown, dark_brown),
light =(ord("."), light_brown, brown),
)
floor_wood = new_tile(
walkable =True,
transparent =False,
dark =(ord("="), brown, brown),
light =(ord("="), brown, light_tan), # No difference when explored
)
wall = new_tile(
walkable =False,
transparent =False,
dark =(ord(" "), dark_gray, dark_gray),
light =(ord(" "), gray, gray)
)
# TO ADD:
#-----------------
# Tree (walkable IF {equipment[shoes]})
# Mountain (walkable IF {equipment[rope]})
# Entrance-building (trigger)
# Entrance-dungeon (trigger + load new map)
# Lava (trigger player damage)
# Etc.