// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#include <config.h>
#include "badguy.h"
BadGuy::BadGuy()
: sprite(0), dir(LEFT), state(STATE_INIT)
{
- //Set hitpoints and bullet hitpoints
- hitpoints = 1;
- bullet_hitpoints = 1;
}
BadGuy::~BadGuy()
return;
if(state == STATE_FALLING) {
uint32_t old_effect = context.get_drawing_effect();
- context.set_drawing_effect(old_effect & VERTICAL_FLIP);
+ context.set_drawing_effect(old_effect | VERTICAL_FLIP);
sprite->draw(context, get_pos(), LAYER_OBJECTS);
context.set_drawing_effect(old_effect);
} else {
}
HitResponse
-BadGuy::collision_player(Player& player, const CollisionHit& hit)
+BadGuy::collision_player(Player& player, const CollisionHit& )
{
if(player.is_invincible()) {
kill_fall();
return ABORT_MOVE;
}
- if(hit.normal.y > .9) {
- //TODO: fix inaccuracy (tux sometimes dies even if badguy was hit)
- // give badguys some invincible time (prevent them from being hit multiple times)
- hitpoints--;
- bullet_hitpoints--;
- if(collision_squished(player))
- return ABORT_MOVE;
- else if (hitpoints <= 0) {
- bullet_hitpoints = 0;
+ // hit from above?
+ if(player.get_movement().y > 0 && player.get_bbox().p2.y <
+ (get_bbox().p1.y + get_bbox().p2.y) / 2) {
+ // if it's not is it possible to squish us, then this will hurt
+ if(!collision_squished(player))
player.kill(Player::SHRINK);
- return FORCE_MOVE;
- }
+
+ return FORCE_MOVE;
}
player.kill(Player::SHRINK);
return FORCE_MOVE;
void
BadGuy::kill_fall()
{
- bullet_hitpoints--;
- if (bullet_hitpoints <= 0) {
- hitpoints = 0;
- sound_manager->play_sound("fall", this,
- Sector::current()->player->get_pos());
- physic.set_velocity_y(0);
- physic.enable_gravity(true);
- set_state(STATE_FALLING);
- }
+ sound_manager->play_sound("fall", this,
+ Sector::current()->player->get_pos());
+ physic.set_velocity_y(0);
+ physic.enable_gravity(true);
+ set_state(STATE_FALLING);
}
void
Vector start_position;
Direction dir;
-
- int hitpoints;
- int bullet_hitpoints;
private:
void try_activate();
void
Nolok_01::activate()
{
- hitpoints = INITIAL_HITPOINTS;
- bullet_hitpoints = INITIAL_BULLET_HP;
+ //hitpoints = INITIAL_HITPOINTS;
+ //bullet_hitpoints = INITIAL_BULLET_HP;
physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
sprite->set_action(dir == LEFT ? "left" : "right");
action = WALKING;
{
bool result = false;
player.bounce(*this);
+#if 0
if (hitpoints <= 0) {
bullet_hitpoints = 0;
sprite->set_action("dead");
Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
result = true;
}
+#endif
return result;
}
void
Nolok_01::kill_fall()
{
+#if 0
bullet_hitpoints--;
if (bullet_hitpoints <= 0) {
hitpoints = 0;
set_state(STATE_FALLING);
Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
}
+#endif
}
IMPLEMENT_FACTORY(Nolok_01, "nolok_01")
static const float RUN_SPEED = 350;
static const float JUMP_TIME = 1.6;
static const float ANGRY_JUMP_WAIT = .5;
+/// the time we are safe when tux just hit us
+static const float SAFE_TIME = .5;
static const int INITIAL_HITPOINTS = 3;
-static const int INITIAL_BULLET_HP = 10;
Yeti::Yeti(const lisp::Lisp& reader)
{
sprite = sprite_manager->create("yeti");
state = INIT;
side = LEFT;
- hitpoints = INITIAL_HITPOINTS;
- bullet_hitpoints = INITIAL_BULLET_HP;
sound_manager->preload_sound("yeti_gna");
- sound_manager->preload_sound("yeti_roar");
+ sound_manager->preload_sound("yeti_roar");
+ hit_points = INITIAL_HITPOINTS;
}
Yeti::~Yeti()
{
- Mix_FreeChunk(sound_gna);
+}
+
+void
+Yeti::draw(DrawingContext& context)
+{
+ // we blink when we are safe
+ if(safe_timer.started() && size_t(global_time*40)%2)
+ return;
+
+ BadGuy::draw(context);
}
void
Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT)));
}
-HitResponse
-Yeti::collision_player(Player& player, const CollisionHit& hit)
-{
- if(player.is_invincible()) {
- kill_fall();
- return ABORT_MOVE;
- }
- if(hit.normal.y > .9) {
- hitpoints--;
- bullet_hitpoints--;
- sound_manager->play_sound("yeti_roar");
- if(collision_squished(player))
- return ABORT_MOVE;
- else if (hitpoints <= 0) {
- bullet_hitpoints = 0;
- player.kill(Player::SHRINK);
- return FORCE_MOVE;
- }
- }
- player.kill(Player::SHRINK);
- return FORCE_MOVE;
-}
-
bool
Yeti::collision_squished(Player& player)
{
- bool result = false;
+ if(safe_timer.started())
+ return true;
+
player.bounce(*this);
- if (hitpoints <= 0) {
- bullet_hitpoints = 0;
- //sprite->set_action("dead");
+ sound_manager->play_sound("yeti_roar");
+ hit_points--;
+ if(hit_points <= 0) {
+ sprite->set_action("dead");
kill_squished(player);
- result = true;
+ } else {
+ safe_timer.start(SAFE_TIME);
}
- return result;
+
+ return true;
+}
+
+void
+Yeti::kill_fall()
+{
+ // shooting bullets or being invincible won't work :)
}
void
return CONTINUE;
}
-void
-Yeti::kill_fall()
-{
- sound_manager->play_sound("yeti_roar");
- bullet_hitpoints--;
- if (bullet_hitpoints <= 0) {
- sound_manager->play_sound("fall", this,
- Sector::current()->player->get_pos());
- physic.set_velocity_y(0);
- physic.enable_gravity(true);
- set_state(STATE_FALLING);
- }
-}
-
IMPLEMENT_FACTORY(Yeti, "yeti")
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#ifndef __YETI_H__
#define __YETI_H__
Yeti(const lisp::Lisp& lisp);
~Yeti();
+ void draw(DrawingContext& context);
void write(lisp::Writer& writer);
void active_action(float elapsed_time);
- HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
- HitResponse collision_player(Player& player, const CollisionHit& hit);
+ HitResponse collision_solid(GameObject& object, const CollisionHit& hit);
bool collision_squished(Player& player);
void kill_fall();
Direction side;
YetiState state;
Timer timer;
+ Timer safe_timer;
int jumpcount;
- Mix_Chunk* sound_gna;
- Mix_Chunk* sound_roar;
+ int hit_points;
};
#endif
if(controller->hold(Controller::JUMP))
physic.set_velocity_y(520);
else
- physic.set_velocity_y(200);
+ physic.set_velocity_y(300);
}