Skip to content

Commit 9a42b1d

Browse files
committed
Fix error with collision after goblin is invisible
1 parent 573b7f0 commit 9a42b1d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pygame1_smallguy/small_guy_game.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def draw(self, win):
8686

8787
def hit(self):
8888
# this is resetting the char after a hit and shows it as standing
89+
self.isJump = False
90+
self.jumpCount = 10
8991
self.x = 60
9092
self.y = 410
9193
self.walkCount = 0
@@ -228,14 +230,8 @@ def redrawGameWindow():
228230
playSeconds = 20
229231

230232
while running:
231-
232233
clock.tick(27)
233234

234-
if shootLoop > 0:
235-
shootLoop += 1
236-
if shootLoop > 3:
237-
shootLoop = 0
238-
239235
for event in pygame.event.get():
240236
if event.type == pygame.QUIT:
241237
running = False
@@ -245,12 +241,20 @@ def redrawGameWindow():
245241
if playSeconds == 0:
246242
print("Time's up!")
247243
running = False
248-
# the char collides with the goblin, calculated via the hitboxes, 5 hitnumber is deducted for every collision
249-
if small_guy.hitbox[1] < goblin.hitbox[1] + goblin.hitbox[3] and small_guy.hitbox[1] + small_guy.hitbox[3] > goblin.hitbox[1]:
250-
if small_guy.hitbox[0] + small_guy.hitbox[2] > goblin.hitbox[0] and small_guy.hitbox[0] < goblin.hitbox[0] + goblin.hitbox[2]:
251-
small_guy.hit()
252-
hitNumber -= 5
253244

245+
# the goblin collides with little guy ONLY when it is visible (= not destroyed yet)
246+
if goblin.visible == True:
247+
# the char collides with the goblin, calculated via the hitboxes, 5 hitnumber is deducted for every collision
248+
if small_guy.hitbox[1] < goblin.hitbox[1] + goblin.hitbox[3] and small_guy.hitbox[1] + small_guy.hitbox[3] > goblin.hitbox[1]:
249+
if small_guy.hitbox[0] + small_guy.hitbox[2] > goblin.hitbox[0] and small_guy.hitbox[0] < goblin.hitbox[0] + goblin.hitbox[2]:
250+
small_guy.hit()
251+
hitNumber -= 5
252+
253+
if shootLoop > 0:
254+
shootLoop += 1
255+
if shootLoop > 3:
256+
shootLoop = 0
257+
254258
for bullet in bullets:
255259
# check if bullet is in hitbox: check top and bottom of hitbox rectangle
256260
if bullet.y - bullet.radius < goblin.hitbox[1] + goblin.hitbox[3] and bullet.y + bullet.radius > goblin.hitbox[1]:

0 commit comments

Comments
 (0)