Add basic controller Support

Fix more memory leaks (seeing a trend here)
This commit is contained in:
Bram Verhulst
2024-04-24 21:38:14 +02:00
parent 1b90f222a4
commit f5d352239c
14 changed files with 2267 additions and 166 deletions

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include "colors.h"
#include "GroundTileTypeManager.h"
#include "utils.h"
#include "Levels/World/WorldLevel.h"
#include "Animations/Animation.h"
@@ -105,7 +106,7 @@ bool Player::CanDig(Collision::CollisionDirection dir, WorldLevel& level) {
GroundTileType type = *tile->GetTileType();
//TODO: Add a list of non diggable tiles
if (type == Tiles::Special::HARD_LEFT || type == Tiles::Special::HARD_MIDDLE || type == Tiles::Special::HARD_RIGHT) {
if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT) {
return false;
}
@@ -191,7 +192,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
WorldTile* tile = gridManager.GetTileAtIndex(x, y);
if (*tile->GetTileType() != Tiles::AIR) {
if (*tile->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
tile->m_Hightlight = false;
if (Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
contactTimes.emplace_back(std::pair<int, float> { x + y * WORLD_WIDTH, t });
@@ -273,7 +274,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
std::cout << progress << '\n';
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
if (progress >= 0.5f && !m_HasDeletedTile) {
m_DigTile->SetTileType(Tiles::AIR);
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
m_DigTile = nullptr;
m_HasDeletedTile = true;
}