X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fbadguy.cpp;h=888694e0fc54fa5a6bbd4948856a4a7703aeed59;hb=c4a1129cfccd204f4267f8ee838f95dd6ebad1cc;hp=5aefab4910502a7a28bc61bd21289b59b576d2ea;hpb=5a632cca810d50b4620fba49f57fc5236cec21af;p=supertux.git diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 5aefab491..888694e0f 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -31,7 +31,6 @@ static const float SQUISH_TIME = 2; static const float X_OFFSCREEN_DISTANCE = 1280; static const float Y_OFFSCREEN_DISTANCE = 800; -static const int LAYER_FALLING = 500; BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) : MovingSprite(pos, sprite_name_, layer_, COLGROUP_DISABLED), @@ -43,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(), @@ -53,8 +53,9 @@ BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) : { start_position = bbox.p1; - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -69,6 +70,7 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite start_dir(direction), frozen(false), ignited(false), + in_water(false), dead_script(), state(STATE_INIT), is_active_flag(), @@ -79,8 +81,9 @@ BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite { start_position = bbox.p1; - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -95,6 +98,7 @@ BadGuy::BadGuy(const Reader& reader, 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(), @@ -112,8 +116,9 @@ BadGuy::BadGuy(const Reader& reader, const std::string& sprite_name_, int layer_ reader.get("dead-script", dead_script); - sound_manager->preload("sounds/squish.wav"); - sound_manager->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/squish.wav"); + SoundManager::current()->preload("sounds/fall.wav"); + SoundManager::current()->preload("sounds/splash.wav"); dir = (start_dir == AUTO) ? LEFT : start_dir; } @@ -234,6 +239,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.wav", 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(); @@ -273,11 +288,20 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit) // hit from above? if (player->get_bbox().p2.y < (bbox.p1.y + 16)) { + if(player->is_stone()) { + kill_fall(); + return FORCE_MOVE; + } if(collision_squished(*player)) { return FORCE_MOVE; } } + if(player->is_stone()) { + collision_solid(hit); + return FORCE_MOVE; + } + return collision_player(*player, hit); } @@ -386,7 +410,7 @@ BadGuy::kill_squished(GameObject& object) { if (!is_active()) return; - sound_manager->play("sounds/squish.wav", get_pos()); + SoundManager::current()->play("sounds/squish.wav", get_pos()); physic.enable_gravity(true); physic.set_velocity_x(0); physic.set_velocity_y(0); @@ -406,12 +430,15 @@ BadGuy::kill_fall() { if (!is_active()) return; - sound_manager->play("sounds/fall.wav", get_pos()); + SoundManager::current()->play("sounds/fall.wav", get_pos()); physic.set_velocity_y(0); physic.set_acceleration_y(0); physic.enable_gravity(true); set_state(STATE_FALLING); - layer = LAYER_FALLING; + + // Set the badguy layer to be the foremost, so that + // this does not reveal secret tilemaps: + layer = Sector::current()->get_foremost_layer() + 1; // start dead-script run_dead_script(); @@ -433,14 +460,14 @@ BadGuy::run_dead_script() } void -BadGuy::set_state(State state) +BadGuy::set_state(State state_) { - if(this->state == state) + if(this->state == state_) return; State laststate = this->state; - this->state = state; - switch(state) { + this->state = state_; + switch(state_) { case STATE_SQUISHED: state_timer.start(SQUISH_TIME); break; @@ -600,6 +627,12 @@ BadGuy::is_frozen() const return frozen; } +bool +BadGuy::is_in_water() const +{ + return in_water; +} + void BadGuy::ignite() {