Skip to content

Commit

Permalink
almost done?
Browse files Browse the repository at this point in the history
  • Loading branch information
Letat authored and wolfwood committed Nov 6, 2011
1 parent 61c8caf commit 0a6dd78
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def __init__(self, screen):

self.gameMusic = pygame.mixer.Sound("music/"+choice(musics))
self.attackSound = pygame.mixer.Sound("sounds/erdie__sword01.wav")

self.ghastlySound = pygame.mixer.Sound("sounds/johnc__moan.wav")
self.hurtSound = pygame.mixer.Sound("sounds/halleck__jacobsladdersingle2.mp3")

self.lc = LoopingCall(self.titleevent)
self.lc.start(0.1)
Expand Down Expand Up @@ -151,7 +152,7 @@ def gameevent(self):
self.pickup_item()

self.map.update(self.viewport)
if self.map.is_cleared():
if self.map.is_cleared() or self.player.stats.hp <= 0:
self.lc.stop()
self.lc = LoopingCall(self.gameoverevent)
self.lc.start(0.1)
Expand Down Expand Up @@ -183,6 +184,9 @@ def handleUpdate(self, update):
entity = Entity(update.stats, update.enttype,
True, update.name, update.idnum)
self.map.layers[2].add(entity)
# the monster's not dead, so it's attacking. arrrgh
if update.stats.hp > 0 and self.player:
self.monster_attack(entity)

elif is_player(update.enttype):
entity = self.map.layers[2].getById(update.idnum)
Expand Down Expand Up @@ -218,6 +222,20 @@ def score_kill(self, entity):
else:
self.player.stats.score += scores.GHOST

def monster_attack(self, entity):
entity_x = entity.stats.x
entity_y = entity.stats.y
player_x = self.player.stats.x
player_y = self.player.stats.y

dist = abs(entity_x - player_x) + abs(entity_y - player_y)
if dist < 2:
self.hurtSound.play()
self.player.stats.hp -= 10
self.f.transport.write(pickle.dumps(self.player.getUpdate(),2))
elif dist < 3:
self.ghastlySound.play()

def pickup_item(self):
item = self.map.item_under_entity(self.player)
if item:
Expand Down

0 comments on commit 0a6dd78

Please sign in to comment.