From 467f8befe9cfdea7f689777abcc80f5cb4d6cc1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Ho=C5=A1ek?= Date: Wed, 12 Apr 2006 18:59:59 +0000 Subject: [PATCH] Hacked together a "coin losing" effect when Tux is killed. SVN-Revision: 3320 --- src/object/player.cpp | 34 ++++++++++++++++++++++++++++++++++ src/object/player.hpp | 15 +++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/object/player.cpp b/src/object/player.cpp index 01167e102..f453f50ae 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -100,6 +100,33 @@ TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer) feet->draw(context, pos, layer-2); } +FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) +{ + pos = start_position; + sprite = sprite_manager->create("images/objects/coin/coin.sprite"); + physic.set_velocity_y(800); + physic.set_velocity_x(vel_x); +} + +FallingCoin::~FallingCoin() +{ + delete sprite; +} + +void +FallingCoin::draw(DrawingContext& context) +{ + sprite->draw(context, pos, LAYER_OBJECTS + 5); +} + +void +FallingCoin::update(float elapsed_time) +{ + pos += physic.get_movement(elapsed_time); + if (pos.y > SCREEN_HEIGHT) + remove_me(); +} + Player::Player(PlayerStatus* _player_status) : player_status(_player_status), grabbed_object(0) { @@ -856,6 +883,13 @@ Player::kill(HurtMode mode) } else { + srand(time(0)); + int i; + for (i = 0; (i < 5) && (i < player_status->coins); i++) + { + // the numbers: starting x, starting y, velocity y + Sector::current()->add_object(new FallingCoin(get_pos() + Vector(rand()%5, rand()%50 - 32), rand()%200 - 100)); + } physic.enable_gravity(true); physic.set_acceleration(0, 0); physic.set_velocity(0, 700); diff --git a/src/object/player.hpp b/src/object/player.hpp index eb5ab8acc..d7326cd0d 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -34,6 +34,7 @@ #include "display_effect.hpp" #include "script_interface.hpp" #include "console.hpp" +#include "coin.hpp" class BadGuy; class Portable; @@ -79,6 +80,20 @@ extern TuxBodyParts* big_tux; extern TuxBodyParts* fire_tux; extern TuxBodyParts* ice_tux; +class FallingCoin : public GameObject +{ +public: + FallingCoin(const Vector& start_position, const int x_vel); + ~FallingCoin(); + + void draw(DrawingContext& context); + void update(float elapsed_time); +private: + Vector pos; + Sprite* sprite; + Physic physic; +}; + class Player : public MovingObject, public Scripting::Player, public ScriptInterface { public: -- 2.11.0