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.h"
27 #include "yeti_stalactite.h"
28 #include "bouncing_snowball.h"
29 #include "game_session.h"
30 #include "scripting/script_interpreter.h"
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");
50 sound_manager->preload_sound("yeti_gna");
51 sound_manager->preload_sound("yeti_roar");
52 hit_points = INITIAL_HITPOINTS;
53 reader.get("dead-script", dead_script);
62 Yeti::draw(DrawingContext& context)
64 // we blink when we are safe
65 if(safe_timer.started() && size_t(global_time*40)%2)
68 BadGuy::draw(context);
72 Yeti::active_update(float elapsed_time)
78 physic.set_velocity_x(RUN_SPEED);
80 physic.set_velocity_y(JUMP_VEL2);
83 physic.set_velocity_x(-RUN_SPEED);
85 physic.set_velocity_y(JUMP_VEL2);
90 sound_manager->play_sound("yeti_gna");
91 physic.set_velocity_y(JUMP_VEL1);
98 movement = physic.get_movement(elapsed_time);
104 // jump and move right
105 physic.set_velocity_y(JUMP_VEL1);
106 physic.set_velocity_x(RUN_SPEED);
108 timer.start(JUMP_TIME);
114 physic.set_velocity_y(JUMP_VEL1);
115 physic.set_velocity_x(-RUN_SPEED);
117 timer.start(JUMP_TIME);
121 Yeti::angry_jumping()
124 timer.start(ANGRY_JUMP_WAIT);
125 state = ANGRY_JUMPING;
126 physic.set_velocity_x(0);
130 Yeti::summon_snowball()
132 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT)));
136 Yeti::collision_squished(Player& player)
138 if(safe_timer.started())
141 player.bounce(*this);
142 sound_manager->play_sound("yeti_roar");
144 if(hit_points <= 0) {
145 sprite->set_action("dead");
146 kill_squished(player);
149 if(dead_script != "") {
150 ScriptInterpreter::add_script_object(Sector::current(),
151 "Yeti - dead-script", dead_script);
154 safe_timer.start(SAFE_TIME);
163 // shooting bullets or being invincible won't work :)
167 Yeti::write(lisp::Writer& )
172 Yeti::drop_stalactite()
174 YetiStalactite* nearest = 0;
175 float dist = FLT_MAX;
177 Sector* sector = Sector::current();
178 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
179 i != sector->gameobjects.end(); ++i) {
180 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
181 if(stalactite && stalactite->is_hanging()) {
183 = fabsf(stalactite->get_pos().x - sector->player->get_pos().x);
185 nearest = stalactite;
192 nearest->start_shaking();
196 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
198 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
199 physic.set_velocity_y(0);
202 } else if(state == GO_LEFT && !timer.started()) {
205 sprite->set_action("right");
207 } else if(state == GO_RIGHT && !timer.started()) {
210 sprite->set_action("left");
212 } else if(state == ANGRY_JUMPING) {
213 if(!timer.started()) {
216 // make a stalactite falling down and shake camera a bit
217 Sector::current()->camera->shake(.1, 0, 10);
220 // go to other side after 3 jumps
228 timer.start(ANGRY_JUMP_WAIT);
237 IMPLEMENT_FACTORY(Yeti, "yeti")