#include "game_session.hpp"
#include "log.hpp"
#include "level.hpp"
+#include "object/bullet.hpp"
static const float SQUISH_TIME = 2;
static const float X_OFFSCREEN_DISTANCE = 1600;
static const float Y_OFFSCREEN_DISTANCE = 1200;
BadGuy::BadGuy()
- : countMe(true), sprite(0), dir(LEFT), state(STATE_INIT)
-{
+ : countMe(true), sprite(0), dir(LEFT), layer(LAYER_OBJECTS), state(STATE_INIT) {
set_group(COLGROUP_DISABLED);
}
+BadGuy::BadGuy(const BadGuy& other)
+ : MovingObject(other), Serializable(other), countMe(other.countMe), physic(other.physic), activated(other.activated), start_position(other.start_position), dir(other.dir), layer(other.layer), state(other.state), state_timer(other.state_timer)
+{
+ sprite = new Sprite(*other.sprite);
+}
+
BadGuy::~BadGuy()
{
delete sprite;
if(state == STATE_FALLING) {
DrawingEffect old_effect = context.get_drawing_effect();
context.set_drawing_effect((DrawingEffect) (old_effect | VERTICAL_FLIP));
- sprite->draw(context, get_pos(), LAYER_OBJECTS);
+ sprite->draw(context, get_pos(), layer);
context.set_drawing_effect(old_effect);
} else {
- sprite->draw(context, get_pos(), LAYER_OBJECTS);
+ sprite->draw(context, get_pos(), layer);
}
}
if(player)
return collision_player(*player, hit);
+ Bullet* bullet = dynamic_cast<Bullet*> (&other);
+ if(bullet)
+ return collision_bullet(*bullet, hit);
+
return FORCE_MOVE;
}
case STATE_SQUISHED:
HitResponse
BadGuy::collision_player(Player& player, const CollisionHit& )
{
- if(player.is_invincible()) {
- kill_fall();
- return ABORT_MOVE;
- }
-
/*
printf("PlayerHit: GT %3.1f PM: %3.1f %3.1f BM: %3.1f %3.1f Hit: %3.1f %3.1f\n",
game_time,
*/
// hit from above?
- if(player.get_movement().y /*- get_movement().y*/ > 0
- && player.get_bbox().p2.y <
- (get_bbox().p1.y + get_bbox().p2.y) / 2) {
+ if(player.get_bbox().p2.y < (bbox.p1.y + 16)) {
// if it's not possible to squish us, then this will hurt
if(collision_squished(player))
return ABORT_MOVE;
}
- player.kill(Player::SHRINK);
+ if(player.is_invincible()) {
+ kill_fall();
+ return ABORT_MOVE;
+ }
+
+ player.kill(false);
return FORCE_MOVE;
}
return false;
}
+HitResponse
+BadGuy::collision_bullet(Bullet& , const CollisionHit& )
+{
+ kill_fall();
+ return ABORT_MOVE;
+}
+
void
BadGuy::kill_squished(Player& player)
{