From: LMH Date: Tue, 3 Sep 2013 03:01:16 +0000 (-1000) Subject: Worldmap now supports an additional level sprite action that indicates completion... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=31180666c7cf8ef2825f68d4afd41cfa0dc9aca6;p=supertux.git Worldmap now supports an additional level sprite action that indicates completion of all level stats. A potential future improvement to this mechanism would be adding an optional "target_time" to levels which needs to be reached before the level is marked as "perfect". Note that this change will cause a one-time reset of all level stats- sorry. --- diff --git a/WHATSNEW.txt b/WHATSNEW.txt index fb01b86b4..26dee86b7 100644 --- a/WHATSNEW.txt +++ b/WHATSNEW.txt @@ -5,6 +5,7 @@ Tracking major changes in-situ: glow effects new badguys: iceflame, ghostflame, livefire, goldbomb, smartblock new bonuses: coinrain, coinexplode +statistics improved Supertux Release 0.3.4 (2013-07) -------------------------------- diff --git a/data/images/worldmap/common/bonusdot.sprite b/data/images/worldmap/common/bonusdot.sprite index 9183d5b11..1bb24a468 100644 --- a/data/images/worldmap/common/bonusdot.sprite +++ b/data/images/worldmap/common/bonusdot.sprite @@ -11,4 +11,33 @@ (hitbox 16 16 0 0) (images "leveldot_green.png") ) + (action + (name "perfect") + (hitbox 16 16 0 0) + (images "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green_perfect-0.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-3.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-0.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png") + ) ) diff --git a/data/images/worldmap/common/hiddendot.sprite b/data/images/worldmap/common/hiddendot.sprite index ee8289025..8761039c6 100644 --- a/data/images/worldmap/common/hiddendot.sprite +++ b/data/images/worldmap/common/hiddendot.sprite @@ -9,4 +9,33 @@ (hitbox 16 16 0 0) (images "leveldot_green.png") ) + (action + (name "perfect") + (hitbox 16 16 0 0) + (images "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green_perfect-0.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-3.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-0.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png") + ) ) diff --git a/data/images/worldmap/common/leveldot.sprite b/data/images/worldmap/common/leveldot.sprite index afa203b57..6d103cc1b 100644 --- a/data/images/worldmap/common/leveldot.sprite +++ b/data/images/worldmap/common/leveldot.sprite @@ -9,4 +9,33 @@ (hitbox 16 16 0 0) (images "leveldot_green.png") ) + (action + (name "perfect") + (hitbox 16 16 0 0) + (images "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green_perfect-0.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-3.png" + "leveldot_green_perfect-2.png" + "leveldot_green_perfect-1.png" + "leveldot_green_perfect-0.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png" + "leveldot_green.png") + ) ) diff --git a/data/images/worldmap/common/leveldot_green_perfect-0.png b/data/images/worldmap/common/leveldot_green_perfect-0.png new file mode 100644 index 000000000..b4a7a30a0 Binary files /dev/null and b/data/images/worldmap/common/leveldot_green_perfect-0.png differ diff --git a/data/images/worldmap/common/leveldot_green_perfect-1.png b/data/images/worldmap/common/leveldot_green_perfect-1.png new file mode 100644 index 000000000..825374ac3 Binary files /dev/null and b/data/images/worldmap/common/leveldot_green_perfect-1.png differ diff --git a/data/images/worldmap/common/leveldot_green_perfect-2.png b/data/images/worldmap/common/leveldot_green_perfect-2.png new file mode 100644 index 000000000..313ec8775 Binary files /dev/null and b/data/images/worldmap/common/leveldot_green_perfect-2.png differ diff --git a/data/images/worldmap/common/leveldot_green_perfect-3.png b/data/images/worldmap/common/leveldot_green_perfect-3.png new file mode 100644 index 000000000..dd5eb8406 Binary files /dev/null and b/data/images/worldmap/common/leveldot_green_perfect-3.png differ diff --git a/data/images/worldmap/common/shroom.sprite b/data/images/worldmap/common/shroom.sprite index 5ed151bea..e432a29e0 100644 --- a/data/images/worldmap/common/shroom.sprite +++ b/data/images/worldmap/common/shroom.sprite @@ -20,6 +20,11 @@ (action (name "solved") (hitbox 16 16 0 0) + (images "level_star.png") + ) + (action + (name "perfect") + (hitbox 16 16 0 0) (images "level_star.png" "level_star1.png" "level_star1.png" diff --git a/src/supertux/statistics.cpp b/src/supertux/statistics.cpp index c749bd614..95ad4edb6 100644 --- a/src/supertux/statistics.cpp +++ b/src/supertux/statistics.cpp @@ -258,6 +258,14 @@ Statistics::operator+=(const Statistics& s2) if (s2.total_secrets != nv_secrets) total_secrets += s2.total_secrets; } +bool +Statistics::completed(const Statistics& stats) +{ + return (stats.coins == stats.total_coins && + stats.badguys == stats.total_badguys && + stats.secrets == stats.total_secrets); +} + void Statistics::declare_invalid() { diff --git a/src/supertux/statistics.hpp b/src/supertux/statistics.hpp index 5de05c836..880cd474c 100644 --- a/src/supertux/statistics.hpp +++ b/src/supertux/statistics.hpp @@ -48,11 +48,6 @@ public: Statistics(); /**< Creates new statistics, call reset() before counting */ ~Statistics(); - /// read statistics from lisp file - //void parse(const Reader& lisp); - /// write statistics to lisp file - //void write(Writer& writer); - /** * serialize statistics object as squirrel table "statistics" */ @@ -70,6 +65,7 @@ public: void reset(); /**< Set stats (but not totals) to zero */ void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */ void operator+=(const Statistics& o); /**< Add two Statistics objects */ + bool completed(const Statistics& stats); /* Check if stats match total stats */ void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */ diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index 1f3ec1a7e..569f31f48 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -33,6 +33,7 @@ LevelTile::LevelTile(const std::string& basedir, const Reader& lisp) : pos(), title(), solved(false), + perfect(false), auto_play(false), sprite(), statistics(), diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index 54b62e63a..8730d2956 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -43,6 +43,7 @@ public: Vector pos; std::string title; bool solved; + bool perfect; bool auto_play; /**< true if Tux should automatically enter this level if it's unfinished */ SpritePtr sprite; diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 41a28f083..1e6ba7b20 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -147,7 +147,7 @@ Tux::tryStartWalking() // We got a new direction, so lets start walking when possible Vector next_tile; - if ((!level || level->solved) + if ((!level || level->solved || level->perfect) && worldmap->path_ok(input_direction, tile_pos, &next_tile)) { tile_pos = next_tile; moving = true; diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index dc57331ba..3d608d532 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -461,6 +461,10 @@ WorldMap::finished_level(Level* gamelevel) // deal with statistics level->statistics.merge(gamelevel->stats); calculate_total_stats(); + if(level->statistics.completed(level->statistics)) { + level->perfect = true; + level->sprite->set_action("perfect"); + } save_state(); @@ -987,6 +991,7 @@ WorldMap::save_state() sq_newtable(vm); store_bool(vm, "solved", level->solved); + store_bool(vm, "perfect", level->perfect); level->statistics.serialize_to_squirrel(vm); sq_createslot(vm, -3); @@ -1058,7 +1063,11 @@ WorldMap::load_state() sq_pushstring(vm, level->get_name().c_str(), -1); if(SQ_SUCCEEDED(sq_get(vm, -2))) { level->solved = read_bool(vm, "solved"); - level->sprite->set_action(level->solved ? "solved" : "default"); + level->perfect = read_bool(vm, "perfect"); + if(!level->solved) + level->sprite->set_action("default"); + else + level->sprite->set_action((level->sprite->has_action("perfect") && level->perfect) ? "perfect" : "solved"); level->statistics.unserialize_from_squirrel(vm); sq_pop(vm, 1); }