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 static const int INITIAL_HITPOINTS = 3;
35 static const int INITIAL_BULLET_HP = 10;
37 Yeti::Yeti(const lisp::Lisp& reader)
39 reader.get("x", start_position.x);
40 reader.get("y", start_position.y);
41 bbox.set_size(80, 120);
42 sprite = sprite_manager->create("yeti");
45 hitpoints = INITIAL_HITPOINTS;
46 bullet_hitpoints = INITIAL_BULLET_HP;
47 sound_manager->preload_sound("yeti_gna");
48 sound_manager->preload_sound("yeti_roar");
53 Mix_FreeChunk(sound_gna);
57 Yeti::active_action(float elapsed_time)
63 physic.set_velocity_x(RUN_SPEED);
65 physic.set_velocity_y(JUMP_VEL2);
68 physic.set_velocity_x(-RUN_SPEED);
70 physic.set_velocity_y(JUMP_VEL2);
75 sound_manager->play_sound("yeti_gna");
76 physic.set_velocity_y(JUMP_VEL1);
83 movement = physic.get_movement(elapsed_time);
89 // jump and move right
90 physic.set_velocity_y(JUMP_VEL1);
91 physic.set_velocity_x(RUN_SPEED);
93 timer.start(JUMP_TIME);
99 physic.set_velocity_y(JUMP_VEL1);
100 physic.set_velocity_x(-RUN_SPEED);
102 timer.start(JUMP_TIME);
106 Yeti::angry_jumping()
109 timer.start(ANGRY_JUMP_WAIT);
110 state = ANGRY_JUMPING;
111 physic.set_velocity_x(0);
115 Yeti::summon_snowball()
117 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT)));
121 Yeti::collision_player(Player& player, const CollisionHit& hit)
123 if(player.is_invincible()) {
127 if(hit.normal.y > .9) {
130 sound_manager->play_sound("yeti_roar");
131 if(collision_squished(player))
133 else if (hitpoints <= 0) {
134 bullet_hitpoints = 0;
135 player.kill(Player::SHRINK);
139 player.kill(Player::SHRINK);
144 Yeti::collision_squished(Player& player)
147 player.bounce(*this);
148 if (hitpoints <= 0) {
149 bullet_hitpoints = 0;
150 //sprite->set_action("dead");
151 kill_squished(player);
158 Yeti::write(lisp::Writer& )
163 Yeti::drop_stalactite()
165 YetiStalactite* nearest = 0;
166 float dist = FLT_MAX;
168 Sector* sector = Sector::current();
169 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
170 i != sector->gameobjects.end(); ++i) {
171 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
172 if(stalactite && stalactite->is_hanging()) {
174 = fabsf(stalactite->get_pos().x - sector->player->get_pos().x);
176 nearest = stalactite;
183 nearest->start_shaking();
187 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
189 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
190 physic.set_velocity_y(0);
193 } else if(state == GO_LEFT && !timer.started()) {
197 } else if(state == GO_RIGHT && !timer.started()) {
201 } else if(state == ANGRY_JUMPING) {
202 if(!timer.started()) {
205 // make a stalactite falling down and shake camera a bit
206 Sector::current()->camera->shake(.1, 0, 10);
209 // go to other side after 3 jumps
217 timer.start(ANGRY_JUMP_WAIT);
229 sound_manager->play_sound("yeti_roar");
231 if (bullet_hitpoints <= 0) {
232 sound_manager->play_sound("fall", this,
233 Sector::current()->player->get_pos());
234 physic.set_velocity_y(0);
235 physic.enable_gravity(true);
236 set_state(STATE_FALLING);
240 IMPLEMENT_FACTORY(Yeti, "yeti")