From: LMH Date: Thu, 27 Nov 2014 02:02:11 +0000 (-1000) Subject: Removed 'add_bullet' from Sector, moved bullet checks into Player X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e117cc5199ebd6c494864a8cbcec7ac583267440;p=supertux.git Removed 'add_bullet' from Sector, moved bullet checks into Player --- diff --git a/src/object/player.cpp b/src/object/player.cpp index 1f4f65aa3..376cdcf91 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -830,12 +830,18 @@ Player::handle_input() /* Shoot! */ if (controller->pressed(Controller::ACTION) && (player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS)) { - if(Sector::current()->add_bullet( - get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) - : Vector(32, bbox.get_height()/2)), - player_status, - physic.get_velocity_x(), dir)) + if((player_status->bonus == FIRE_BONUS && + Sector::current()->get_active_bullets() < player_status->max_fire_bullets) || + (player_status->bonus == ICE_BONUS && + Sector::current()->get_active_bullets() < player_status->max_ice_bullets)) + { + Vector pos = get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) : Vector(32, bbox.get_height()/2)); + auto new_bullet = std::make_shared(pos, physic.get_velocity_x(), dir, player_status->bonus); + Sector::current()->add_object(new_bullet); + + SoundManager::current()->play("sounds/shoot.wav"); shooting_timer.start(SHOOTING_TIME); + } } /* Duck or Standup! */ diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 73d3cce97..409ec87c1 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -1468,23 +1468,6 @@ Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_o } bool -Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir) -{ - // TODO remove this function and move these checks elsewhere... - if((player_status->bonus == FIRE_BONUS && - (int)bullets.size() >= player_status->max_fire_bullets) || - (player_status->bonus == ICE_BONUS && - (int)bullets.size() >= player_status->max_ice_bullets)) - return false; - auto new_bullet = std::make_shared(pos, xm, dir, player_status->bonus); - add_object(new_bullet); - - SoundManager::current()->play("sounds/shoot.wav"); - - return true; -} - -bool Sector::add_smoke_cloud(const Vector& pos) { add_object(std::make_shared(pos)); diff --git a/src/supertux/sector.hpp b/src/supertux/sector.hpp index b28d82692..885a817e6 100644 --- a/src/supertux/sector.hpp +++ b/src/supertux/sector.hpp @@ -110,7 +110,8 @@ public: void play_music(MusicType musictype); MusicType get_music_type(); - bool add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir); + int get_active_bullets() + { return (int)bullets.size(); } bool add_smoke_cloud(const Vector& pos); /** get currently activated sector. */