B118: visual indication of Yeti's hitpoints. The scaled down image of the Yeti's...
authorOndřej Hošek <ondra.hosek@gmail.com>
Sun, 28 Jan 2007 17:58:50 +0000 (17:58 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Sun, 28 Jan 2007 17:58:50 +0000 (17:58 +0000)
SVN-Revision: 4710

data/images/creatures/yeti/hudlife.png [new file with mode: 0644]
src/badguy/yeti.cpp
src/badguy/yeti.hpp

diff --git a/data/images/creatures/yeti/hudlife.png b/data/images/creatures/yeti/hudlife.png
new file mode 100644 (file)
index 0000000..517da36
Binary files /dev/null and b/data/images/creatures/yeti/hudlife.png differ
index 76f0faa..5578d0d 100644 (file)
@@ -59,6 +59,7 @@ Yeti::Yeti(const lisp::Lisp& reader)
   countMe = false;
   sound_manager->preload("sounds/yeti_gna.wav");
   sound_manager->preload("sounds/yeti_roar.wav");
+  hud_head.reset(new Surface("images/creatures/yeti/hudlife.png"));
   draw_dead_script_hint = false;
 }
 
@@ -80,10 +81,32 @@ Yeti::draw(DrawingContext& context)
   if(safe_timer.started() && size_t(game_time*40)%2)
     return;
 
+  draw_hit_points(context);
+
   BadGuy::draw(context);
 }
 
 void
+Yeti::draw_hit_points(DrawingContext& context)
+{
+  int i;
+
+  Surface *hh = hud_head.get();
+  if (!hh)
+    return;
+
+  context.push_transform();
+  context.set_translation(Vector(0, 0));
+
+  for (i = 0; i < hit_points; ++i)
+  {
+    context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
+  }
+
+  context.pop_transform();
+}
+
+void
 Yeti::active_update(float elapsed_time)
 {
   switch(state) {
index f1b7504..cfc6d05 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef __YETI_H__
 #define __YETI_H__
 
+#include <memory>
+
 #include "badguy.hpp"
 
 class Yeti : public BadGuy
@@ -38,7 +40,7 @@ public:
   void kill_squished(GameObject& object);
   void kill_fall();
 
-  virtual Yeti* clone() const { return new Yeti(*this); }
+  virtual Yeti* clone() const { return new Yeti((Yeti&)*this); }
 
 private:
   void run();
@@ -48,6 +50,8 @@ private:
   void summon_snowball();
   void jump_down();
 
+  void draw_hit_points(DrawingContext& context);
+
   void take_hit(Player& player);
 
   enum YetiState {
@@ -62,6 +66,7 @@ private:
   Timer safe_timer;
   int stomp_count;
   int hit_points;
+  std::auto_ptr<Surface> hud_head;
 };
 
 #endif