New bonus_block content: light
authorLMH <lmh.0013@gmail.com>
Wed, 28 Nov 2012 22:29:21 +0000 (12:29 -1000)
committerLMH <lmh.0013@gmail.com>
Wed, 28 Nov 2012 22:29:21 +0000 (12:29 -1000)
data/images/objects/bonus_block/bonusblock.sprite
data/images/objects/bonus_block/light.xcf [new file with mode: 0644]
data/images/objects/bonus_block/off.png [new file with mode: 0644]
data/images/objects/bonus_block/on.png [new file with mode: 0644]
data/images/objects/lightmap_light/bonusblock_light.png [new file with mode: 0644]
data/images/tiles.strf
data/levels/test/bonusblock.stl
src/object/bonus_block.cpp
src/object/bonus_block.hpp

index 3f5924c..9ce96d1 100644 (file)
       (action
          (name "empty")
          (images "empty.png"))
+      (action
+         (name "on")
+         (images "on.png"))
+      (action
+         (name "off")
+         (images "off.png"))
 )
diff --git a/data/images/objects/bonus_block/light.xcf b/data/images/objects/bonus_block/light.xcf
new file mode 100644 (file)
index 0000000..91e5440
Binary files /dev/null and b/data/images/objects/bonus_block/light.xcf differ
diff --git a/data/images/objects/bonus_block/off.png b/data/images/objects/bonus_block/off.png
new file mode 100644 (file)
index 0000000..37db176
Binary files /dev/null and b/data/images/objects/bonus_block/off.png differ
diff --git a/data/images/objects/bonus_block/on.png b/data/images/objects/bonus_block/on.png
new file mode 100644 (file)
index 0000000..f66ae77
Binary files /dev/null and b/data/images/objects/bonus_block/on.png differ
diff --git a/data/images/objects/lightmap_light/bonusblock_light.png b/data/images/objects/lightmap_light/bonusblock_light.png
new file mode 100644 (file)
index 0000000..e498abd
Binary files /dev/null and b/data/images/objects/lightmap_light/bonusblock_light.png differ
index c35cf70..afc788f 100644 (file)
 ;;  - the meaning of the values in (attributes ...) can be seen in
 ;;    src/tile.cpp, unisolid is 3 not 2
 (supertux-tiles
+  (tile
+    (id 2943)
+    (images
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-1.png"
+      "objects/bonus_block/full-2.png"
+      "objects/bonus_block/full-3.png"
+      "objects/bonus_block/full-4.png"
+      "objects/bonus_block/full-3.png"
+      "objects/bonus_block/full-2.png"
+      "objects/bonus_block/full-1.png"
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-0.png"
+    )
+    (solid #t)
+    (fullbox #t)
+    (next-tile 84)
+    (editor-images "objects/bonus_block/off.png")
+    (data 6)
+    (fps 15)
+  )
+  
   (tilegroup
     (name "Pipe: Green")
     (tiles
   )
   (tilegroup
     (name "Block")
-    (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 84 102 140 103 104 105 112 128 1311 2153)
+    (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 84 102 140 103 104 105 112 128 1311 2153 2943)
   )
   (tilegroup
     (name "Background")
     (image "tiles/snow/slope-upper.png" )
   )
 
-;; next-id: 2943
+;; next-id: 2944
 )
index 44cf5f0..4f953a0 100755 (executable)
@@ -35,7 +35,7 @@
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       544
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       576
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       608
-0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       640
+0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       2943    0       0       0       0       0       0       0       0       0       0       0       0       0       ;       640
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       672
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       132     0       ;       704
 8      8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       8       48      8       ;       736
index 3a2596f..37ad895 100644 (file)
@@ -40,7 +40,8 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
   Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")), 
   contents(),
   object(0),
-  hit_counter(1)
+  hit_counter(1),
+  lightsprite(Surface::create("/images/objects/lightmap_light/bonusblock_light.png"))
 {
   bbox.set_pos(pos);
   sprite->set_action("normal");
@@ -50,6 +51,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
     case 3: contents = CONTENT_STAR; break;
     case 4: contents = CONTENT_1UP; break;
     case 5: contents = CONTENT_ICEGROW; break;
+    case 6: contents = CONTENT_LIGHT; sound_manager->preload("sounds/switch.ogg"); break;
     default:
       log_warning << "Invalid box contents" << std::endl;
       contents = CONTENT_COIN;
@@ -61,7 +63,8 @@ BonusBlock::BonusBlock(const Reader& lisp) :
   Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")),
   contents(),
   object(0),
-  hit_counter(1)
+  hit_counter(1),
+  lightsprite(Surface::create("/images/objects/lightmap_light/bonusblock_light.png"))
 {
   Vector pos;
 
@@ -97,6 +100,9 @@ BonusBlock::BonusBlock(const Reader& lisp) :
         contents = CONTENT_CUSTOM;
       } else if(contentstring == "script") {
         contents = CONTENT_SCRIPT;
+      } else if(contentstring == "light") {
+        contents = CONTENT_LIGHT;
+        sound_manager->preload("sounds/switch.ogg");
       } else {
         log_warning << "Invalid box contents '" << contentstring << "'" << std::endl;
       }
@@ -244,10 +250,18 @@ BonusBlock::try_open(Player *player)
       }
       break;
     }
+    case CONTENT_LIGHT:
+    {
+      if(sprite->get_action() == "on")
+        sprite->set_action("off");
+      else
+        sprite->set_action("on");
+      sound_manager->play("sounds/switch.ogg");
+    }
   }
 
   start_bounce(player);
-  if(hit_counter <= 0){ //use 0 to allow infinite hits
+  if(hit_counter <= 0 || contents == CONTENT_LIGHT){ //use 0 to allow infinite hits
   }else if(hit_counter == 1){
     sprite->set_action("empty");
   }else{
@@ -273,4 +287,17 @@ Block::break_me()
   remove_me();
 }
 
+void
+BonusBlock::draw(DrawingContext& context){
+  // draw regular sprite
+  sprite->draw(context, get_pos(), 10);
+  //Draw light if on.
+  if(sprite->get_action() == "on") {
+    Vector pos = get_pos() + (bbox.get_size() - lightsprite->get_size()) / 2;
+    context.push_target();
+    context.set_target(DrawingContext::LIGHTMAP);
+    context.draw_surface(lightsprite, pos, 10);
+    context.pop_target();
+  }
+}
 /* EOF */
index d8798b3..f993785 100644 (file)
@@ -18,6 +18,7 @@
 #define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP
 
 #include "object/block.hpp"
+#include "object/moving_sprite.hpp"
 
 class BonusBlock : public Block
 {
@@ -36,7 +37,8 @@ public:
     CONTENT_STAR,
     CONTENT_1UP,
     CONTENT_CUSTOM,
-    CONTENT_SCRIPT
+    CONTENT_SCRIPT,
+    CONTENT_LIGHT
   };
 
 protected:
@@ -46,12 +48,14 @@ public:
   Contents contents;
   MovingObject* object;
   int hit_counter;
+  void draw(DrawingContext& context);
 
 private:
   BonusBlock(const BonusBlock&);
   BonusBlock& operator=(const BonusBlock&);
   std::string sprite_name;
   std::string script;
+  SurfacePtr lightsprite;
 };
 
 #endif