From 00b3f83fd19472aa1e12dccba9e592425d687001 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 20 May 2006 13:32:55 +0000 Subject: [PATCH] UnstableTile now has configurable sprite and allows for animations SVN-Revision: 3555 --- data/images/objects/unstable_tile/crumbling-0.png | Bin 0 -> 2714 bytes .../{unstable_tile.png => crumbling-1.png} | Bin data/images/objects/unstable_tile/normal.png | Bin 0 -> 2784 bytes .../objects/unstable_tile/unstable_tile.sprite | 29 ++++++- src/object/unstable_tile.cpp | 88 +++++++++++---------- src/object/unstable_tile.hpp | 20 +++-- 6 files changed, 87 insertions(+), 50 deletions(-) create mode 100644 data/images/objects/unstable_tile/crumbling-0.png rename data/images/objects/unstable_tile/{unstable_tile.png => crumbling-1.png} (100%) create mode 100644 data/images/objects/unstable_tile/normal.png diff --git a/data/images/objects/unstable_tile/crumbling-0.png b/data/images/objects/unstable_tile/crumbling-0.png new file mode 100644 index 0000000000000000000000000000000000000000..9cc8e68442c2cb22b37965e9c67b012ebe9122b0 GIT binary patch literal 2714 zcmV;L3T5?)P)r);plMp6q7-pJ#6)Z$0^HevDi>}Axv&BE zDN>|R;UYi^BS9JqNZ|yq6TnC!B@8GBu_Q_Z?!)0M@6Eh7Z~OPVrx@C>4FwTkq{{~! z;NIpt-#Pazmn>~?yM`Fb7_{&o+h*5e>Ph!R*U0BDFrdwI#G&QS(Oj7Wcp#6 z4Eq2qkK5$x%iA};y|%IS`%3CC%f>X0W7=qTiM7W0egw~NAkRv7xc_A9r2iy6zrHyi zhBZzAXsy6KzvUc(#{=!s7Dw%7yg?tb=uHpoGKoV>stX5Jm`s8j@s6@_bs$k`r!?WX{%5k2~G*X;r)-AgX6v1)Zr%p#@zFRhOye4 zO@?5ULTdx94Jh?stbvjO)>>3$j^Rn)jZS--dCqTlDx}F6gfMs>2cZnkSvad8s?3f~ z2L+*?w|V($(C#iGZnR*GM4C)ko+k}$bp!xB&$36mkM8dbk9)r-MCHq>qQ)9RK!`TV zrO8A~Av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bmKB63oRVV7 zf3yP2vM9^4xKoegt+~0CNU72u>_0BzW@p)2tJ7)f07|SjU>*neIHuzviaduk8d1G2 z;BYh<^-IpZny3nBrD3dvH4cI9+wPsdHQ7J7a4zP?+ z21*D3P)ADZ?4hX2#{>Z4^E1)e+UlFrGNs*>wBfC*R(Ec=tW2tGv^l zdov7cUv<_k0f_5yyG;nm2gm#08XWKav6Q0s-wqmocGT>%_-Wj;up9vB$hKO`GdC}8 zT)Vcow8lLz#Nha7CQYWldeT4m?BMC>TUEaEmyG%Uz!;qep)+ArUn7L1Ws!X-r8xfa z&(67b-+kBIxN$?j_10SsUjToW4+Bsqgi`A?Dv=^h$6(x>i{sX7^=AFM$#`_AwcZBs z03f6+GIlBm{j3@Qz}s)XjV!a?2Os?N>9BtR6acK}s;VmX`bWFf*6n}84?p@RJi7m} zJL&J`WtkltZPe%ObJjVloU;nBpR4k{_uj+YTwT8Y`d7YC{KpPdp-KC_{qIrWMpSRS zoF<7)rsET9^zCFi`5;e=DgK9$(?0uLQt!O;F70&M?(1Lw1NYnn^g${Iy!?R>#n*zM z_Ohrdk!8tF5Jf2?`~XlI{|6?Mf@fK20qE!V006CZHJVO7@yK+`S!=b{h7w0;5SX8? m=zq(?LQ5_!E#d!p9{&Ynr%^LX{PFz&0000 +// Copyright (C) 2006 Christoph Sommer // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -27,63 +28,70 @@ #include "resources.hpp" #include "sprite/sprite.hpp" #include "random_generator.hpp" - -static const float CRACKTIME = 0.3; -static const float FALLTIME = 0.8; +#include "object/bullet.hpp" UnstableTile::UnstableTile(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/unstable_tile/unstable_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false) + : MovingSprite(lisp, LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL) { + sprite->set_action("normal"); flags |= FLAG_SOLID; } HitResponse -UnstableTile::collision(GameObject& other, const CollisionHit& hitdata) +UnstableTile::collision(GameObject& other, const CollisionHit& hit) { - if(hitdata.normal.y < 0.8) - return FORCE_MOVE; + switch (state) { - Player* player = dynamic_cast (&other); - if(player) - hit = true; + case STATE_NORMAL: + if ((hit.normal.y >= 0.8 ) && (dynamic_cast(&other))) { + state = STATE_CRUMBLING; + sprite->set_action("crumbling", 1); + return FORCE_MOVE; + } + return FORCE_MOVE; + break; - return FORCE_MOVE; -} + case STATE_CRUMBLING: + return FORCE_MOVE; + break; -void -UnstableTile::draw(DrawingContext& context) -{ - Vector pos = get_pos(); - // shacking - if(timer.get_timegone() > CRACKTIME) { - pos.x += systemRandom.rand(-3, 3); - } + case STATE_DISINTEGRATING: + return FORCE_MOVE; + break; + + } - sprite->draw(context, pos, LAYER_TILES); + log_debug << "unhandled state" << std::endl; + return FORCE_MOVE; } void UnstableTile::update(float elapsed_time) { - if(falling) { - movement = physic.get_movement(elapsed_time); - if(!Sector::current()->inside(bbox)) { - remove_me(); - return; - } - } else if(hit) { - if(timer.check()) { - falling = true; - physic.enable_gravity(true); - flags &= ~FLAG_SOLID; - timer.stop(); - } else if(!timer.started()) { - timer.start(FALLTIME); - } - } else { - timer.stop(); + switch (state) { + + case STATE_NORMAL: + break; + + case STATE_CRUMBLING: + if (sprite->animation_done()) { + state = STATE_DISINTEGRATING; + sprite->set_action("disintegrating", 1); + flags &= ~FLAG_SOLID; + set_group(COLGROUP_DISABLED); + physic.enable_gravity(true); + } + break; + + case STATE_DISINTEGRATING: + movement = physic.get_movement(elapsed_time); + if (sprite->animation_done()) { + remove_me(); + return; + } + break; + } - hit = false; } IMPLEMENT_FACTORY(UnstableTile, "unstable_tile"); diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index 0e8cb3221..cd19c4e0d 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -1,7 +1,8 @@ // $Id$ // -// SuperTux +// SuperTux - Unstable Tile // Copyright (C) 2006 Matthias Braun +// Copyright (C) 2006 Christoph Sommer // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -25,9 +26,9 @@ #include "physic.hpp" #include "timer.hpp" -class Player; - -/** A tile that starts falling down if tux stands to long on it */ +/** + * A block that disintegrates when stood on + */ class UnstableTile : public MovingSprite { public: @@ -36,13 +37,16 @@ public: HitResponse collision(GameObject& other, const CollisionHit& hit); void update(float elapsed_time); - void draw(DrawingContext& context); private: + enum State { + STATE_NORMAL, /**< default state */ + STATE_CRUMBLING, /**< crumbling, still solid */ + STATE_DISINTEGRATING /**< disintegrating, no longer solid */ + }; + State state; + Physic physic; - Timer timer; - bool hit; - bool falling; }; #endif -- 2.11.0