From 4f0d26aa598a1fd471f22767cedea4f179f8908b Mon Sep 17 00:00:00 2001 From: LMH Date: Sat, 13 Jul 2013 11:22:45 -1000 Subject: [PATCH] New BonusBlock content: 'explode' - a coin explosion. Causes ten coins to be hurled through the air as an alternative to coin rain in covered areas such as cave levels. These coins are included in the level stats. Testable in test/bonusblock.stl. --- data/images/objects/bonus_block/bonus-explode.png | Bin 0 -> 2596 bytes data/images/tiles.strf | 37 ++++++++++++--- data/levels/test/bonusblock.stl | 20 ++++---- src/object/bonus_block.cpp | 12 +++++ src/object/bonus_block.hpp | 3 +- src/object/coin.cpp | 4 ++ src/object/coin_explode.cpp | 55 ++++++++++++++++++++++ src/object/coin_explode.hpp | 39 +++++++++++++++ src/supertux/level.cpp | 3 ++ src/supertux/object_factory.cpp | 1 + 10 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 data/images/objects/bonus_block/bonus-explode.png create mode 100644 src/object/coin_explode.cpp create mode 100644 src/object/coin_explode.hpp diff --git a/data/images/objects/bonus_block/bonus-explode.png b/data/images/objects/bonus_block/bonus-explode.png new file mode 100644 index 0000000000000000000000000000000000000000..cdc07f9aa59a71773c72a3701f4a4f62507f8856 GIT binary patch literal 2596 zcmV+<3fuLGP)WFU8GbZ8()Nlj2>E@cM*011dmL_t(o!;P1DkX%(2 z#(!_`*Zq2(>7FH%S;9=#Nsuih#STHJ5EBuCLM$iy@3>Ae%yy9m4(~MkGQgT#aP}IZ==pPGm{sii}00JbC9jT%{EGp2I=~K-*I1 zn&;kPby#4roJY6I3KUhwkTqPo4lWf*lF)6Fci-JfN5>vIJ3BcsILIXzXSneO1G4}- zUK6OBwT|}o#WXg~W?1*po3=TYDA3tA#3#d1j(>iD(U-TtvE70^>B2 zG?~UU0;L18?3+8z%)y!szQ6azyl9G z!MO7SVuD5?>|$R*u=cuxxOIiTz6>sxLa}Jk)+Y1twh;#X zbBU@xz7P#Q%)+QC5>Mv{mn1UbxiEJ8ei_F>&S$Vk57Scf6t3ANL`lIc*fc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<_o-3{=`_79~$|cPQz#SXD%OAtbm~-QA;VZMso4mm?PXf?f z0|5~{QVzvYCQ31oF4+WwG8bPIVjPE}eM(bwsb}hSR&<1`eI{luHUr?Ut2V;QTc&`r zD?2qOD&QB(hWSK^q9RvHF@PeA7)JS{X`jXe6CegYdV`m?zltQu)4Q`mj_z-?&j36* z>ZP(wRV)#7E1(I}0gUHu4jfFE$+dRDDW+vBg6EwB!1K>PPoa=!$BrE{!S2dVv%XQV z@Tmemv0~U9zh2>h?edUG$#it&DK)z)%1#n8X{Df@Pt#+sbJNYMkXs%@o3rS@H?0#g z3|YdffeVq8EfNw-7-F$fiXDFyqSip#J_F0BhF5wk0w&$LD~q6&Q}g)QmzDYOy@$!( zz2$!@2dI-As+G!A%oeFC<|>Dg5NV+G((4h%MfRB?5Zu$~V zPD|LSdapr9a?nMQz9PhPMULlfltQ+A7C4?Drc0+Q27L(^2)hnN zR>|Q@x>C6gd_Wf3$FP9Zm;==91P z-%9}&ZJNmZki#{#0uj+++_o9XTlAO?WQ$;C%Oou1N{p2pR8goT#;$Ay#A)0*&DvAO zsw#0000add_object(new CoinRain(get_pos(), true)); sound_manager->play("sounds/upgrade.wav"); + break; + } + case CONTENT_EXPLODE: + { + hit_counter = 1; // multiple hits of coin explode is not allowed + Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40), 1)); + sound_manager->play("sounds/upgrade.wav"); + break; } } diff --git a/src/object/bonus_block.hpp b/src/object/bonus_block.hpp index 127965e6c..4e3be522e 100644 --- a/src/object/bonus_block.hpp +++ b/src/object/bonus_block.hpp @@ -42,7 +42,8 @@ public: CONTENT_TRAMPOLINE, CONTENT_PORTTRAMPOLINE, CONTENT_ROCK, - CONTENT_RAIN + CONTENT_RAIN, + CONTENT_EXPLODE }; protected: diff --git a/src/object/coin.cpp b/src/object/coin.cpp index a1eea594f..c87c9384f 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -194,10 +194,14 @@ HeavyCoin::collision_solid(const CollisionHit& hit) { if(hit.bottom) { physic.set_velocity_y(0); + physic.set_velocity_x(0); } if(hit.right || hit.left) { physic.set_velocity_x(-physic.get_velocity_x()); } + if(hit.top) { + physic.set_velocity_y(0); + } } /* EOF */ diff --git a/src/object/coin_explode.cpp b/src/object/coin_explode.cpp new file mode 100644 index 000000000..e1853cf73 --- /dev/null +++ b/src/object/coin_explode.cpp @@ -0,0 +1,55 @@ +// CoinExplode - several coins are hurled through the air +// Copyright (C) 2013 LMH +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "object/coin_explode.hpp" + +#include "math/random_generator.hpp" +#include "object/coin.hpp" +#include "supertux/sector.hpp" + +CoinExplode::CoinExplode(const Vector& pos, const int vert) : + position(pos), + y_velocity_weight(vert) // should generally be +/- 1 to send coins up or down respectively +{ +} + +void +CoinExplode::update(float ) +{ + int mag = 100; // madnitude that coins are to be thrown + int rand = 30; // max variation to be subtracted from magnitide + + //TODO: this needs its own snazzy sound + Sector::current()->add_object(new HeavyCoin(position, Vector (2.5,-4.5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (2,-5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (1.5,-5.5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (1,-6)*(mag+gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (0.5,-6.5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (-2.5,-4.5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (-2,-5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (-1.5,-5.5)*(mag-gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (-1,-6)*(mag+gameRandom.rand(rand)))); + Sector::current()->add_object(new HeavyCoin(position, Vector (-0.5,-6.5)*(mag-gameRandom.rand(rand)))); + + remove_me(); +} + +void +CoinExplode::draw(DrawingContext &) +{ +} + +/* EOF */ diff --git a/src/object/coin_explode.hpp b/src/object/coin_explode.hpp new file mode 100644 index 000000000..227215cb9 --- /dev/null +++ b/src/object/coin_explode.hpp @@ -0,0 +1,39 @@ +// CoinExplode - several coins are hurled through the air +// Copyright (C) 2013 LMH +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_OBJECT_COIN_EXPLODE_HPP +#define HEADER_SUPERTUX_OBJECT_COIN_EXPLODE_HPP + +#include + +#include "math/vector.hpp" +#include "supertux/game_object.hpp" + +class CoinExplode : public GameObject +{ +public: + CoinExplode(const Vector& pos, const int vert); + virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); + +private: + Vector position; + int y_velocity_weight; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/level.cpp b/src/supertux/level.cpp index e63b4a664..fbd16c3bb 100644 --- a/src/supertux/level.cpp +++ b/src/supertux/level.cpp @@ -206,6 +206,9 @@ Level::get_total_coins() } else if (block->contents == BonusBlock::CONTENT_RAIN) { total_coins += 10; continue; + } else if (block->contents == BonusBlock::CONTENT_EXPLODE) { + total_coins += 10; + continue; } #if 0 // FIXME: do we want this? q.v. src/object/oneup.cpp diff --git a/src/supertux/object_factory.cpp b/src/supertux/object_factory.cpp index 318389fa1..42fe3445a 100644 --- a/src/supertux/object_factory.cpp +++ b/src/supertux/object_factory.cpp @@ -86,6 +86,7 @@ #include "object/candle.hpp" #include "object/cloud_particle_system.hpp" #include "object/coin.hpp" +#include "object/coin_explode.hpp" #include "object/coin_rain.hpp" #include "object/comet_particle_system.hpp" #include "object/decal.hpp" -- 2.11.0