From: Ricardo Cruz Date: Thu, 9 Sep 2004 10:00:00 +0000 (+0000) Subject: Implemented mirroring in Sprite, so that now it's possible to adjust left offsets. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5023c5b34da1b979a9bd829824662960bd3a7ff9;p=supertux.git Implemented mirroring in Sprite, so that now it's possible to adjust left offsets. SVN-Revision: 1881 --- diff --git a/data/images/supertux.strf b/data/images/supertux.strf index d67a2d0d4..80eaf52fd 100644 --- a/data/images/supertux.strf +++ b/data/images/supertux.strf @@ -6,7 +6,7 @@ ;; Small Tux arms (name "small-tux-arms") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 14) @@ -20,43 +20,83 @@ "shared/smalltux/arms-walk-7.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 14) (images "shared/smalltux/arms-walk-5.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 14) (images "shared/smalltux/arms-jump-0.png")) (action - (name "skid") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "jump-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 15) (images "shared/smalltux/arms-skid-0.png")) (action - (name "kick") + (name "skid-left") + (fps 15.0) + (x-offset 6) + (y-offset 15) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 14) (images "shared/smalltux/arms-kick-0.png")) + (action + (name "kick-left") + (x-offset 5) + (y-offset 14) + (mirror-action "kick-right")) + ; Grabbing is arms specific! (action - (name "grab") + (name "grab-right") (x-offset 5) (y-offset 14) (images "shared/bigtux/arms-grab-0.png"))) + (action + (name "grab-left") + (x-offset 5) + (y-offset 14) + (mirror-action "grab-right")) + ;; Small Tux Body (sprite (name "small-tux-body") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 14) @@ -70,31 +110,64 @@ "shared/smalltux/body-walk-7.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 14) (images "shared/smalltux/body-walk-5.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 14) (images "shared/smalltux/body-jump-0.png")) (action - (name "skid") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "jump-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 15) (images "shared/smalltux/body-skid-0.png")) (action - (name "kick") + (name "skid-left") + (x-offset 6) + (y-offset 15) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 14) (images "shared/smalltux/body-kick-0.png"))) + (action + (name "kick-left") + (x-offset 5) + (y-offset 14) + (mirror-action "kick-right")) + ; End of Small Tux sprite ; Big Tux (no power) sprite @@ -103,7 +176,7 @@ (name "big-tux-arms") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 32) @@ -115,101 +188,201 @@ "shared/bigtux/arms-walk-5.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 14) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/arms-stand-0.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/arms-jump-0.png")) (action - (name "skid") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "jump-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 31) (images "shared/bigtux/arms-skid-0.png")) (action - (name "kick") + (name "skid-left") + (fps 15.0) + (x-offset 6) + (y-offset 31) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/arms-stand-0.png")) (action - (name "buttjump") + (name "kick-left") + (x-offset 5) + (y-offset 32) + (mirror-action "kick-right")) + + (action + (name "buttjump-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/arms-stand-0.png")) + (action + (name "buttjump-left") + (x-offset 5) + (y-offset 32) + (mirror-action "buttjump-right")) + ; Grabbing is arms specific! (action - (name "grab") + (name "grab-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/arms-grab-0.png")) (action - (name "duck+grab") + (name "grab-left") + (x-offset 5) + (y-offset 32) + (mirror-action "grab-right")) + + (action + (name "duck+grab-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/arms-duck+grab-0.png"))) + (action + (name "duck+grab-left") + (x-offset 5) + (y-offset 32) + (mirror-action "grab-right")) + ;; Big Tux Head (sprite (name "big-tux-head") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/head-stand-0.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/head-stand-0.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/head-stand-0.png")) (action - (name "duck") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "jump-right")) + + (action + (name "duck-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/head-duck-0.png")) (action - (name "skid") + (name "duck-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "duck-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 31) (images "shared/bigtux/head-skid-0.png")) (action - (name "kick") + (name "skid-left") + (fps 15.0) + (x-offset 6) + (y-offset 31) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/head-stand-0.png")) (action - (name "buttjump") + (name "kick-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "kick-right")) + + (action + (name "buttjump-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/head-stand-0.png")) (action - (name "idle") + (name "buttjump-left") + (x-offset 5) + (y-offset 32) + (mirror-action "buttjump-right")) + + (action + (name "idle-right") (fps 1.0) (x-offset 6) (y-offset 31) @@ -217,60 +390,116 @@ "shared/bigtux/head-idle-blink-1.png"))) + (action + (name "idle-left") + (fps 1.0) + (x-offset 6) + (y-offset 31) + (mirror-action "idle-right")) + ;; Big Tux Body (sprite (name "big-tux-body") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/body-stand-0.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/body-stand-0.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/body-stand-0.png")) (action - (name "duck") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "jump-right")) + + (action + (name "duck-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/body-duck-0.png")) (action - (name "skid") + (name "duck-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "duck-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 31) (images "shared/bigtux/body-skid-0.png")) (action - (name "kick") + (name "skid-left") + (fps 15.0) + (x-offset 6) + (y-offset 31) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/body-stand-0.png")) (action - (name "buttjump") + (name "kick-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "kick-right")) + + (action + (name "buttjump-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/body-stand-0.png"))) + (action + (name "buttjump-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "buttjump-right")) + ;; Big Tux Feet (sprite (name "big-tux-feet") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 32) @@ -282,44 +511,90 @@ "shared/bigtux/feet-walk-5.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/feet-stand-0.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/feet-jump-0.png")) (action - (name "duck") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "jump-right")) + + (action + (name "duck-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/feet-duck-0.png")) (action - (name "skid") + (name "duck-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "duck-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 31) (images "shared/bigtux/feet-skid-0.png")) (action - (name "kick") + (name "skid-left") + (x-offset 6) + (y-offset 31) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/feet-kick-0.png")) (action - (name "buttjump") + (name "kick-left") + (x-offset 5) + (y-offset 32) + (mirror-action "kick-right")) + + (action + (name "buttjump-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/feet-buttjump-0.png"))) + (action + (name "buttjump-left") + (x-offset 5) + (y-offset 32) + (mirror-action "buttjump-right")) + ; End of Big Tux (no power) sprite ; Big Fire Tux sprite @@ -327,59 +602,112 @@ (sprite (name "big-fire-tux-head") (action - (name "walk") + (name "walk-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "stand") + (name "walk-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "walk-right")) + + (action + (name "stand-right") (fps 15.0) (x-offset 5) (y-offset 32) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "jump") + (name "stand-left") + (fps 15.0) + (x-offset 5) + (y-offset 32) + (mirror-action "stand-right")) + + (action + (name "jump-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "duck") + (name "jump-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "jump-right")) + + (action + (name "duck-right") (fps 15.0) (x-offset 5) (y-offset 30) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "skid") + (name "duck-left") + (fps 15.0) + (x-offset 5) + (y-offset 30) + (mirror-action "duck-right")) + + (action + (name "skid-right") (x-offset 6) (y-offset 31) (images "shared/bigtux/head-skid-0.png")) (action - (name "kick") + (name "skid-left") + (x-offset 6) + (y-offset 31) + (mirror-action "skid-right")) + + (action + (name "kick-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "buttjump") + (name "kick-left") + (x-offset 5) + (y-offset 32) + (mirror-action "kick-right")) + + (action + (name "buttjump-right") (x-offset 5) (y-offset 32) (images "shared/bigtux/head-fire-stand-0.png")) (action - (name "idle") + (name "buttjump-left") + (x-offset 5) + (y-offset 32) + (mirror-action "buttjump-right")) + + (action + (name "idle-right") (fps 1.0) (x-offset 6) (y-offset 31) (images "shared/bigtux/head-idle-blink-0.png" "shared/bigtux/head-idle-blink-1.png"))) + (action + (name "idle-left") + (fps 1.0) + (x-offset 6) + (y-offset 31) + (mirror-action "idle-right")) + ; End of Big Fire Tux sprite diff --git a/lib/special/sprite.cpp b/lib/special/sprite.cpp index ac50b837e..100634b06 100644 --- a/lib/special/sprite.cpp +++ b/lib/special/sprite.cpp @@ -75,17 +75,7 @@ Sprite::parse_action(LispReader& lispreader) lispreader.read_int("z-order", action->z_order); lispreader.read_float("fps", action->fps); - std::vector images; - if(!lispreader.read_string_vector("images", images)) - Termination::abort("Sprite contains no images: ", action->name.c_str()); - - for(std::vector::size_type i = 0; i < images.size(); i++) - { - action->surfaces.push_back( - new Surface(datadir + "/images/" + images[i], true)); - } - - // TODO: add a top filter entry + /* TODO: add a top filter entry */ std::vector mask_color; lispreader.read_int_vector("apply-mask", mask_color); if(mask_color.size() == 4) @@ -97,6 +87,33 @@ Sprite::parse_action(LispReader& lispreader) } } + action->mirror = false; + std::string mirror_action; + lispreader.read_string("mirror-action", mirror_action); + if(!mirror_action.empty()) + { + action->mirror = true; + Action* act_tmp = get_action(mirror_action); + if(act_tmp == NULL) + std::cerr << "Warning: Could not mirror action. Action not found\n" + "Mirror actions must be defined after the real one!\n"; + else + action->surfaces = act_tmp->surfaces; + } + + // Load images + if(!action->mirror) + { + std::vector images; + if(!lispreader.read_string_vector("images", images)) + Termination::abort("Sprite contains no images: ", action->name.c_str()); + + for(std::vector::size_type i = 0; i < images.size(); i++) + { + action->surfaces.push_back( + new Surface(datadir + "/images/" + images[i], true)); + } + } actions[action->name] = action; } @@ -133,6 +150,18 @@ if(i == actions.end()) action = i->second; } +Sprite::Action* +Sprite::get_action(std::string act) +{ +Actions::iterator i = actions.find(act); +if(i == actions.end()) + { + std::cerr << "Warning: Action '" << act << "' not found on Sprite '" << name << "'\n"; + return NULL; + } +return i->second; +} + void Sprite::start_animation(int loops) { diff --git a/lib/special/sprite.h b/lib/special/sprite.h index 86b4a06af..15ee35b99 100644 --- a/lib/special/sprite.h +++ b/lib/special/sprite.h @@ -48,6 +48,10 @@ namespace SuperTux /** Frames per second */ float fps; + /** Mirror is used to avoid duplicating left and right side + sprites */ + bool mirror; + std::vector surfaces; }; @@ -112,6 +116,9 @@ namespace SuperTux void init_defaults(Action* act); void parse_action(LispReader& lispreader); + /** Get an action */ + Action* get_action(std::string act); + void update(); void reset(); diff --git a/src/player.cpp b/src/player.cpp index b7633fe2b..86bb7d2e0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -748,24 +748,55 @@ Player::draw(DrawingContext& context) /* Set Tux sprite action */ if (duck && size != SMALL) - tux_body->set_action("duck"); + { + if(dir == LEFT) + tux_body->set_action("duck-left"); + else // dir == RIGHT + tux_body->set_action("duck-right"); + } else if (skidding_timer.started()) - tux_body->set_action("skid"); + { + if(dir == LEFT) + tux_body->set_action("skid-left"); + else // dir == RIGHT + tux_body->set_action("skid-right"); + } else if (kick_timer.started()) - tux_body->set_action("kick"); + { + if(dir == LEFT) + tux_body->set_action("kick-left"); + else // dir == RIGHT + tux_body->set_action("kick-right"); + } else if (butt_jump) - tux_body->set_action("buttjump"); + { + if(dir == LEFT) + tux_body->set_action("buttjump-left"); + else // dir == RIGHT + tux_body->set_action("buttjump-right"); + } else if (physic.get_velocity_y() != 0) - tux_body->set_action("jump"); + { + if(dir == LEFT) + tux_body->set_action("jump-left"); + else // dir == RIGHT + tux_body->set_action("jump-right"); + } else { if (fabsf(physic.get_velocity_x()) < 1.0f) // standing { - tux_body->set_action("stand"); + if(dir == LEFT) + tux_body->set_action("stand-left"); + else // dir == RIGHT + tux_body->set_action("stand-right"); } else // moving { - tux_body->set_action("walk"); + if(dir == LEFT) + tux_body->set_action("walk-left"); + else // dir == RIGHT + tux_body->set_action("walk-right"); } } @@ -773,7 +804,11 @@ Player::draw(DrawingContext& context) { if(size == BIG) { - tux_body->head->set_action("idle"); + if(dir == LEFT) + tux_body->head->set_action("idle-left"); + else // dir == RIGHT + tux_body->set_action("idle-right"); + tux_body->head->start_animation(1); } @@ -785,9 +820,19 @@ Player::draw(DrawingContext& context) shooting_timer.check()) { if (duck) - tux_body->arms->set_action("duck+grab"); + { + if(dir == LEFT) + tux_body->arms->set_action("duck+grab"); + else // dir == RIGHT + tux_body->set_action("duck-right"); + } else - tux_body->arms->set_action("grab"); + { + if(dir == LEFT) + tux_body->arms->set_action("grab"); + else // dir == RIGHT + tux_body->set_action("duck-right"); + } } /* Draw Tux */