Skip to content

Commit 324f220

Browse files
fix(all): bugfixes
1 parent 247244f commit 324f220

5 files changed

Lines changed: 11 additions & 42 deletions

File tree

CollisionManager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ def handleBoxHit(self, one: pygame.Rect, two: pygame.Rect, hit: List[int]) -> No
6565
1,-1 0,-1 -1,-1
6666
"""
6767
if(one.facing != 'LSTOP' or one.facing != 'RSTOP'):
68-
# Right Edge
68+
# Right Edge - hit the left side of terrain while moving right
6969
if(hit[0] == -1):
7070
one.x = two.x + two.width
7171
one.x += 1
72-
# Left Edge
72+
# Left Edge - hit the right side of terrain while moving left
7373
elif(hit[0] == 1):
7474
one.x = two.x - one.width
7575
one.x -= 1
7676
# Bottom Edge
7777
if(hit[1] == -1):
7878
one.y = two.y + two.height
7979
one.y += 5
80-
# Top Edge
80+
# Top Edge - landed on terrain from above
8181
elif(hit[1] == 1):
8282
one.y = two.y - one.height
8383

EnemyManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def update_sword(self, player) -> None:
101101
if player.sword.colliderect(enemy) and player.sword.stab:
102102
_get_enemy_death_sound().play()
103103
self.enemies.pop(self.enemies.index(enemy))
104-
if enemy.sword.colliderect(player) and enemy.stab:
104+
if enemy.sword.colliderect(player) and enemy.stab and player.lives != 0:
105105
player.die()
106106

107107
def draw(self) -> None:

GameLoop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ async def draw(self) -> None:
7070
controller.get_input(pygame.key.get_pressed(), player, level, player.sword)
7171

7272
if player.lives > 0:
73-
player.move(level)
73+
# Update jump before collision detection to get correct position
7474
player.update_jump()
75+
player.move(level)
7576
pygame.draw.rect(self.surface, BLUE, player, 0)
7677
player.bullet_manager.update_bullets(self.surface)
7778
player.bullet_manager.check_hit(enemy_manager)

Player.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, surface: pygame.Surface) -> None:
4444
self.sword = Sword(self)
4545

4646
self.speed = 10
47-
self.ammo = 6
47+
self.ammo = 20
4848
self.status = 'GROUND'
4949
self.facing = 'RSTOP'
5050
self.current_weapon = 'GUN'
@@ -59,7 +59,7 @@ def move(self, levelloader) -> None:
5959
levelloader: The level loader instance for collision detection.
6060
"""
6161
self.hit = levelloader.check_collisions(self, False)
62-
62+
# Apply horizontal movement
6363
if self.facing == 'LEFT':
6464
if self.x > PLAYER_WID:
6565
self.x -= PLAYER_SPEED
@@ -75,8 +75,10 @@ def update_jump(self) -> None:
7575
"""Update player jumping physics and state."""
7676
if self.status == 'RISE' and self.y > PLAYER_JUMP_HT-self.jump_offset:
7777
self.y -= PLAYER_GRAVITY
78-
elif self.status == 'FALL' and self.y < SCREEN_HEIGHT-PLAYER_HT-GROUND_HEIGHT and self.status != 'GROUND':
78+
elif self.status == 'FALL' and self.y < SCREEN_HEIGHT-PLAYER_HT-GROUND_HEIGHT:
7979
self.y += PLAYER_GRAVITY
80+
elif self.y >= SCREEN_HEIGHT-PLAYER_HT-GROUND_HEIGHT:
81+
self.status = 'GROUND'
8082
else:
8183
self.status = 'GROUND'
8284

main.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ async def main() -> None:
3737
# Pre-load sounds after pygame.init() but before game starts
3838
preload_sounds()
3939

40-
# Display "Click to Start" message for browser compatibility
4140
try:
4241
font = pygame.font.Font(None, 48)
4342
small_font = pygame.font.Font(None, 24)
@@ -47,40 +46,7 @@ async def main() -> None:
4746
font = None
4847
small_font = None
4948

50-
print("Waiting for user interaction...")
51-
# Wait for user click (required for browser audio/input)
52-
waiting = True
53-
frame_count = 0
54-
while waiting:
55-
frame_count += 1
56-
if frame_count % 60 == 0: # Log every 60 frames (~1 second)
57-
print(f"Still waiting... frame {frame_count}")
58-
59-
win_surf.fill((0, 0, 0))
60-
61-
if font and small_font:
62-
title = font.render("Pygame Side Scroller", True, (74, 144, 226))
63-
prompt = small_font.render("Click anywhere to start", True, (255, 255, 255))
64-
win_surf.blit(title, (800//2 - title.get_width()//2, 250))
65-
win_surf.blit(prompt, (800//2 - prompt.get_width()//2, 320))
66-
else:
67-
# Fallback if fonts don't load - draw a white rectangle
68-
pygame.draw.rect(win_surf, (255, 255, 255), (300, 250, 200, 100))
69-
70-
pygame.display.flip()
71-
72-
for event in pygame.event.get():
73-
if event.type == pygame.QUIT:
74-
print("Quit event received")
75-
return
76-
if event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.KEYDOWN:
77-
print(f"User interaction detected: {event.type}")
78-
waiting = False
79-
80-
await asyncio.sleep(0) # Yield to browser
81-
8249
print("Starting game loop...")
83-
# Now start the actual game
8450
game_loop = GameLoop(win_surf)
8551
await game_loop.draw()
8652

0 commit comments

Comments
 (0)