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
24 #include "badguy/bouncing_snowball.h"
25 #include "trigger/door.h"
28 #define SHOOT_TIME 0.4
30 #define INITIAL_HITPOINTS 3
31 #define INITIAL_BULLET_HP 10
33 static const float WALKSPEED = 90;
35 //TODO: Create sprite, limit max number of snowballs
36 Nolok_01::Nolok_01(const lisp::Lisp& reader)
38 reader.get("x", start_position.x);
39 reader.get("y", start_position.y);
40 bbox.set_size(31.8, 63.8);
41 sprite = sprite_manager->create("dummyguy");
44 Nolok_01::Nolok_01(float pos_x, float pos_y)
46 start_position.x = pos_x;
47 start_position.y = pos_y;
48 bbox.set_size(31.8, 63.8);
49 sprite = sprite_manager->create("dummyguy");
53 Nolok_01::write(lisp::Writer& writer)
55 writer.start_list("nolok_01");
57 writer.write_float("x", start_position.x);
58 writer.write_float("y", start_position.y);
60 writer.end_list("nolok_01");
66 hitpoints = INITIAL_HITPOINTS;
67 bullet_hitpoints = INITIAL_BULLET_HP;
68 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
69 sprite->set_action(dir == LEFT ? "left" : "right");
71 action_timer.start(WALK_TIME);
75 Nolok_01::active_action(float elapsed_time)
77 if (action_timer.check()) {
81 sprite->set_action("jump");
82 physic.set_velocity_y(700);
84 action_timer.start(JUMP_TIME);
89 sprite->set_action("throw");
91 action_timer.start(SHOOT_TIME);
96 Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
97 Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
98 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
99 sprite->set_action(dir == LEFT ? "left" : "right");
101 action_timer.start(WALK_TIME);
106 movement = physic.get_movement(elapsed_time);
110 Nolok_01::collision_squished(Player& player)
113 player.bounce(*this);
114 if (hitpoints <= 0) {
115 bullet_hitpoints = 0;
116 sprite->set_action("dead");
117 kill_squished(player);
118 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
125 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
127 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
128 if (action != JUMPING) physic.set_velocity_y(0);
129 } else { // hit right or left
130 dir = dir == LEFT ? RIGHT : LEFT;
131 sprite->set_action(dir == LEFT ? "left" : "right");
132 physic.set_velocity_x(-physic.get_velocity_x());
138 //TODO: Hitpoint count incorrect when combining squishing and shooting
140 Nolok_01::kill_fall()
143 if (bullet_hitpoints <= 0) {
145 sound_manager->play_sound("fall", this,
146 Sector::current()->player->get_pos());
147 physic.set_velocity_y(0);
148 physic.enable_gravity(true);
149 set_state(STATE_FALLING);
150 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
152 std::cout << "KILL_FALL - HITPOINTS: " << hitpoints << ", BULLET HP: " << bullet_hitpoints << std::endl;
155 IMPLEMENT_FACTORY(Nolok_01, "nolok_01")