-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconstants.py
197 lines (145 loc) · 3.99 KB
/
constants.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import arcade
import isometric
from isometric import IsoList
"""
VARIABLES
"""
# Isometric Sprite Data
TILE_WIDTH, TILE_HEIGHT = 160, 80
SPRITE_SCALE = 0.6
FLOOR_TILE_THICKNESS = 20
# Window Information
SCREEN_WIDTH, SCREEN_HEIGHT = arcade.get_display_size()
WINDOW_NAME, FULL_SCREEN = "Temporum: The Melclex Incident", True
# Movement dictionary
DIRECTIONS = {(0, 1): 0, (1, 0): 1, (0, -1): 2, (-1, 0): 3}
# The Isolist That holds all isometric items
ISO_LIST = IsoList()
GROUND_LIST = IsoList()
# A list of walls for line of sight
WALLS = []
# The Player Object
PLAYER = None
# Map Information
CURRENT_MAP_SIZE = 0, 0
"""
FUNCTIONS
"""
def restart():
"""
Resets all the constants.
"""
global ISO_LIST
ISO_LIST = isometric.IsoList()
global GROUND_LIST
GROUND_LIST = isometric.IsoList()
set_player(None)
set_map_size([0, 0])
stop_music()
def set_player(player):
"""
Set the player
:param player: the player object
"""
global PLAYER
PLAYER = player
def set_map_size(size):
"""
set map size
:param size: a tuple/list of type (int, int)
"""
global CURRENT_MAP_SIZE
CURRENT_MAP_SIZE = tuple(size)
def clamp(value, low=0, high=1):
"""
clamp value
:param value: value
:param low: lowest possible value
:param high: highest possible value
:return: the clamped value
"""
return min(max(value, low), high)
def round_to_x(value, x):
"""
round value to the nearest multiple of x
if you have 16 and round to 5 it will return 15.
:param value: the value to round
:param x: the number to round to.
:return: the rounded value
"""
return int(round(value/x)*x)
def floor_to_x(value, x):
"""
round value to the next lowest multiple of x.
if you have 19 and floor to 5 it will return 15
:param value: value to round
:param x: the number to floor to
:return: the floored value
"""
return int(value/x)*x
def iso_append(item):
"""
Add an iso sprite to the iso list.
Will not add an item more than once, and will not add an item that is in the ground list.
:param item: an iso sprite.
"""
if item not in GROUND_LIST and item not in ISO_LIST:
ISO_LIST.append(item)
def iso_extend(iterable: iter):
"""
appends all items in the inputted iterable to the iso list.
:param iterable: a iterable of iso sprites.
"""
for item in iterable:
iso_append(item)
def iso_strip(iterable: iter):
"""
removes all items in inputted iterable from iso list
:param iterable: an iterable of iso sprites
"""
for item in iterable:
ISO_LIST.remove(item)
def iso_remove(item):
"""
removes the inputted iso sprite from the iso list
only works if the item is in the iso list.
:param item: an iso sprite
"""
if item in ISO_LIST:
ISO_LIST.remove(item)
def iso_hide(iterable: iter):
strips = []
for item in iterable:
if item.hidden is not None and item in ISO_LIST:
item.texture = item.hidden
item.hide = True
else:
strips.append(item)
iso_strip(strips)
def iso_changed():
# If the iso list has changed or an item in the list has changed it's W value. then tell the program to resort
# the iso list when the draw function is called.
ISO_LIST.changed = True
def set_floor(items):
# set the floor tiles.
global GROUND_LIST
GROUND_LIST = IsoList()
GROUND_LIST.extend(items)
GROUND_LIST.reorder_isometric()
"""
AUDIO FUNCTIONS
"""
# The base music and music player.
BASE_MUSIC = arcade.load_sound("audio/The Workshop 44100Hz Mono 16 bit.wav")
MUSIC_PLAYER = None
def start_music():
# starts the music.
global MUSIC_PLAYER
if MUSIC_PLAYER is None:
MUSIC_PLAYER = BASE_MUSIC.play(volume=0.15, pan=0.0, loop=True)
def stop_music():
# stops the music
global MUSIC_PLAYER
if MUSIC_PLAYER is not None:
BASE_MUSIC.stop(MUSIC_PLAYER)
MUSIC_PLAYER = None