changeset 56:2eeda60e4f04

randomized damage
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 28 Aug 2011 23:11:30 +0200
parents d278a39dc4d6
children 13e307963d5e
files src/effect.py src/hero.py src/monster.py
diffstat 3 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/effect.py	Sun Aug 28 22:57:39 2011 +0200
+++ b/src/effect.py	Sun Aug 28 23:11:30 2011 +0200
@@ -50,15 +50,17 @@
             self.kill()
 
 class Caption(object):
-    def __init__(self, x, y, text, color=(255, 255, 255), ttl=16):
+    def __init__(self, x, y, text, color=(255, 255, 255), ttl=16, delay=0):
         self.x = x
         self.y = y
         self.text = text
         self.color = color
         self.ttl = ttl
+        self.delay = delay
 
     def render(self, to_display, delay=0):
         self.sprite = CaptionSprite(self.x, self.y, self.text,
-                                    self.color, delay, self.ttl)
+                                    self.color, max(self.delay, delay),
+                                    self.ttl)
         to_display.effects.add(self.sprite)
 
--- a/src/hero.py	Sun Aug 28 22:57:39 2011 +0200
+++ b/src/hero.py	Sun Aug 28 23:11:30 2011 +0200
@@ -4,6 +4,7 @@
 import display
 import thing
 import effect
+import random
 
 
 class HeroSprite(display.Sprite):
@@ -134,15 +135,20 @@
             what = level.is_blocked(self.x + dx, self.y + dy)
         if not hasattr(what, 'hit'):
             return
-        what.hit()
+        what.hit(random.randint(0, 4))
         self.sprite.animation = self.sprite.anim_fight(dx, dy)
         if isinstance(what, thing.Chest):
             self.effects.append(
-                effect.Caption(self.x + dx, self.y + dy, 'empty', (64, 192, 0)))
+                effect.Caption(self.x + dx, self.y + dy, 'empty',
+                               (192, 192, 192), delay=8))
 
     def hit(self, damage):
         self.hp -= damage
         self.regen_tick = 0
+        if damage:
+            text = '%d' % (-damage)
+        else:
+            text = 'miss'
         self.effects.append(
-            effect.Caption(self.x, self.y, '%d' % (-damage), (255, 32, 32)))
+            effect.Caption(self.x, self.y, text, (255, 64, 64)))
 
--- a/src/monster.py	Sun Aug 28 22:57:39 2011 +0200
+++ b/src/monster.py	Sun Aug 28 23:11:30 2011 +0200
@@ -86,6 +86,7 @@
     max_hp = 4
     name = "monster"
     alpha = None
+    damage = 3
 
     def __init__(self, x, y):
         self.x, self.y = x, y
@@ -104,8 +105,12 @@
 
     def hit(self, damage=1):
         self.asleep = False
+        if damage:
+            text = '%d' % (-damage)
+        else:
+            text = 'miss'
         self.effects.append(
-            effect.Caption(self.x, self.y, '%d' % (-damage), (255, 128, 16)))
+            effect.Caption(self.x, self.y, text, (255, 128, 16)))
         self.hp -= damage
         if self.hp <= 0:
             self.die()
@@ -161,7 +166,7 @@
             return
         self.sprite.animation = self.sprite.anim_fight(dx, dy)
         self.sprite.animation.next()
-        level.hero.hit(1)
+        level.hero.hit(random.randint(0, self.damage))
 
 
 class Skeleton(Monster):
@@ -174,18 +179,21 @@
     tx = 1
     name = "zombie"
     max_hp = 7
+    damage = 1
 
 
 class Jack(Monster):
     tx = 2
     name = "jack"
     max_hp = 8
+    damage = 5
 
 
 class Bat(Monster):
     tx = 3
     name = "bat"
     max_hp = 2
+    damage = 1
 
     def act(self, level):
         # Attack if we feel like it
@@ -237,6 +245,7 @@
     tx = 7
     name = "plant"
     max_hp = 4
+    damage = 5
 
     def act(self, level):
         # Never move, only attack