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
25 #include "object/camera.h"
26 #include "yeti_stalactite.h"
27 #include "bouncing_snowball.h"
29 static const float JUMP_VEL1 = 250;
30 static const float JUMP_VEL2 = 700;
31 static const float RUN_SPEED = 350;
32 static const float JUMP_TIME = 1.6;
33 static const float ANGRY_JUMP_WAIT = .5;
34 /// the time we are safe when tux just hit us
35 static const float SAFE_TIME = .5;
36 static const int INITIAL_HITPOINTS = 3;
38 Yeti::Yeti(const lisp::Lisp& reader)
40 reader.get("x", start_position.x);
41 reader.get("y", start_position.y);
42 bbox.set_size(80, 120);
43 sprite = sprite_manager->create("yeti");
46 sound_manager->preload_sound("yeti_gna");
47 sound_manager->preload_sound("yeti_roar");
48 hit_points = INITIAL_HITPOINTS;
56 Yeti::draw(DrawingContext& context)
58 // we blink when we are safe
59 if(safe_timer.started() && size_t(global_time*40)%2)
62 BadGuy::draw(context);
66 Yeti::active_action(float elapsed_time)
72 physic.set_velocity_x(RUN_SPEED);
74 physic.set_velocity_y(JUMP_VEL2);
77 physic.set_velocity_x(-RUN_SPEED);
79 physic.set_velocity_y(JUMP_VEL2);
84 sound_manager->play_sound("yeti_gna");
85 physic.set_velocity_y(JUMP_VEL1);
92 movement = physic.get_movement(elapsed_time);
98 // jump and move right
99 physic.set_velocity_y(JUMP_VEL1);
100 physic.set_velocity_x(RUN_SPEED);
102 timer.start(JUMP_TIME);
108 physic.set_velocity_y(JUMP_VEL1);
109 physic.set_velocity_x(-RUN_SPEED);
111 timer.start(JUMP_TIME);
115 Yeti::angry_jumping()
118 timer.start(ANGRY_JUMP_WAIT);
119 state = ANGRY_JUMPING;
120 physic.set_velocity_x(0);
124 Yeti::summon_snowball()
126 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT)));
130 Yeti::collision_squished(Player& player)
132 if(safe_timer.started())
135 player.bounce(*this);
136 sound_manager->play_sound("yeti_roar");
138 if(hit_points <= 0) {
139 sprite->set_action("dead");
140 kill_squished(player);
142 safe_timer.start(SAFE_TIME);
151 // shooting bullets or being invincible won't work :)
155 Yeti::write(lisp::Writer& )
160 Yeti::drop_stalactite()
162 YetiStalactite* nearest = 0;
163 float dist = FLT_MAX;
165 Sector* sector = Sector::current();
166 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
167 i != sector->gameobjects.end(); ++i) {
168 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
169 if(stalactite && stalactite->is_hanging()) {
171 = fabsf(stalactite->get_pos().x - sector->player->get_pos().x);
173 nearest = stalactite;
180 nearest->start_shaking();
184 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
186 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
187 physic.set_velocity_y(0);
190 } else if(state == GO_LEFT && !timer.started()) {
194 } else if(state == GO_RIGHT && !timer.started()) {
198 } else if(state == ANGRY_JUMPING) {
199 if(!timer.started()) {
202 // make a stalactite falling down and shake camera a bit
203 Sector::current()->camera->shake(.1, 0, 10);
206 // go to other side after 3 jumps
214 timer.start(ANGRY_JUMP_WAIT);
223 IMPLEMENT_FACTORY(Yeti, "yeti")