4 // Copyright (C) 2006 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 02111-1307, USA.
22 #include "nolok_01.hpp"
23 #include "badguy/snail.hpp"
24 #include "trigger/door.hpp"
27 #define SHOOT_TIME 0.4
29 #define INITIAL_HITPOINTS 3
30 #define INITIAL_BULLET_HP 10
32 static const float WALKSPEED = 90;
34 //TODO: Create sprite, limit max number of snowballs
35 Nolok_01::Nolok_01(const lisp::Lisp& reader)
36 : BadGuy(reader, "images/creatures/nolok/nolok.sprite")
41 Nolok_01::Nolok_01(const Vector& pos)
42 : BadGuy(pos, "images/creatures/nolok/nolok.sprite")
48 Nolok_01::write(lisp::Writer& writer)
50 writer.start_list("nolok_01");
52 writer.write_float("x", start_position.x);
53 writer.write_float("y", start_position.y);
55 writer.end_list("nolok_01");
61 //hitpoints = INITIAL_HITPOINTS;
62 //bullet_hitpoints = INITIAL_BULLET_HP;
63 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
64 sprite->set_action(dir == LEFT ? "left" : "right");
66 action_timer.start(WALK_TIME);
70 Nolok_01::active_update(float elapsed_time)
72 if (action_timer.check()) {
76 sprite->set_action("jump");
77 physic.set_velocity_y(700);
79 action_timer.start(JUMP_TIME);
84 sprite->set_action("throw");
86 action_timer.start(SHOOT_TIME);
91 Sector::current()->add_object(new Snail(Vector(get_pos().x - 64, get_pos().y), LEFT));
92 Sector::current()->add_object(new Snail(Vector(get_pos().x + 64, get_pos().y), RIGHT));
93 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
94 sprite->set_action(dir == LEFT ? "left" : "right");
96 action_timer.start(WALK_TIME);
101 movement = physic.get_movement(elapsed_time);
105 Nolok_01::collision_squished(Player& player)
108 player.bounce(*this);
110 if (hitpoints <= 0) {
111 bullet_hitpoints = 0;
112 sprite->set_action("dead");
113 kill_squished(player);
114 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
122 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
124 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
125 if (action != JUMPING) physic.set_velocity_y(0);
126 } else { // hit right or left
127 dir = dir == LEFT ? RIGHT : LEFT;
128 sprite->set_action(dir == LEFT ? "left" : "right");
129 physic.set_velocity_x(-physic.get_velocity_x());
135 //TODO: Hitpoint count incorrect when combining squishing and shooting
137 Nolok_01::kill_fall()
141 if (bullet_hitpoints <= 0) {
143 sound_manager->play("sounds/fall.wav", this,
145 physic.set_velocity_y(0);
146 physic.enable_gravity(true);
147 set_state(STATE_FALLING);
148 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
153 IMPLEMENT_FACTORY(Nolok_01, "nolok_01")