From: Tobias Markus Date: Sun, 1 Mar 2015 17:01:03 +0000 (+0100) Subject: Rudimentary approach at water splash effect for badguys X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=092556fd403b1464402c741f949c48f04f628ee8;p=supertux.git Rudimentary approach at water splash effect for badguys --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 609b3522c..ebea262a0 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -42,6 +42,7 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) : start_dir(AUTO), frozen(false), ignited(false), + in_water(false), dead_script(), state(STATE_INIT), is_active_flag(), @@ -54,6 +55,7 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) : SoundManager::current()->preload("sounds/squish.wav"); SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.ogg"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -80,6 +82,7 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite SoundManager::current()->preload("sounds/squish.wav"); SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.ogg"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -113,6 +116,7 @@ BadGuy::BadGuy(const Reader& reader, const std::string& sprite_name_, int layer_ SoundManager::current()->preload("sounds/squish.wav"); SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.ogg"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -233,6 +237,16 @@ BadGuy::collision_tile(uint32_t tile_attributes) // Don't kill badguys that have already been killed if (!is_active()) return; + if(tile_attributes & Tile::WATER && !is_in_water()) + { + in_water = true; + SoundManager::current()->play("sounds/splash.ogg", get_pos()); + } + if(!(tile_attributes & Tile::WATER) && is_in_water()) + { + in_water = false; + } + if(tile_attributes & Tile::HURTS) { if (tile_attributes & Tile::FIRE) { if (is_flammable()) ignite(); @@ -611,6 +625,12 @@ BadGuy::is_frozen() const return frozen; } +bool +BadGuy::is_in_water() const +{ + return in_water; +} + void BadGuy::ignite() { diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 8e9670b29..092ff54c8 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -96,6 +96,8 @@ public: bool is_frozen() const; + bool is_in_water() const; + protected: enum State { STATE_INIT, @@ -212,6 +214,7 @@ protected: bool frozen; bool ignited; /**< true if this badguy is currently on fire */ + bool in_water; /** < true if the badguy is currently in water */ std::string dead_script; /**< script to execute when badguy is killed */