Fix Collision add basic digging

This commit is contained in:
Bram Verhulst
2024-03-19 17:12:24 +01:00
parent d5e4aa9752
commit a165c0bc6f
6 changed files with 43 additions and 12 deletions

View File

@@ -37,9 +37,16 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
if(utils::isKeyDown(SDL_SCANCODE_S)) {
m_Vel.y = -100;
if(m_Grounded) {
if(m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(GroundTileTypes::Air);
}
}
}
if(utils::isKeyDown(SDL_SCANCODE_A)) {
m_Vel.x = -100;
}
if(utils::isKeyDown(SDL_SCANCODE_D)) {
m_Vel.x = 100;
@@ -68,6 +75,16 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
int x = contact_time.first % WorldLevel::WORLD_WIDTH;
int y = contact_time.first / WorldLevel::WORLD_WIDTH;
WorldTile* world_tile = level.GetTileAt(Point2f{(float) x, (float) y});
//check if tile is next to player
//check if the collision happend beneeth the player
if(world_tile->GetCollisionRect().pos.y < m_Position.y) {
m_Grounded = true;
m_ContactMap[Collision::CollisionDirection::Bottom] = world_tile;
}
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
}