mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 20:41:47 +01:00
Fix Collision add basic digging
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user