entity destruction, etc.
This commit is contained in:
@@ -37,5 +37,8 @@ namespace Game::AGame {
|
||||
} else if (playerY > bottomBound) {
|
||||
Object::Camera::getInstance().move(0.f, mSpeed * deltaTime);
|
||||
}
|
||||
|
||||
const bool* state = SDL_GetKeyboardState(nullptr);
|
||||
mSpeed = state[SDL_SCANCODE_LSHIFT] ? 400.f : 200.f;
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,6 @@ namespace Game::AGame {
|
||||
if (state[SDL_SCANCODE_S]) mTransform.y += mSpeed * deltaTime;
|
||||
if (state[SDL_SCANCODE_A]) mTransform.x -= mSpeed * deltaTime;
|
||||
if (state[SDL_SCANCODE_D]) mTransform.x += mSpeed * deltaTime;
|
||||
mSpeed = state[SDL_SCANCODE_LSHIFT] ? 400.f : 200.f;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,19 @@ namespace Game::State {
|
||||
LOG("Added entity '" << addedEntity->getName() << "' to GameState");
|
||||
}
|
||||
|
||||
bool GameState::removeEntity(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mMutex); // Lock the mutex for thread safety
|
||||
for (size_t i = 0; i < mEntities.size(); i++) {
|
||||
if (mEntities[i]->getName() == name) {
|
||||
mEntities[i]->destroyed();
|
||||
mEntities.erase(mEntities.begin() + i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameState::sort() {
|
||||
std::lock_guard<std::mutex> lock(mMutex); // Lock the mutex for thread safety
|
||||
std::sort(mEntities.begin(), mEntities.end(), [](const std::unique_ptr<Object::Entity>& a, const std::unique_ptr<Object::Entity>& b) {
|
||||
@@ -31,6 +44,16 @@ namespace Game::State {
|
||||
});
|
||||
}
|
||||
|
||||
void GameState::wipe() {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
for (const auto& entity : mEntities) {
|
||||
if (entity) {
|
||||
entity->destroyed();
|
||||
}
|
||||
}
|
||||
mEntities.clear();
|
||||
}
|
||||
|
||||
Object::Entity* GameState::getEntityByName(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mMutex); // Lock the mutex for thread safety
|
||||
for (const auto& entity : mEntities) {
|
||||
|
||||
Reference in New Issue
Block a user