X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fyeti.cpp;h=8d1b49b58b25b75e2bf2d98bbbe0f6dea3f01757;hb=2e163cb10e0a6af504275585e7c31091931dd7b2;hp=79959257df8e74dc7d10c7c2aa00e246c81050da;hpb=fea3446f05e1e7673607b835c269d3e8d1929ab3;p=supertux.git diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 79959257d..8d1b49b58 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -1,13 +1,11 @@ -// $Id$ -// // SuperTux - Boss "Yeti" // Copyright (C) 2005 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 -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// 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 @@ -15,51 +13,58 @@ // 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, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. -#include +// along with this program. If not, see . -#include -#include -#include -#include "yeti.hpp" +#include "badguy/yeti.hpp" + +#include "audio/sound_manager.hpp" +#include "badguy/bouncing_snowball.hpp" +#include "badguy/yeti_stalactite.hpp" #include "object/camera.hpp" -#include "yeti_stalactite.hpp" -#include "bouncing_snowball.hpp" -#include "game_session.hpp" -#include "level.hpp" +#include "object/player.hpp" +#include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" + +#include +#include namespace { - const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */ - const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */ +const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */ +const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */ - const float RUN_VX = 350; /**< horizontal speed while running */ +const float RUN_VX = 350; /**< horizontal speed while running */ - const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */ - const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */ +const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */ +const float JUMP_UP_VY = -700; /**< vertical speed while jumping on the dais */ - const float STOMP_VY = -250; /** vertical speed while stomping on the dais */ +const float STOMP_VY = -300; /** vertical speed while stomping on the dais */ - const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */ - const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */ - const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */ - const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */ - const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */ - const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */ - const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */ +const float LEFT_STAND_X = 80; /**< x-coordinate of left dais' end position */ +const float RIGHT_STAND_X = 1280-LEFT_STAND_X-60; /**< x-coordinate of right dais' end position */ +const float LEFT_JUMP_X = LEFT_STAND_X+448; /**< x-coordinate of from where to jump on the left dais */ +const float RIGHT_JUMP_X = RIGHT_STAND_X-448; /**< x-coordinate of from where to jump on the right dais */ +const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */ +const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */ +const int INITIAL_HITPOINTS = 5; /**< number of hits we can take */ - const float SQUISH_TIME = 5; +const float YETI_SQUISH_TIME = 5; } -Yeti::Yeti(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/yeti/yeti.sprite") +Yeti::Yeti(const Reader& reader) : + BadGuy(reader, "images/creatures/yeti/yeti.sprite"), + state(), + state_timer(), + safe_timer(), + stomp_count(), + hit_points(), + hud_head() { hit_points = INITIAL_HITPOINTS; countMe = false; - sound_manager->preload("sounds/yeti_gna.wav"); - sound_manager->preload("sounds/yeti_roar.wav"); - hud_head.reset(new Surface("images/creatures/yeti/hudlife.png")); + SoundManager::current()->preload("sounds/yeti_gna.wav"); + SoundManager::current()->preload("sounds/yeti_roar.wav"); + hud_head = Surface::create("images/creatures/yeti/hudlife.png"); } Yeti::~Yeti() @@ -67,7 +72,7 @@ Yeti::~Yeti() } void -Yeti::activate() +Yeti::initialize() { dir = RIGHT; jump_down(); @@ -88,21 +93,18 @@ Yeti::draw(DrawingContext& context) void Yeti::draw_hit_points(DrawingContext& context) { - int i; - - Surface *hh = hud_head.get(); - if (!hh) - return; + if (hud_head) + { + context.push_transform(); + context.set_translation(Vector(0, 0)); - context.push_transform(); - context.set_translation(Vector(0, 0)); + for (int i = 0; i < hit_points; ++i) + { + context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1); + } - for (i = 0; i < hit_points; ++i) - { - context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1); + context.pop_transform(); } - - context.pop_transform(); } void @@ -122,7 +124,7 @@ Yeti::active_update(float elapsed_time) break; case BE_ANGRY: if(state_timer.check()) { - sound_manager->play("sounds/yeti_gna.wav"); + SoundManager::current()->play("sounds/yeti_gna.wav"); physic.set_velocity_y(STOMP_VY); sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left"); } @@ -168,23 +170,16 @@ void Yeti::be_angry() { //turn around - dir = (dir==RIGHT)?LEFT:RIGHT; + dir = (dir==RIGHT) ? LEFT : RIGHT; - sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); + sprite->set_action((dir==RIGHT) ? "stand-right" : "stand-left"); physic.set_velocity_x(0); physic.set_velocity_y(0); - if (hit_points < INITIAL_HITPOINTS) summon_snowball(); stomp_count = 0; state = BE_ANGRY; state_timer.start(STOMP_WAIT); } -void -Yeti::summon_snowball() -{ - Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir)); -} - bool Yeti::collision_squished(GameObject& object) { @@ -208,7 +203,7 @@ void Yeti::take_hit(Player& ) if(safe_timer.started()) return; - sound_manager->play("sounds/yeti_roar.wav"); + SoundManager::current()->play("sounds/yeti_roar.wav"); hit_points--; if(hit_points <= 0) { @@ -217,17 +212,15 @@ void Yeti::take_hit(Player& ) physic.set_velocity_x(0); physic.set_velocity_y(0); + // Set the badguy layer to be above the foremost, so that + // this does not reveal secret tilemaps: + layer = Sector::current()->get_foremost_layer() + 1; state = SQUISHED; - state_timer.start(SQUISH_TIME); - set_group(COLGROUP_MOVING_ONLY_STATIC); + state_timer.start(YETI_SQUISH_TIME); + set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); sprite->set_action("dead"); - if (countMe) Sector::current()->get_level()->stats.badguys++; - - if(dead_script != "") { - std::istringstream stream(dead_script); - Sector::current()->run_script(stream, "Yeti - dead-script"); - } + run_dead_script(); } else { safe_timer.start(SAFE_TIME); @@ -238,18 +231,6 @@ void Yeti::kill_fall() { // shooting bullets or being invincible won't work :) - take_hit(*get_nearest_player()); // FIXME: debug only(?) -} - -void -Yeti::write(lisp::Writer& writer) -{ - writer.start_list("yeti"); - - writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); - - writer.end_list("yeti"); } void @@ -258,28 +239,29 @@ Yeti::drop_stalactite() // make a stalactite falling down and shake camera a bit Sector::current()->camera->shake(.1f, 0, 10); - YetiStalactite* nearest = 0; - float dist = FLT_MAX; - Player* player = this->get_nearest_player(); if (!player) return; Sector* sector = Sector::current(); for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) { - YetiStalactite* stalactite = dynamic_cast (*i); + YetiStalactite* stalactite = dynamic_cast(i->get()); if(stalactite && stalactite->is_hanging()) { - float sdist - = fabsf(stalactite->get_pos().x - player->get_pos().x); - if(sdist < dist) { - nearest = stalactite; - dist = sdist; + if (hit_points >= 3) { + // drop stalactites within 3 of player, going out with each jump + float distancex = fabsf(stalactite->get_bbox().get_middle().x - player->get_bbox().get_middle().x); + if(distancex < stomp_count*32) { + stalactite->start_shaking(); + } } - } + else { /* if (hitpoints < 3) */ + // drop every 3rd pair of stalactites + if(((((int)stalactite->get_pos().x + 16) / 64) % 3) == (stomp_count % 3)) { + stalactite->start_shaking(); + } + } + } /* if(stalactite && stalactite->is_hanging()) */ } - - if(nearest) - nearest->start_shaking(); } void @@ -290,28 +272,28 @@ Yeti::collision_solid(const CollisionHit& hit) physic.set_velocity_y(0); switch (state) { case JUMP_DOWN: - run(); - break; + run(); + break; case RUN: - break; + break; case JUMP_UP: - break; + break; case BE_ANGRY: - // we just landed - if(!state_timer.started()) { - sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); - stomp_count++; - drop_stalactite(); - - // go to other side after 3 jumps - if(stomp_count == 3) { - jump_down(); - } else { - // jump again - state_timer.start(STOMP_WAIT); - } - } - break; + // we just landed + if(!state_timer.started()) { + sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); + stomp_count++; + drop_stalactite(); + + // go to other side after 3 jumps + if(stomp_count == 3) { + jump_down(); + } else { + // jump again + state_timer.start(STOMP_WAIT); + } + } + break; case SQUISHED: break; } @@ -321,4 +303,4 @@ Yeti::collision_solid(const CollisionHit& hit) } } -IMPLEMENT_FACTORY(Yeti, "yeti") +/* EOF */