From: Ricardo Cruz Date: Sat, 22 May 2004 15:27:45 +0000 (+0000) Subject: Tux shows arm when firing. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6046aabffb333d1a1a150e77d4982b622a068643;p=supertux.git Tux shows arm when firing. SVN-Revision: 1297 --- diff --git a/src/player.cpp b/src/player.cpp index 717878e28..5cebfba26 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -30,6 +30,8 @@ #include "screen.h" #define AUTOSCROLL_DEAD_INTERVAL 300 +// animation times (in ms): +#define SHOOTING_TIME 320 Surface* tux_life; @@ -110,6 +112,7 @@ Player::init() safe_timer.init(true); frame_timer.init(true); kick_timer.init(true); + shooting_timer.init(true); physic.reset(); } @@ -474,8 +477,9 @@ Player::handle_input() /* Shoot! */ if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER) { - World::current()->add_bullet(Vector(base.x, base.y + (base.height/2)), - physic.get_velocity_x(), dir); + if(World::current()->add_bullet(Vector(base.x, base.y + (base.height/2)), + physic.get_velocity_x(), dir)) + shooting_timer.start(SHOOTING_TIME); input.old_fire = DOWN; } @@ -590,7 +594,7 @@ Player::draw(ViewPort& viewport, int layer) if(layer == LAYER_OBJECTS + 1) { // Draw arm overlay graphics when Tux is holding something - if (holding_something && physic.get_velocity_y() == 0) + if ((holding_something && physic.get_velocity_y() == 0) || shooting_timer.check()) { if (dir == RIGHT) sprite->grab_right->draw(pos); diff --git a/src/player.h b/src/player.h index 362fbc621..7e39b4a6a 100644 --- a/src/player.h +++ b/src/player.h @@ -135,6 +135,7 @@ public: Timer safe_timer; Timer frame_timer; Timer kick_timer; + Timer shooting_timer; // used to show the arm when Tux is shooting Physic physic; public: diff --git a/src/world.cpp b/src/world.cpp index 97edbeb31..7863584ee 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -538,18 +538,18 @@ World::add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind) add_object(new Upgrade(displaymanager, pos, dir, kind)); } -void +bool World::add_bullet(const Vector& pos, float xm, Direction dir) { if(tux->got_power == Player::FIRE_POWER) { if(bullets.size() > MAX_FIRE_BULLETS-1) - return; + return false; } else if(tux->got_power == Player::ICE_POWER) { if(bullets.size() > MAX_ICE_BULLETS-1) - return; + return false; } Bullet* new_bullet = 0; @@ -562,6 +562,8 @@ World::add_bullet(const Vector& pos, float xm, Direction dir) add_object(new_bullet); play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER); + + return true; } void diff --git a/src/world.h b/src/world.h index 2ae7e0ba6..1f90d9f42 100644 --- a/src/world.h +++ b/src/world.h @@ -106,7 +106,7 @@ public: BadGuy* add_bad_guy(float x, float y, BadGuyKind kind); void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind); - void add_bullet(const Vector& pos, float xm, Direction dir); + bool add_bullet(const Vector& pos, float xm, Direction dir); /** Try to grab the coin at the given coordinates */ void trygrabdistro(float x, float y, int bounciness);