4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "object/camera.hpp"
27 #include "yeti_stalactite.hpp"
28 #include "bouncing_snowball.hpp"
29 #include "game_session.hpp"
30 #include "scripting/script_interpreter.hpp"
32 static const float JUMP_VEL1 = 250;
33 static const float JUMP_VEL2 = 700;
34 static const float RUN_SPEED = 350;
35 static const float JUMP_TIME = 1.6;
36 static const float ANGRY_JUMP_WAIT = .5;
37 /// the time we are safe when tux just hit us
38 static const float SAFE_TIME = .5;
39 static const int INITIAL_HITPOINTS = 3;
41 Yeti::Yeti(const lisp::Lisp& reader)
43 reader.get("x", start_position.x);
44 reader.get("y", start_position.y);
45 bbox.set_size(80, 120);
46 sprite = sprite_manager->create("yeti");
47 sprite->set_action("right");
51 sound_manager->preload_sound("yeti_gna");
52 sound_manager->preload_sound("yeti_roar");
54 hit_points = INITIAL_HITPOINTS;
55 reader.get("dead-script", dead_script);
64 Yeti::draw(DrawingContext& context)
66 // we blink when we are safe
67 if(safe_timer.started() && size_t(global_time*40)%2)
70 BadGuy::draw(context);
74 Yeti::active_update(float elapsed_time)
80 physic.set_velocity_x(RUN_SPEED);
82 physic.set_velocity_y(JUMP_VEL2);
85 physic.set_velocity_x(-RUN_SPEED);
87 physic.set_velocity_y(JUMP_VEL2);
92 sound_manager->play("sounds/yeti_gna.wav");
93 physic.set_velocity_y(JUMP_VEL1);
100 movement = physic.get_movement(elapsed_time);
106 // jump and move right
107 physic.set_velocity_y(JUMP_VEL1);
108 physic.set_velocity_x(RUN_SPEED);
110 timer.start(JUMP_TIME);
116 physic.set_velocity_y(JUMP_VEL1);
117 physic.set_velocity_x(-RUN_SPEED);
119 timer.start(JUMP_TIME);
123 Yeti::angry_jumping()
126 timer.start(ANGRY_JUMP_WAIT);
127 state = ANGRY_JUMPING;
128 physic.set_velocity_x(0);
132 Yeti::summon_snowball()
134 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT)));
138 Yeti::collision_squished(Player& player)
140 if(safe_timer.started())
143 player.bounce(*this);
144 sound_manager->play("sounds/yeti_roar.wav");
146 if(hit_points <= 0) {
147 sprite->set_action("dead");
148 kill_squished(player);
151 if(dead_script != "") {
152 ScriptInterpreter::add_script_object(Sector::current(),
153 "Yeti - dead-script", dead_script);
156 safe_timer.start(SAFE_TIME);
165 // shooting bullets or being invincible won't work :)
169 Yeti::write(lisp::Writer& )
174 Yeti::drop_stalactite()
176 YetiStalactite* nearest = 0;
177 float dist = FLT_MAX;
179 Sector* sector = Sector::current();
180 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
181 i != sector->gameobjects.end(); ++i) {
182 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
183 if(stalactite && stalactite->is_hanging()) {
185 = fabsf(stalactite->get_pos().x - sector->player->get_pos().x);
187 nearest = stalactite;
194 nearest->start_shaking();
198 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
200 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
201 physic.set_velocity_y(0);
204 } else if(state == GO_LEFT && !timer.started()) {
207 sprite->set_action("right");
209 } else if(state == GO_RIGHT && !timer.started()) {
212 sprite->set_action("left");
214 } else if(state == ANGRY_JUMPING) {
215 if(!timer.started()) {
218 // make a stalactite falling down and shake camera a bit
219 Sector::current()->camera->shake(.1, 0, 10);
222 // go to other side after 3 jumps
230 timer.start(ANGRY_JUMP_WAIT);
239 IMPLEMENT_FACTORY(Yeti, "yeti")