sound_manager->preload("sounds/bigjump.wav");
sound_manager->preload("sounds/jump.wav");
sound_manager->preload("sounds/hurt.wav");
+ sound_manager->preload("sounds/kill.wav");
sound_manager->preload("sounds/skid.wav");
sound_manager->preload("sounds/flip.wav");
sound_manager->preload("sounds/invincible_start.ogg");
movement = physic.get_movement(elapsed_time);
if(grabbed_object != NULL && !dying) {
- Vector pos = get_pos() +
- Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32);
- grabbed_object->grab(*this, pos, dir);
+ position_grabbed_object();
}
if(grabbed_object != NULL && dying){
if(controller->hold(Controller::JUMP) && jump_button_timer.started() && can_jump) {
jump_button_timer.stop();
if (duck) {
- // when running, only jump a little bit; else do a backflip
- if ((physic.get_velocity_x() != 0) ||
- (controller->hold(Controller::LEFT)) ||
- (controller->hold(Controller::RIGHT)))
- {
+ // jump a little bit if moving in same direction; otherwise, do a backflip
+ if ((physic.get_velocity_x() < 0 && dir == LEFT) || (physic.get_velocity_x() > 0 && dir == RIGHT)) {
do_jump(-300);
- }
- else
- {
+ } else {
do_backflip();
}
} else {
if(Sector::current()->add_bullet(
get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
: Vector(32, bbox.get_height()/2)),
+ player_status,
physic.get_velocity_x(), dir))
shooting_timer.start(SHOOTING_TIME);
}
try_grab();
if(!controller->hold(Controller::ACTION) && grabbed_object) {
- // move the grabbed object a bit away from tux
- Vector pos = get_pos() +
- Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
- bbox.get_height()*0.66666 - 32);
- Rectf dest(pos, pos + Vector(32, 32));
- if(Sector::current()->is_free_of_movingstatics(dest)) {
- MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
- if(moving_object) {
- moving_object->set_pos(pos);
+ MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
+ if(moving_object) {
+ // move the grabbed object a bit away from tux
+ Rectf grabbed_bbox = moving_object->get_bbox();
+ Rectf dest;
+ dest.p2.y = bbox.get_top() + bbox.get_height()*0.66666;
+ dest.p1.y = dest.p2.y - grabbed_bbox.get_height();
+ if(dir == LEFT) {
+ dest.p2.x = bbox.get_left() - 1;
+ dest.p1.x = dest.p2.x - grabbed_bbox.get_width();
} else {
- log_debug << "Non MovingObject grabbed?!?" << std::endl;
+ dest.p1.x = bbox.get_right() + 1;
+ dest.p2.x = dest.p1.x + grabbed_bbox.get_width();
}
- if(controller->hold(Controller::UP)) {
- grabbed_object->ungrab(*this, UP);
- } else {
- grabbed_object->ungrab(*this, dir);
+ if(Sector::current()->is_free_of_movingstatics(dest)) {
+ moving_object->set_pos(dest.p1);
+ if(controller->hold(Controller::UP)) {
+ grabbed_object->ungrab(*this, UP);
+ } else {
+ grabbed_object->ungrab(*this, dir);
+ }
+ grabbed_object = NULL;
}
- grabbed_object = NULL;
+ } else {
+ log_debug << "Non MovingObject grabbed?!?" << std::endl;
}
}
}
void
+Player::position_grabbed_object()
+{
+ MovingObject* moving_object = dynamic_cast<MovingObject*>(grabbed_object);
+ assert(moving_object);
+
+ // Position where we will hold the lower-inner corner
+ Vector pos(get_bbox().get_left() + get_bbox().get_width()/2,
+ get_bbox().get_top() + get_bbox().get_height()*0.66666);
+
+ // Adjust to find the grabbed object's upper-left corner
+ if (dir == LEFT)
+ pos.x -= moving_object->get_bbox().get_width();
+ pos.y -= moving_object->get_bbox().get_height();
+
+ grabbed_object->grab(*this, pos, dir);
+}
+
+void
Player::try_grab()
{
if(controller->hold(Controller::ACTION) && !grabbed_object
if(moving_object->get_bbox().contains(pos)) {
if (climbing) stop_climbing(*climbing);
grabbed_object = portable;
- grabbed_object->grab(*this, get_pos(), dir);
+ position_grabbed_object();
break;
}
}
float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
float py = Sector::current()->camera->get_translation().y;
py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
- context.draw_surface(airarrow.get(), Vector(px, py), LAYER_HUD - 1);
+ context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
}
std::string sa_prefix = "";
90-40, 90-20,
Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
LAYER_OBJECTS+1));
+ Sector::current()->camera->shake(.1f, 0, 5);
}
} else if(hit.top) {
growing = false;
- sound_manager->play("sounds/hurt.wav");
-
if (climbing) stop_climbing(*climbing);
physic.set_velocity_x(0);
if(!completely && is_big()) {
+ sound_manager->play("sounds/hurt.wav");
+
if(player_status->bonus == FIRE_BONUS
|| player_status->bonus == ICE_BONUS) {
safe_timer.start(TUX_SAFE_TIME);
duck = false;
}
} else {
+ sound_manager->play("sounds/kill.wav");
// do not die when in edit mode
if (edit_mode) {