proves3
This commit is contained in:
@@ -446,31 +446,6 @@ auto Player::handleBorders() const -> Room::Border {
|
||||
return Room::Border::NONE;
|
||||
}
|
||||
|
||||
// Reposiciona al jugador al hacer commit definitivo a la room adyacente.
|
||||
// Se llama cuando el rectángulo completo del jugador ha salido de bounds.
|
||||
void Player::commitToRoom(Room::Border border) {
|
||||
switch (border) {
|
||||
case Room::Border::TOP:
|
||||
y_ += PlayArea::HEIGHT;
|
||||
last_grounded_position_ = static_cast<int>(y_);
|
||||
break;
|
||||
case Room::Border::BOTTOM:
|
||||
y_ -= PlayArea::HEIGHT;
|
||||
last_grounded_position_ = static_cast<int>(y_);
|
||||
break;
|
||||
case Room::Border::RIGHT:
|
||||
x_ -= PlayArea::WIDTH;
|
||||
break;
|
||||
case Room::Border::LEFT:
|
||||
x_ += PlayArea::WIDTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
border_ = Room::Border::NONE;
|
||||
syncSpriteAndCollider();
|
||||
}
|
||||
|
||||
void Player::setAdjacentRoom(std::shared_ptr<Room> room, Room::Border direction) {
|
||||
adjacent_room_ = std::move(room);
|
||||
adjacent_direction_ = direction;
|
||||
@@ -481,23 +456,6 @@ void Player::clearAdjacentRoom() {
|
||||
adjacent_direction_ = Room::Border::NONE;
|
||||
}
|
||||
|
||||
auto Player::isFullyOutOfBounds() const -> bool {
|
||||
switch (adjacent_direction_) {
|
||||
case Room::Border::TOP:
|
||||
return (y_ + HEIGHT) <= PlayArea::TOP;
|
||||
case Room::Border::BOTTOM:
|
||||
return y_ >= PlayArea::BOTTOM;
|
||||
case Room::Border::LEFT:
|
||||
return (x_ + WIDTH) <= PlayArea::LEFT;
|
||||
case Room::Border::RIGHT:
|
||||
return x_ >= PlayArea::RIGHT;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el TileCollider correcto y los offsets de traducción de coordenadas
|
||||
// según en qué room está el centro del jugador.
|
||||
auto Player::getCollisionContext() const -> CollisionContext {
|
||||
if (!adjacent_room_) {
|
||||
return {room_->getTileCollider(), 0.0F, 0.0F};
|
||||
@@ -534,6 +492,29 @@ auto Player::getCollisionContext() const -> CollisionContext {
|
||||
return {room_->getTileCollider(), 0.0F, 0.0F};
|
||||
}
|
||||
|
||||
void Player::switchBorders() {
|
||||
switch (border_) {
|
||||
case Room::Border::TOP:
|
||||
y_ += PlayArea::HEIGHT;
|
||||
last_grounded_position_ = static_cast<int>(y_);
|
||||
break;
|
||||
case Room::Border::BOTTOM:
|
||||
y_ -= PlayArea::HEIGHT;
|
||||
last_grounded_position_ = static_cast<int>(y_);
|
||||
break;
|
||||
case Room::Border::RIGHT:
|
||||
x_ -= PlayArea::WIDTH;
|
||||
break;
|
||||
case Room::Border::LEFT:
|
||||
x_ += PlayArea::WIDTH;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
border_ = Room::Border::NONE;
|
||||
syncSpriteAndCollider();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Geometría y renderizado
|
||||
// ============================================================================
|
||||
|
||||
@@ -63,7 +63,7 @@ class Player {
|
||||
void update(float delta_time);
|
||||
[[nodiscard]] auto isOnBorder() const -> bool { return border_ != Room::Border::NONE; }
|
||||
[[nodiscard]] auto getBorder() const -> Room::Border { return border_; }
|
||||
void commitToRoom(Room::Border border);
|
||||
void switchBorders();
|
||||
auto getRect() -> SDL_FRect { return {.x = x_, .y = y_, .w = WIDTH, .h = HEIGHT}; }
|
||||
auto getCollider() -> SDL_FRect& { return collider_box_; }
|
||||
auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; }
|
||||
@@ -73,7 +73,6 @@ class Player {
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); }
|
||||
void setAdjacentRoom(std::shared_ptr<Room> room, Room::Border direction);
|
||||
void clearAdjacentRoom();
|
||||
[[nodiscard]] auto isFullyOutOfBounds() const -> bool;
|
||||
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; }
|
||||
void setPaused(bool value) { is_paused_ = value; }
|
||||
void setIgnoreInput(bool value) { ignore_input_ = value; }
|
||||
|
||||
Reference in New Issue
Block a user