GameBox 0.0.5__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- GameBox/__init__.py +9 -18
- GameBox/_game.py +38 -0
- GameBox/basics/_net.py +29 -0
- GameBox/basics/_shapes.py +23 -0
- GameBox/basics/cammera.py +30 -0
- GameBox/basics/utils.py +17 -0
- GameBox/player/_player.py +35 -0
- GameBox/player/_playerControler.py +54 -0
- GameBox/player/_playerPhysics.py +105 -0
- gamebox-0.1.0.dist-info/METADATA +20 -0
- gamebox-0.1.0.dist-info/RECORD +14 -0
- {gamebox-0.0.5.dist-info → gamebox-0.1.0.dist-info}/WHEEL +1 -1
- GameBox/basics/Defaults.json +0 -12
- GameBox/basics/Functions.py +0 -43
- GameBox/basics/_core.py +0 -41
- GameBox/basics/camera.py +0 -14
- GameBox/basics/player.py +0 -284
- GameBox/basics/shapes.py +0 -30
- GameBox/entities/basicNPCs.py +0 -21
- GameBox/entities/basicTypes.py +0 -79
- GameBox/game.py +0 -30
- GameBox/inputs/BasicInput.py +0 -11
- GameBox/sound/BasicSound.py +0 -66
- GameBox/tilemap/editor.py +0 -267
- GameBox/tilemap/tilemap.py +0 -146
- gamebox-0.0.5.dist-info/METADATA +0 -40
- gamebox-0.0.5.dist-info/RECORD +0 -19
- {gamebox-0.0.5.dist-info → gamebox-0.1.0.dist-info}/licenses/LICENSE +0 -0
GameBox/basics/player.py
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import os
|
|
3
|
-
from ..basics._core import GLOBAL
|
|
4
|
-
|
|
5
|
-
class Player:
|
|
6
|
-
def __init__(self, pos, spritePath, dim, camera, scale = 1):
|
|
7
|
-
self.last_pos = pos
|
|
8
|
-
self.pos = pos
|
|
9
|
-
self.camera = camera
|
|
10
|
-
self.sprite = pygame.transform.scale_by(pygame.image.load(spritePath), scale)
|
|
11
|
-
self.collisions = []
|
|
12
|
-
self.width = dim[0]
|
|
13
|
-
self.height = dim[1]
|
|
14
|
-
self.Info = {
|
|
15
|
-
"velocity": [0, 0],
|
|
16
|
-
"on_ground": False
|
|
17
|
-
}
|
|
18
|
-
self.states = {}
|
|
19
|
-
self.currentState = None
|
|
20
|
-
GLOBAL.playerPosition = pygame.Rect(pos, dim)
|
|
21
|
-
self.screen = GLOBAL.screen
|
|
22
|
-
|
|
23
|
-
def display(self, dt):
|
|
24
|
-
self.collisions = GLOBAL.collisions
|
|
25
|
-
if self.currentState != None:
|
|
26
|
-
#state logic
|
|
27
|
-
self.changeState()
|
|
28
|
-
image = self.states[self.currentState]["animation"].update(dt)
|
|
29
|
-
self.screen.blit(image, self.pos)
|
|
30
|
-
else:
|
|
31
|
-
#if no states (when initalized first)
|
|
32
|
-
self.screen.blit(self.sprite, self.pos)
|
|
33
|
-
|
|
34
|
-
def changeState(self):
|
|
35
|
-
# Define collision rectangles relative to the player
|
|
36
|
-
collision_map = {
|
|
37
|
-
"^": pygame.Rect(self.pos[0], self.pos[1]-10, self.width, 10),
|
|
38
|
-
"_": pygame.Rect(self.pos[0], self.pos[1] + self.height+10, self.width, 10),
|
|
39
|
-
"<": pygame.Rect(self.pos[0]-10, self.pos[1], 10, self.height),
|
|
40
|
-
">": pygame.Rect(self.pos[0]+10 + self.width - 10, self.pos[1], 10, self.height),
|
|
41
|
-
"#": pygame.Rect((self.pos[0]-10, self.pos[1]-10), (self.width+20, self.height+20)),
|
|
42
|
-
"N": pygame.Rect((self.pos[0]-10, self.pos[1]-10), (self.width+20, self.height+20)),
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
for state, data in self.states.items():
|
|
46
|
-
condition = data.get("condition", "")
|
|
47
|
-
if len(condition) < 2:
|
|
48
|
-
print("Invalid condition:", condition)
|
|
49
|
-
continue
|
|
50
|
-
|
|
51
|
-
type_code, dir_code = condition[0], condition[1]
|
|
52
|
-
|
|
53
|
-
if type_code =="C":
|
|
54
|
-
rect = collision_map[dir_code]
|
|
55
|
-
hit = self.check_collisions(rect)
|
|
56
|
-
os.system("cls")
|
|
57
|
-
print(hit)
|
|
58
|
-
|
|
59
|
-
# Handle state change
|
|
60
|
-
if dir_code == "N":
|
|
61
|
-
if not hit:
|
|
62
|
-
self.currentState = state
|
|
63
|
-
break
|
|
64
|
-
else:
|
|
65
|
-
if hit:
|
|
66
|
-
self.currentState = state
|
|
67
|
-
break
|
|
68
|
-
elif type_code =="M":
|
|
69
|
-
#setup
|
|
70
|
-
if self.camera.type == "dynamic":
|
|
71
|
-
pos = self.camera.pos
|
|
72
|
-
else:
|
|
73
|
-
pos = self.pos
|
|
74
|
-
#code
|
|
75
|
-
if dir_code == "^":
|
|
76
|
-
if pos[1] - self.last_pos[1] >0:
|
|
77
|
-
self.currentState = state
|
|
78
|
-
break
|
|
79
|
-
elif dir_code == "_":
|
|
80
|
-
if pos[1] - self.last_pos[1] <0:
|
|
81
|
-
self.currentState = state
|
|
82
|
-
break
|
|
83
|
-
elif dir_code == "<":
|
|
84
|
-
if pos[0] - self.last_pos[0] <0:
|
|
85
|
-
self.currentState = state
|
|
86
|
-
break
|
|
87
|
-
elif dir_code == ">":
|
|
88
|
-
if pos[0] - self.last_pos[0] >0:
|
|
89
|
-
self.currentState = state
|
|
90
|
-
break
|
|
91
|
-
elif dir_code != "#":
|
|
92
|
-
if pos[0] == self.last_pos[0]:
|
|
93
|
-
self.currentState = state
|
|
94
|
-
break
|
|
95
|
-
elif dir_code == "N":
|
|
96
|
-
if pos[0] - self.last_pos[0] >0:
|
|
97
|
-
self.currentState = state
|
|
98
|
-
break
|
|
99
|
-
else:
|
|
100
|
-
raise Exception("Not combatible condition type")
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def check_collisions(self, test_rect):
|
|
105
|
-
for collider in self.collisions:
|
|
106
|
-
if test_rect.colliderect(collider):
|
|
107
|
-
return True
|
|
108
|
-
return False
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def Add_state(self, name, animation, condition):
|
|
112
|
-
self.currentState = name
|
|
113
|
-
self.states[name] = {"animation": animation, "condition": condition}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def update_position(self, UP_A):
|
|
117
|
-
x, y = self.pos
|
|
118
|
-
vx, vy = self.Info.get("velocity", [0, 0])
|
|
119
|
-
|
|
120
|
-
# --- Check X movement first ---
|
|
121
|
-
new_x = x + UP_A[0]
|
|
122
|
-
player_rect_x = pygame.Rect(new_x, y, self.width, self.height)
|
|
123
|
-
|
|
124
|
-
blocked_x = None
|
|
125
|
-
for rect in self.collisions:
|
|
126
|
-
if rect.colliderect(player_rect_x):
|
|
127
|
-
blocked_x = rect
|
|
128
|
-
break
|
|
129
|
-
|
|
130
|
-
if blocked_x:
|
|
131
|
-
vx = 0 # stop horizontal velocity when colliding
|
|
132
|
-
else:
|
|
133
|
-
x = new_x
|
|
134
|
-
|
|
135
|
-
# --- Check Y movement separately ---
|
|
136
|
-
new_y = y + UP_A[1]
|
|
137
|
-
player_rect_y = pygame.Rect(x, new_y, self.width, self.height)
|
|
138
|
-
|
|
139
|
-
blocked_y = None
|
|
140
|
-
for rect in self.collisions:
|
|
141
|
-
if rect.colliderect(player_rect_y):
|
|
142
|
-
blocked_y = rect
|
|
143
|
-
break
|
|
144
|
-
|
|
145
|
-
if blocked_y:
|
|
146
|
-
if vy > 0: # falling → landed on top of something
|
|
147
|
-
y = blocked_y.top - self.height
|
|
148
|
-
self.Info["on_ground"] = True
|
|
149
|
-
elif vy < 0: # jumping → hit head on ceiling
|
|
150
|
-
y = blocked_y.bottom
|
|
151
|
-
vy = 0 # stop vertical velocity
|
|
152
|
-
else:
|
|
153
|
-
y = new_y
|
|
154
|
-
self.Info["on_ground"] = False
|
|
155
|
-
|
|
156
|
-
# --- Apply movement ---
|
|
157
|
-
if self.camera.type == "dynamic":
|
|
158
|
-
self.last_pos = self.camera.pos
|
|
159
|
-
dx = x - self.pos[0]
|
|
160
|
-
dy = y - self.pos[1]
|
|
161
|
-
self.camera.move(dx, dy)
|
|
162
|
-
elif self.camera.type == "fixed":
|
|
163
|
-
self.last_pos = self.pos
|
|
164
|
-
self.pos = (x, y)
|
|
165
|
-
GLOBAL.playerPosition = pygame.Rect((x, y) (self.width, self.height))
|
|
166
|
-
|
|
167
|
-
# Save velocity (updated after collisions)
|
|
168
|
-
self.Info["velocity"] = [vx, vy]
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
#=== movement ===
|
|
173
|
-
|
|
174
|
-
def move_by_WSAD(self, speed):
|
|
175
|
-
# Get the state of all keys
|
|
176
|
-
keys = pygame.key.get_pressed()
|
|
177
|
-
|
|
178
|
-
# Update player position based on key presses\
|
|
179
|
-
x,y = self.pos
|
|
180
|
-
if keys[pygame.K_a]:
|
|
181
|
-
x -= -speed
|
|
182
|
-
if keys[pygame.K_d]:
|
|
183
|
-
x += -speed
|
|
184
|
-
if keys[pygame.K_w]:
|
|
185
|
-
y -= -speed
|
|
186
|
-
if keys[pygame.K_s]:
|
|
187
|
-
y += -speed
|
|
188
|
-
|
|
189
|
-
new_x = self.pos[0]
|
|
190
|
-
new_x-=x
|
|
191
|
-
|
|
192
|
-
new_y = self.pos[1]
|
|
193
|
-
new_y -= y
|
|
194
|
-
|
|
195
|
-
self.update_position((new_x, new_y))
|
|
196
|
-
|
|
197
|
-
def move_by_arrows(self, speed):
|
|
198
|
-
# Get the state of all keys
|
|
199
|
-
keys = pygame.key.get_pressed()
|
|
200
|
-
|
|
201
|
-
# Update player position based on key presses\
|
|
202
|
-
x,y = self.pos
|
|
203
|
-
if keys[pygame.K_UP]:
|
|
204
|
-
x -= -speed
|
|
205
|
-
if keys[pygame.K_DOWN]:
|
|
206
|
-
x += -speed
|
|
207
|
-
if keys[pygame.K_LEFT]:
|
|
208
|
-
y -= -speed
|
|
209
|
-
if keys[pygame.K_RIGHT]:
|
|
210
|
-
y += -speed
|
|
211
|
-
|
|
212
|
-
new_x = self.pos[0]
|
|
213
|
-
new_x-=x
|
|
214
|
-
|
|
215
|
-
new_y = self.pos[1]
|
|
216
|
-
new_y -= y
|
|
217
|
-
|
|
218
|
-
self.update_position((new_x, new_y))
|
|
219
|
-
|
|
220
|
-
def platformer_movement(self, speed, gravity, jump_force, max_gravity):
|
|
221
|
-
keys = pygame.key.get_pressed()
|
|
222
|
-
|
|
223
|
-
# Current velocity
|
|
224
|
-
vx, vy = self.Info.get("velocity", [0, 0])
|
|
225
|
-
|
|
226
|
-
# Horizontal movement
|
|
227
|
-
if keys[pygame.K_a]:
|
|
228
|
-
vx = -speed
|
|
229
|
-
elif keys[pygame.K_d]:
|
|
230
|
-
vx = speed
|
|
231
|
-
else:
|
|
232
|
-
vx = 0
|
|
233
|
-
|
|
234
|
-
# Gravity (affects vertical velocity, not position directly)
|
|
235
|
-
vy += gravity
|
|
236
|
-
if vy > max_gravity:
|
|
237
|
-
vy = max_gravity
|
|
238
|
-
|
|
239
|
-
# Jump (only if on_ground — assuming update_position sets this)
|
|
240
|
-
if keys[pygame.K_w] and self.Info.get("on_ground", False):
|
|
241
|
-
vy = -jump_force
|
|
242
|
-
|
|
243
|
-
# Save velocity
|
|
244
|
-
self.Info["velocity"] = [vx, vy]
|
|
245
|
-
|
|
246
|
-
# Move position — let update_position handle collisions
|
|
247
|
-
self.update_position((vx, vy))
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
class Animation:
|
|
252
|
-
def __init__(self, image, tileSize, dim, speed, frames, scale, X_offset):
|
|
253
|
-
self.image = image
|
|
254
|
-
self.tileSize = tileSize
|
|
255
|
-
self.fileDim = dim
|
|
256
|
-
self.speed = speed
|
|
257
|
-
self.images = []
|
|
258
|
-
self.timer = 0
|
|
259
|
-
self.frames = frames
|
|
260
|
-
self.index = 0
|
|
261
|
-
|
|
262
|
-
# Load images (crop each tile)
|
|
263
|
-
for y in range(dim[1]):
|
|
264
|
-
for x in range(dim[0]):
|
|
265
|
-
# Create a fresh surface for this tile
|
|
266
|
-
surface = pygame.Surface((tileSize, tileSize), pygame.SRCALPHA)
|
|
267
|
-
# Define the rectangle area on the sheet
|
|
268
|
-
rect = pygame.Rect(
|
|
269
|
-
x * tileSize +X_offset*tileSize,
|
|
270
|
-
y * tileSize,
|
|
271
|
-
tileSize,
|
|
272
|
-
tileSize
|
|
273
|
-
)
|
|
274
|
-
# Copy the correct tile into the new surface
|
|
275
|
-
surface.blit(image, (0, 0), rect)
|
|
276
|
-
# Store it in the images dictionary
|
|
277
|
-
self.images.append(pygame.transform.scale_by(surface, scale))
|
|
278
|
-
|
|
279
|
-
def update(self, dt):
|
|
280
|
-
self.timer += dt
|
|
281
|
-
if self.timer >= self.speed:
|
|
282
|
-
self.timer = 0
|
|
283
|
-
self.index = (self.index + 1) % self.frames
|
|
284
|
-
return self.images[self.index]
|
GameBox/basics/shapes.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class Rect:
|
|
4
|
-
def __init__(self, pos, dim, color, width=0):
|
|
5
|
-
self.pos = pos
|
|
6
|
-
self.color = color
|
|
7
|
-
self.width = width
|
|
8
|
-
self.rect = pygame.rect.Rect(pos, dim)
|
|
9
|
-
def display(self, screen, dt):
|
|
10
|
-
pygame.draw.rect(screen, self.color, self.rect, self.width)
|
|
11
|
-
def move(self, x, y, add=True):
|
|
12
|
-
if add:
|
|
13
|
-
self.pos.x+=x
|
|
14
|
-
self.pos.y+=y
|
|
15
|
-
else:
|
|
16
|
-
self.pos = x, y
|
|
17
|
-
self.rect.move(self.pos)
|
|
18
|
-
def resize(self, width, height):
|
|
19
|
-
self.rect.size = width, height
|
|
20
|
-
def change_color(self, color):
|
|
21
|
-
self.color = color
|
|
22
|
-
|
|
23
|
-
class Text:
|
|
24
|
-
def __init__(self, text, pos, size, color="black"):
|
|
25
|
-
self.font = pygame.font.Font(None, size)
|
|
26
|
-
self.textSurf = self.font.render(text, False, color)
|
|
27
|
-
self.pos = pos
|
|
28
|
-
|
|
29
|
-
def display(self, screen, dt):
|
|
30
|
-
screen.blit(self.textSurf, self.pos)
|
GameBox/entities/basicNPCs.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
from ..basics._core import GLOBAL
|
|
3
|
-
|
|
4
|
-
class Static_NPC:
|
|
5
|
-
def __init__(self, pos, animation, dim, camera, collision = True):
|
|
6
|
-
self.pos = pos
|
|
7
|
-
self.anim = animation
|
|
8
|
-
self.dim = dim
|
|
9
|
-
self.cam = camera
|
|
10
|
-
self.col = collision
|
|
11
|
-
self.screen = GLOBAL.screen
|
|
12
|
-
|
|
13
|
-
def display(self, dt):
|
|
14
|
-
image = self.anim.update(dt)
|
|
15
|
-
x, y = self.pos
|
|
16
|
-
if self.cam.type == "dynamic":
|
|
17
|
-
x-=self.cam.pos[0]
|
|
18
|
-
y-=self.cam.pos[1]
|
|
19
|
-
self.screen.blit(image, (x, y))
|
|
20
|
-
if self.col:
|
|
21
|
-
GLOBAL.collisions.append(pygame.Rect((x, y), self.dim))
|
GameBox/entities/basicTypes.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
from ..basics._core import GLOBAL
|
|
3
|
-
|
|
4
|
-
class Static_enemy:
|
|
5
|
-
def __init__(self, pos, animation, camera, dim, collision = True):
|
|
6
|
-
self.pos = pos
|
|
7
|
-
self.animation = animation
|
|
8
|
-
self.cam = camera
|
|
9
|
-
self.dim = dim
|
|
10
|
-
self.col = collision
|
|
11
|
-
self.screen = GLOBAL.screen
|
|
12
|
-
|
|
13
|
-
def display(self, dt):
|
|
14
|
-
if self.cam.type == "dynamic":
|
|
15
|
-
x, y = self.pos
|
|
16
|
-
x -= self.cam.pos[0]
|
|
17
|
-
y -= self.cam.pos[1]
|
|
18
|
-
self.screen.blit(self.animation.update(dt), (x, y))
|
|
19
|
-
if self.col:
|
|
20
|
-
GLOBAL.collisions.append(pygame.Rect((x, y), self.dim))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Dynamic_enemy:
|
|
24
|
-
def __init__(self, pos, travelPos, flip, animation, camera, dim, collision=True, speed=100):
|
|
25
|
-
self.pos = list(pos) # mutable copy for movement
|
|
26
|
-
self.start_pos = list(pos) # remember starting position
|
|
27
|
-
self.travel = list(travelPos) # target position
|
|
28
|
-
self.flip = flip
|
|
29
|
-
self.animation = animation
|
|
30
|
-
self.cam = camera
|
|
31
|
-
self.dim = dim
|
|
32
|
-
self.dir = 1 # 1 = toward travelPos, -1 = back to start
|
|
33
|
-
self.speed = speed # pixels per second
|
|
34
|
-
self.col = collision
|
|
35
|
-
self.screen = GLOBAL.screen
|
|
36
|
-
|
|
37
|
-
def move(self, dt):
|
|
38
|
-
target = self.travel if self.dir == 1 else self.start_pos
|
|
39
|
-
dx = target[0] - self.pos[0]
|
|
40
|
-
dy = target[1] - self.pos[1]
|
|
41
|
-
|
|
42
|
-
distance = (dx**2 + dy**2)**0.5
|
|
43
|
-
if distance == 0:
|
|
44
|
-
return # Already at target
|
|
45
|
-
|
|
46
|
-
move_dist = self.speed * dt
|
|
47
|
-
if move_dist >= distance:
|
|
48
|
-
next_pos = target.copy() # would snap to target
|
|
49
|
-
else:
|
|
50
|
-
next_pos = [
|
|
51
|
-
self.pos[0] + (dx / distance) * move_dist,
|
|
52
|
-
self.pos[1] + (dy / distance) * move_dist
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
# --- Collision check with player ---
|
|
56
|
-
enemy_next_rect = pygame.Rect(
|
|
57
|
-
next_pos[0]-self.cam.pos[0], next_pos[1]-self.cam.pos[1], self.dim[0], self.dim[1]
|
|
58
|
-
)
|
|
59
|
-
if enemy_next_rect.colliderect(GLOBAL.playerPosition):
|
|
60
|
-
return # Stop movement this frame if player is blocking
|
|
61
|
-
|
|
62
|
-
# If no collision, commit the move
|
|
63
|
-
self.pos = next_pos if move_dist < distance else target.copy()
|
|
64
|
-
if move_dist >= distance:
|
|
65
|
-
self.dir *= -1 # reverse direction
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def display(self, dt):
|
|
69
|
-
self.move(dt)
|
|
70
|
-
|
|
71
|
-
x, y = self.pos
|
|
72
|
-
if self.cam.type == "dynamic":
|
|
73
|
-
x -= self.cam.pos[0]
|
|
74
|
-
y -= self.cam.pos[1]
|
|
75
|
-
self.screen.blit(self.animation.update(dt), (x, y))
|
|
76
|
-
if self.col:
|
|
77
|
-
GLOBAL.collisions.append(pygame.Rect((x, y), self.dim))
|
|
78
|
-
|
|
79
|
-
|
GameBox/game.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
from .basics._core import GLOBAL
|
|
3
|
-
|
|
4
|
-
class Game:
|
|
5
|
-
def __init__(self, width, height, background_color = "black"):
|
|
6
|
-
pygame.font.init()
|
|
7
|
-
self.dim = width, height
|
|
8
|
-
self.color = background_color
|
|
9
|
-
self.objects = []
|
|
10
|
-
self.screen = pygame.display.set_mode((width, height))
|
|
11
|
-
self.clock = pygame.time.Clock()
|
|
12
|
-
|
|
13
|
-
GLOBAL.BaseInfo["screenDim"] = self.screen.get_size()
|
|
14
|
-
GLOBAL.screen = self.screen
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def show(self, obj):
|
|
18
|
-
self.objects.append(obj)
|
|
19
|
-
|
|
20
|
-
def update(self):
|
|
21
|
-
GLOBAL.collisions.clear()
|
|
22
|
-
self.screen.fill(self.color)
|
|
23
|
-
dt = self.clock.tick(60)/1000
|
|
24
|
-
for obj in self.objects:
|
|
25
|
-
obj.display(dt)
|
|
26
|
-
pygame.display.update()
|
|
27
|
-
|
|
28
|
-
def show_list(self, objs):
|
|
29
|
-
for item in objs:
|
|
30
|
-
self.objects.append(item)
|
GameBox/inputs/BasicInput.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class Input:
|
|
4
|
-
def mouse_leftClick(self):
|
|
5
|
-
return pygame.mouse.get_pressed(3)[0]
|
|
6
|
-
def mouse_rightClick(self):
|
|
7
|
-
return pygame.mouse.get_pressed(3)[2]
|
|
8
|
-
def is_pressed(self, key):
|
|
9
|
-
keys = pygame.key.get_pressed()
|
|
10
|
-
look = f"pygame.K_{key}"
|
|
11
|
-
return keys[look]
|
GameBox/sound/BasicSound.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class Sound:
|
|
4
|
-
def __init__(self):
|
|
5
|
-
# Initialize pygame mixer
|
|
6
|
-
pygame.mixer.init()
|
|
7
|
-
self.sounds = {}
|
|
8
|
-
self.music_playing = False
|
|
9
|
-
|
|
10
|
-
def load_sound(self, name: str, filepath: str):
|
|
11
|
-
"""
|
|
12
|
-
Load a sound effect into memory.
|
|
13
|
-
name -> reference key for later
|
|
14
|
-
filepath -> path to .wav/.ogg/.mp3
|
|
15
|
-
"""
|
|
16
|
-
self.sounds[name] = pygame.mixer.Sound(filepath)
|
|
17
|
-
|
|
18
|
-
def play_sound(self, name: str, loops=0):
|
|
19
|
-
"""
|
|
20
|
-
Play a loaded sound effect.
|
|
21
|
-
loops = 0 plays once, -1 loops forever
|
|
22
|
-
"""
|
|
23
|
-
if name in self.sounds:
|
|
24
|
-
self.sounds[name].play(loops=loops)
|
|
25
|
-
else:
|
|
26
|
-
print(f"[Sound] '{name}' not found!")
|
|
27
|
-
|
|
28
|
-
def stop_sound(self, name: str):
|
|
29
|
-
"""
|
|
30
|
-
Stop a specific sound effect if it is playing.
|
|
31
|
-
"""
|
|
32
|
-
if name in self.sounds:
|
|
33
|
-
self.sounds[name].stop()
|
|
34
|
-
|
|
35
|
-
def load_music(self, filepath: str):
|
|
36
|
-
"""
|
|
37
|
-
Load a background music track (only one at a time).
|
|
38
|
-
"""
|
|
39
|
-
pygame.mixer.music.load(filepath)
|
|
40
|
-
|
|
41
|
-
def play_music(self, loops=-1):
|
|
42
|
-
"""
|
|
43
|
-
Play loaded background music.
|
|
44
|
-
loops=-1 means infinite loop.
|
|
45
|
-
"""
|
|
46
|
-
pygame.mixer.music.play(loops)
|
|
47
|
-
self.music_playing = True
|
|
48
|
-
|
|
49
|
-
def stop_music(self):
|
|
50
|
-
"""
|
|
51
|
-
Stop background music.
|
|
52
|
-
"""
|
|
53
|
-
pygame.mixer.music.stop()
|
|
54
|
-
self.music_playing = False
|
|
55
|
-
|
|
56
|
-
def pause_music(self):
|
|
57
|
-
"""
|
|
58
|
-
Pause background music.
|
|
59
|
-
"""
|
|
60
|
-
pygame.mixer.music.pause()
|
|
61
|
-
|
|
62
|
-
def resume_music(self):
|
|
63
|
-
"""
|
|
64
|
-
Resume paused background music.
|
|
65
|
-
"""
|
|
66
|
-
pygame.mixer.music.unpause()
|