From 168291d025f8873e55fbae9df8e2088353231946 Mon Sep 17 00:00:00 2001 From: xGauss05 Date: Sun, 18 Dec 2022 12:04:22 +0100 Subject: [PATCH] Cleaned code. Done the following: - Removed unnecessary Item.cpp / .h - Deactivate all DEBUG features when disabling it. --- Game/Game.vcxproj | 2 - Game/Game.vcxproj.filters | 6 --- Game/Source/App.cpp | 24 +++++------- Game/Source/Debug.cpp | 54 ++++++++++++++++++++----- Game/Source/Enemy_Fly.cpp | 39 +++++++++--------- Game/Source/Enemy_Fly.h | 1 - Game/Source/Enemy_Walk.cpp | 64 ++++++++---------------------- Game/Source/Enemy_Walk.h | 3 +- Game/Source/Entity.h | 6 +-- Game/Source/EntityManager.cpp | 69 ++++++++++++++++---------------- Game/Source/EntityManager.h | 10 ++--- Game/Source/Item.cpp | 74 ----------------------------------- Game/Source/Item.h | 42 -------------------- Game/Source/Map.cpp | 44 ++++++++------------- Game/Source/Map.h | 2 +- Game/Source/Player.cpp | 2 +- Game/Source/Scene_Die.cpp | 10 +++-- Game/Source/Scene_Die.h | 1 + Game/Source/Scene_Intro.cpp | 1 - Game/Source/Scene_Level1.cpp | 5 ++- Game/Source/Scene_Level1.h | 2 +- Game/Source/Scene_Menu.cpp | 13 ++---- Game/Source/Scene_Menu.h | 1 + Game/Source/Scene_Win.cpp | 8 +++- Output/save_game.xml | 6 +-- 25 files changed, 179 insertions(+), 310 deletions(-) delete mode 100644 Game/Source/Item.cpp delete mode 100644 Game/Source/Item.h diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index 70b3b5c..87f93ac 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -104,7 +104,6 @@ - @@ -130,7 +129,6 @@ - diff --git a/Game/Game.vcxproj.filters b/Game/Game.vcxproj.filters index 787e2e5..d113ecb 100644 --- a/Game/Game.vcxproj.filters +++ b/Game/Game.vcxproj.filters @@ -16,9 +16,6 @@ Application\Entities - - Application\Entities - Modules\Gameplay\Scenes @@ -120,9 +117,6 @@ Application\Entities - - Application\Entities - Modules\Gameplay\Scenes diff --git a/Game/Source/App.cpp b/Game/Source/App.cpp index 8e75100..ff5ff1c 100644 --- a/Game/Source/App.cpp +++ b/Game/Source/App.cpp @@ -123,7 +123,6 @@ bool App::Start() item = modules.start; while (item != NULL && ret == true) - { ret = item->data->Start(); item = item->next; @@ -161,11 +160,13 @@ bool App::LoadConfig() pugi::xml_parse_result parseResult = configFile.load_file("config.xml"); - if (parseResult) { + if (parseResult) + { ret = true; configNode = configFile.child("config"); } - else { + else + { LOG("Error in App::LoadConfig(): %s", parseResult.description()); } @@ -175,6 +176,7 @@ bool App::LoadConfig() // --------------------------------------------- void App::PrepareUpdate() { + } // --------------------------------------------- @@ -196,10 +198,8 @@ bool App::PreUpdate() { pModule = item->data; - if (pModule->active == false) { - continue; - } - + if (pModule->active == false) continue; + ret = item->data->PreUpdate(); } @@ -218,9 +218,7 @@ bool App::DoUpdate() { pModule = item->data; - if (pModule->active == false) { - continue; - } + if (pModule->active == false) continue; ret = item->data->Update(dt); } @@ -239,10 +237,8 @@ bool App::PostUpdate() { pModule = item->data; - if (pModule->active == false) { - continue; - } - + if (pModule->active == false) continue; + ret = item->data->PostUpdate(); } diff --git a/Game/Source/Debug.cpp b/Game/Source/Debug.cpp index 5ac68fb..61b80ae 100644 --- a/Game/Source/Debug.cpp +++ b/Game/Source/Debug.cpp @@ -50,6 +50,7 @@ bool Debug::Update(float dt) if (debug) { + // Previous level if (app->input->GetKey(SDL_SCANCODE_F1) == KEY_DOWN) { if (app->scene->player->level > 1) @@ -60,7 +61,8 @@ bool Debug::Update(float dt) app->scene->player->TeleportTo(app->scene->player->spawn); } } - //Pass level + + // Next level if (app->input->GetKey(SDL_SCANCODE_F2) == KEY_DOWN) { if (app->scene->player->level < 4) @@ -72,23 +74,31 @@ bool Debug::Update(float dt) } } - if (app->input->GetKey(SDL_SCANCODE_F3) == KEY_DOWN) { + // Reset level + if (app->input->GetKey(SDL_SCANCODE_F3) == KEY_DOWN) + { app->entityManager->ReviveAllEntities(); - app->entityManager->TeleportToSpawnAllEntities(); + app->entityManager->NeedsToSpawnAllEntities(); app->entityManager->ActivateEnemies(); app->scene->player->TeleportTo(app->scene->player->spawn); } + // Save request if (app->input->GetKey(SDL_SCANCODE_F5) == KEY_DOWN) app->SaveGameRequest(); - + + // Load request if (app->input->GetKey(SDL_SCANCODE_F6) == KEY_DOWN) app->LoadGameRequest(); + // Enable/Disable variables if (app->input->GetKey(SDL_SCANCODE_F7) == KEY_DOWN) variables = !variables; + // Enable/Disable debug camera if (app->input->GetKey(SDL_SCANCODE_F8) == KEY_DOWN) debugCamera = !debugCamera; + // Enable/Disable hitboxes if (app->input->GetKey(SDL_SCANCODE_F9) == KEY_DOWN) hitboxes = !hitboxes; + // Enable/Disable godmode if (app->input->GetKey(SDL_SCANCODE_F10) == KEY_DOWN) { godMode = !godMode; @@ -103,22 +113,46 @@ bool Debug::Update(float dt) } } + // Enable/Disable FPS limit if (app->input->GetKey(SDL_SCANCODE_F11) == KEY_DOWN) limitFps = !limitFps; + // Insta-win if (app->input->GetKey(SDL_SCANCODE_I) == KEY_DOWN) { app->entityManager->ReviveAllEntities(); - app->entityManager->TeleportToSpawnAllEntities(); + app->entityManager->NeedsToSpawnAllEntities(); app->scene->player->ResetGame(); app->ftb->SceneFadeToBlack(app->scene, app->scene_win, 0.0f); } + // Insta-kill if (app->input->GetKey(SDL_SCANCODE_O) == KEY_DOWN) app->scene->player->isDead = true; + // Enable/Disable paths if (app->input->GetKey(SDL_SCANCODE_P) == KEY_DOWN) paths = !paths; + // Enable/Disable preference matrix if (app->input->GetKey(SDL_SCANCODE_M) == KEY_DOWN) preferenceMatrix = !preferenceMatrix; + } + else + { + if (variables != false) variables = false; + + if (hitboxes != false) hitboxes = false; + + if (debugCamera != false) debugCamera = false; + + if (godMode != false) godMode = false; + + if (limitFps != false) limitFps = false; + + if (paths != false) paths = false; + + if (preferenceMatrix != false) preferenceMatrix = false; + + if (originSelected != false) originSelected = false; + } return true; @@ -148,8 +182,8 @@ bool Debug::PostUpdate() app->font->BlitText(10, 110, 0, "Press F11 to Enable/Disable FPS cap to 30"); app->font->BlitText(320, 10, 0, "Press I to instantly WIN"); - app->font->BlitText(320, 20, 0, "Press O to kill the player"); - app->font->BlitText(320, 30, 0, "Press P to show paths"); + app->font->BlitText(320, 20, 0, "Press O to KILL the player"); + app->font->BlitText(320, 30, 0, "Press P to show PATHS"); app->font->BlitText(320, 40, 0, "Press M to show preference map"); } else { @@ -315,10 +349,12 @@ void Debug::DebugDraw() #pragma endregion - if (limitFps) { + if (limitFps) + { if (targetFPS != 30) targetFPS = 30; } - else { + else + { if (targetFPS != 60) targetFPS = 60; } } diff --git a/Game/Source/Enemy_Fly.cpp b/Game/Source/Enemy_Fly.cpp index dc7f87e..e20ec1e 100644 --- a/Game/Source/Enemy_Fly.cpp +++ b/Game/Source/Enemy_Fly.cpp @@ -49,6 +49,7 @@ bool Enemy_Fly::Awake() { spawn.y = position.y; texturePath = parameters.attribute("texturepath").as_string(); level = parameters.attribute("level").as_int(); + InitAnims(); return true; @@ -56,25 +57,30 @@ bool Enemy_Fly::Awake() { bool Enemy_Fly::Start() { - //initialize textures + // Starting flags needsToSpawn = false; isDead = false; + texture = app->tex->Load(texturePath); + dieFx = app->audio->LoadFx("Assets/Audio/Fx/enemy_die.wav"); + + // Physical body pbody = app->physics->CreateRectangle(position.x, position.y, 39, 29, DYNAMIC); pbody->listener = this; pbody->ctype = ColliderType::ENEMY; - dieFx = app->audio->LoadFx("Assets/Audio/Fx/enemy_die.wav"); b2MassData* data = new b2MassData; data->center = b2Vec2((float)40 / 2, (float)88 / 2); data->I = 0.0f; data->mass = 0.1f; pbody->body->SetMassData(data); delete data; - pbody->body->SetGravityScale(0.0f); + + // Initial position TeleportTo(spawn); return true; } -void Enemy_Fly::TeleportTo(iPoint position) { +void Enemy_Fly::TeleportTo(iPoint position) +{ pbody->body->SetLinearVelocity(b2Vec2(0, 0)); pbody->body->SetTransform(b2Vec2(PIXEL_TO_METERS(position.x), PIXEL_TO_METERS(position.y)), 0.0f); pbody->body->ApplyForce(b2Vec2(0.1f, 0.0f), pbody->body->GetWorldCenter(), true); @@ -87,7 +93,7 @@ bool Enemy_Fly::Update() currentAnim->Update(); app->render->DrawTexture(texture, position.x, position.y, &(currentAnim->GetCurrentFrame())); - //Pathfinding + // Pathfinding iPoint entityTile = app->map->ScreenToMap(METERS_TO_PIXELS(this->pbody->body->GetPosition().x), METERS_TO_PIXELS(this->pbody->body->GetPosition().y)); @@ -103,7 +109,7 @@ bool Enemy_Fly::Update() pathToPlayer.PushBack(iPoint(path->At(i)->x, path->At(i)->y)); } - //Pathfinding debug visuals + // Pathfinding debug visuals if (app->debug->debug && app->debug->paths) { for (uint i = 0; i < pathToPlayer.Count(); ++i) @@ -113,7 +119,7 @@ bool Enemy_Fly::Update() } } - //Movement + // Movement if (pathToPlayer.Count() > 1) { int dirX = pathToPlayer.At(1)->x - pathToPlayer.At(0)->x; @@ -127,7 +133,6 @@ bool Enemy_Fly::Update() pbody->body->ApplyForce(b2Vec2(2.0f, 0.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(200, 200, 0, "Must go right"); } else if (dirX < 0) { @@ -137,11 +142,9 @@ bool Enemy_Fly::Update() pbody->body->ApplyForce(b2Vec2(-2.0f, 0.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(200, 200, 0, "Must go left"); } else { - //app->font->BlitText(200, 350, 0, "X is 0;"); pbody->body->ApplyForce(b2Vec2(-pbody->body->GetLinearVelocity().x * 0.1f, 0.0f), pbody->body->GetWorldCenter(), true); } @@ -151,7 +154,6 @@ bool Enemy_Fly::Update() { pbody->body->ApplyForce(b2Vec2(0.0f, 2.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(300, 200, 0, "Must go down"); } else if (dirY < 0) { @@ -159,26 +161,21 @@ bool Enemy_Fly::Update() { pbody->body->ApplyForce(b2Vec2(0.0f, -2.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(300, 200, 0, "Must go up"); } else { - //app->font->BlitText(200, 350, 0, "Y is 0;"); pbody->body->ApplyForce(b2Vec2(0.0f, -pbody->body->GetLinearVelocity().y * 0.1f), pbody->body->GetWorldCenter(), true); } - - //app->font->BlitText(200, 300, 0, std::to_string(dirX).c_str()); - //app->font->BlitText(200, 310, 0, std::to_string(dirY).c_str()); - //app->font->BlitText(200, 320, 0, std::to_string(pbody->body->GetLinearVelocity().x).c_str()); - //app->font->BlitText(200, 330, 0, std::to_string(pbody->body->GetLinearVelocity().y).c_str()); } - if (needsToSpawn) { + if (needsToSpawn) + { TeleportTo(spawn); needsToSpawn = false; } - if (pendingToDelete) { + if (pendingToDelete) + { isDead = true; Disable(); } @@ -216,4 +213,4 @@ void Enemy_Fly::OnCollision(PhysBody* physA, PhysBody* physB) void Enemy_Fly::DeathAnimation() { -} \ No newline at end of file +} diff --git a/Game/Source/Enemy_Fly.h b/Game/Source/Enemy_Fly.h index d533264..604b40e 100644 --- a/Game/Source/Enemy_Fly.h +++ b/Game/Source/Enemy_Fly.h @@ -48,7 +48,6 @@ class Enemy_Fly : public Entity DynArray pathToPlayer; - bool pendingToDelete = false; }; #endif // ___ENEMY_FLY_H__ \ No newline at end of file diff --git a/Game/Source/Enemy_Walk.cpp b/Game/Source/Enemy_Walk.cpp index c23280c..679f44a 100644 --- a/Game/Source/Enemy_Walk.cpp +++ b/Game/Source/Enemy_Walk.cpp @@ -64,18 +64,23 @@ bool Enemy_Walk::Awake() { bool Enemy_Walk::Start() { - //initilize textures + // Starting flags needsToSpawn = false; isDead = false; + texture = app->tex->Load(texturePath); + dieFx = app->audio->LoadFx("Assets/Audio/Fx/enemy_die.wav"); + + // Physical body + lastImpulse = iPoint(0, 0); pbody = app->physics->CreateRectangle(position.x, position.y, 30, 18, DYNAMIC); pbody->listener = this; pbody->ctype = ColliderType::ENEMY; - dieFx = app->audio->LoadFx("Assets/Audio/Fx/enemy_die.wav"); b2MassData* data = new b2MassData; data->center = b2Vec2((float)40 / 2, (float)88 / 2); data->I = 0.0f; data->mass = 0.1f; pbody->body->SetMassData(data); delete data; - lastImpulse = iPoint(0, 0); + + // Initial position TeleportTo(spawn); return true; @@ -94,7 +99,8 @@ bool Enemy_Walk::Update() currentAnim->Update(); app->render->DrawTexture(texture, position.x, position.y, &(currentAnim->GetCurrentFrame())); - if (needsToSpawn) { + if (needsToSpawn) + { TeleportTo(spawn); needsToSpawn = false; } @@ -114,7 +120,7 @@ bool Enemy_Walk::Update() if (!airborn) { - //Pathfinding + // Pathfinding iPoint entityTile = app->map->ScreenToMap(METERS_TO_PIXELS(this->pbody->body->GetPosition().x), METERS_TO_PIXELS(this->pbody->body->GetPosition().y)); @@ -130,7 +136,7 @@ bool Enemy_Walk::Update() pathToPlayer.PushBack(iPoint(path->At(i)->x, path->At(i)->y)); } - //Pathfinding debug visuals + // Pathfinding debug visuals if (app->debug->debug && app->debug->paths) { for (uint i = 0; i < pathToPlayer.Count(); ++i) @@ -140,7 +146,7 @@ bool Enemy_Walk::Update() } } - //Movement + // Movement if (pathToPlayer.Count() > 1 && app->scene->player->position.y > 80) { int dirX = pathToPlayer.At(1)->x - pathToPlayer.At(0)->x; @@ -153,7 +159,6 @@ bool Enemy_Walk::Update() pbody->body->ApplyForce(b2Vec2(2.0f, 0.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(200, 200, 0, "Must go right"); } else if (dirX < 0) { @@ -163,53 +168,16 @@ bool Enemy_Walk::Update() pbody->body->ApplyForce(b2Vec2(-2.0f, 0.0f), pbody->body->GetWorldCenter(), true); } - //app->font->BlitText(200, 200, 0, "Must go left"); } - else - { - /*if (app->scene->player->pbody->body->GetPosition().x < this->pbody->body->GetPosition().x) - { - if (pbody->body->GetLinearVelocity().x < speedCap) - { - pbody->body->ApplyForce(b2Vec2(-2.0f, 0.0f), pbody->body->GetWorldCenter(), true); - } - } - else - { - if (pbody->body->GetLinearVelocity().x > -speedCap) - { - pbody->body->ApplyForce(b2Vec2(2.0f, 0.0f), pbody->body->GetWorldCenter(), true); - } - }*/ - } - - //app->font->BlitText(200, 300, 0, std::to_string(dirX).c_str()); - //app->font->BlitText(200, 310, 0, std::to_string(dirY).c_str()); - //app->font->BlitText(200, 320, 0, std::to_string(pbody->body->GetLinearVelocity().x).c_str()); - //app->font->BlitText(200, 330, 0, std::to_string(pbody->body->GetLinearVelocity().y).c_str()); } } - if (pendingToDelete) { + if (pendingToDelete) + { isDead = true; Disable(); } - - //This is only for testing - /*if (app->input->GetKey(SDL_SCANCODE_LEFT) == KEY_REPEAT) - { - pbody->body->ApplyForce(b2Vec2(-1.0f, 0.0f), pbody->body->GetWorldCenter(), true); - } - if (app->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_REPEAT) - { - pbody->body->ApplyForce(b2Vec2(1.0f, 0.0f), pbody->body->GetWorldCenter(), true); - } - if (app->input->GetKey(SDL_SCANCODE_UP) == KEY_REPEAT) - { - pbody->body->ApplyForce(b2Vec2(0.0f, -5.0f), pbody->body->GetWorldCenter(), true); - }*/ - return true; } @@ -257,4 +225,4 @@ void Enemy_Walk::OnCollision(PhysBody* physA, PhysBody* physB) void Enemy_Walk::DeathAnimation() { -} \ No newline at end of file +} diff --git a/Game/Source/Enemy_Walk.h b/Game/Source/Enemy_Walk.h index 17824ab..a82b446 100644 --- a/Game/Source/Enemy_Walk.h +++ b/Game/Source/Enemy_Walk.h @@ -50,9 +50,8 @@ class Enemy_Walk : public Entity bool jumping = false; bool stop = false; bool airborn = false; - iPoint lastImpulse; - bool pendingToDelete = false; + iPoint lastImpulse; }; #endif // ___ENEMY_WALK_H__ \ No newline at end of file diff --git a/Game/Source/Entity.h b/Game/Source/Entity.h index aec641f..40e30c3 100644 --- a/Game/Source/Entity.h +++ b/Game/Source/Entity.h @@ -9,7 +9,6 @@ enum class EntityType { PLAYER, - ITEM, SAW, ENEMY_FLY, ENEMY_WALK, @@ -87,16 +86,17 @@ class Entity public: - iPoint spawn; SString name; EntityType type; + iPoint spawn; + iPoint position; bool active = true; bool isDead; bool needsToSpawn = false; + bool pendingToDelete = false; int level; pugi::xml_node parameters; PhysBody* pbody = nullptr; - iPoint position; }; diff --git a/Game/Source/EntityManager.cpp b/Game/Source/EntityManager.cpp index d8dd7ca..f8b5b3a 100644 --- a/Game/Source/EntityManager.cpp +++ b/Game/Source/EntityManager.cpp @@ -1,6 +1,5 @@ #include "EntityManager.h" #include "Player.h" -#include "Item.h" #include "Saw.h" #include "App.h" #include "Textures.h" @@ -42,7 +41,8 @@ bool EntityManager::Awake(pugi::xml_node& config) return ret; } -bool EntityManager::Start() { +bool EntityManager::Start() +{ bool ret = true; @@ -90,10 +90,6 @@ Entity* EntityManager::CreateEntity(EntityType type) entity = new Player(); break; - case EntityType::ITEM: - entity = new Item(); - break; - case EntityType::SAW: entity = new Saw(); break; @@ -101,6 +97,7 @@ Entity* EntityManager::CreateEntity(EntityType type) case EntityType::ENEMY_FLY: entity = new Enemy_Fly(); break; + case EntityType::ENEMY_WALK: entity = new Enemy_Walk(); break; @@ -114,6 +111,11 @@ Entity* EntityManager::CreateEntity(EntityType type) return entity; } +void EntityManager::AddEntity(Entity* entity) +{ + if (entity != nullptr) entities.Add(entity); +} + void EntityManager::DestroyEntity(Entity* entity) { ListItem* item; @@ -127,28 +129,23 @@ void EntityManager::DestroyEntity(Entity* entity) } } -void EntityManager::AddEntity(Entity* entity) -{ - if (entity != nullptr) entities.Add(entity); -} - void EntityManager::ReviveAllEntities() { ListItem* item; Entity* pEntity = NULL; - for (item = entities.start; item != NULL; item = item->next) { + for (item = entities.start; item != NULL; item = item->next) + { pEntity = item->data; pEntity->isDead = false; } } -void EntityManager::TeleportToSpawnAllEntities() { +void EntityManager::NeedsToSpawnAllEntities() { ListItem* item; Entity* pEntity = NULL; - for (item = entities.start; item != NULL; item = item->next) { + for (item = entities.start; item != NULL; item = item->next) + { pEntity = item->data; - if (pEntity != app->scene->player) { - pEntity->needsToSpawn = true; - } + if (pEntity != app->scene->player) pEntity->needsToSpawn = true; } } @@ -160,14 +157,15 @@ void EntityManager::ActivateEnemies() { for (item = entities.start; item != NULL && ret == true; item = item->next) { pEntity = item->data; - if (pEntity != app->scene->player) { - if (pEntity->level != app->scene->player->level) { // check if they're on the same level + if (pEntity != app->scene->player) + { + if (pEntity->level != app->scene->player->level) + { // check if they're on the same level if (pEntity->active != false) pEntity->Disable(); // if they are active, disable them } - else { // if they are on the same level - if (pEntity->active != true) { - pEntity->Enable(); // if they are not active, enable them - } + else + { // if they are on the same level + if (pEntity->active != true) pEntity->Enable(); // if they are not active, enable them } } } @@ -195,20 +193,22 @@ bool EntityManager::LoadState(pugi::xml_node& data) ListItem* item; Entity* pEntity = NULL; pugi::xml_node node = data.child("enemy"); - for (item = entities.start; item != NULL; item = item->next) { + for (item = entities.start; item != NULL; item = item->next) + { pEntity = item->data; if (pEntity != app->scene->player && - pEntity->level == app->scene->player->level) { + pEntity->level == app->scene->player->level) + { bool isActiveInfo = node.attribute("active").as_bool(); if (pEntity->active) // entity is active { if (isActiveInfo) { // information says is active pEntity->pbody->body->SetTransform(b2Vec2(PIXEL_TO_METERS(node.attribute("x").as_int()), - PIXEL_TO_METERS(node.attribute("y").as_int())), - 0.0f); + PIXEL_TO_METERS(node.attribute("y").as_int())), + 0.0f); pEntity->pbody->body->SetLinearVelocity(b2Vec2(node.attribute("x_velocity").as_float(), - node.attribute("y_velocity").as_float())); + node.attribute("y_velocity").as_float())); } else { // information says is not active @@ -226,7 +226,7 @@ bool EntityManager::LoadState(pugi::xml_node& data) position.y = node.attribute("y").as_int(); pEntity->TeleportTo(position); pEntity->pbody->body->SetLinearVelocity(b2Vec2(node.attribute("x_velocity").as_float(), - node.attribute("y_velocity").as_float())); + node.attribute("y_velocity").as_float())); pEntity->isDead = node.attribute("isDead").as_bool(); } } @@ -242,12 +242,15 @@ bool EntityManager::SaveState(pugi::xml_node& data) pugi::xml_node node; ListItem* item; Entity* pEntity = NULL; - for (item = entities.start; item != NULL; item = item->next) { + for (item = entities.start; item != NULL; item = item->next) + { pEntity = item->data; if (pEntity != app->scene->player && - pEntity->level == app->scene->player->level) { + pEntity->level == app->scene->player->level) + { node = data.append_child("enemy"); - if (!pEntity->isDead) { + if (!pEntity->isDead) + { node.append_attribute("x") = METERS_TO_PIXELS(pEntity->pbody->body->GetPosition().x); node.append_attribute("y") = METERS_TO_PIXELS(pEntity->pbody->body->GetPosition().y); node.append_attribute("x_velocity") = pEntity->pbody->body->GetLinearVelocity().x; @@ -259,4 +262,4 @@ bool EntityManager::SaveState(pugi::xml_node& data) } return true; -} \ No newline at end of file +} diff --git a/Game/Source/EntityManager.h b/Game/Source/EntityManager.h index 982d1ea..508bce7 100644 --- a/Game/Source/EntityManager.h +++ b/Game/Source/EntityManager.h @@ -29,20 +29,20 @@ class EntityManager : public Module // Additional methods Entity* CreateEntity(EntityType type); - void DestroyEntity(Entity* entity); - void AddEntity(Entity* entity); + void DestroyEntity(Entity* entity); + void ReviveAllEntities(); - void TeleportToSpawnAllEntities(); + void NeedsToSpawnAllEntities(); + + void ActivateEnemies(); bool LoadState(pugi::xml_node& data); bool SaveState(pugi::xml_node& data); - void ActivateEnemies(); - public: List entities; diff --git a/Game/Source/Item.cpp b/Game/Source/Item.cpp deleted file mode 100644 index fdaacf0..0000000 --- a/Game/Source/Item.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "Item.h" -#include "App.h" -#include "Textures.h" -#include "Audio.h" -#include "Input.h" -#include "Render.h" -#include "Scene_Level1.h" -#include "Log.h" -#include "Point.h" -#include "Physics.h" - -Item::Item() : Entity(EntityType::ITEM) -{ - name.Create("item"); -} - -Item::~Item() -{ - -} - -bool Item::Awake() { - - position.x = parameters.attribute("x").as_int(); - position.y = parameters.attribute("y").as_int(); - texturePath = parameters.attribute("texturepath").as_string(); - pickUpFx = app->audio->LoadFx("Assets/Audio/Fx/hurt.wav"); - return true; -} - -bool Item::Start() { - - //initilize textures - texture = app->tex->Load(texturePath); - pbody = app->physics->CreateCircle(position.x, position.y, 10, STATIC); - pbody->listener = this; - pbody->ctype = ColliderType::ITEM; - return true; -} - -bool Item::Update() -{ - position.x = METERS_TO_PIXELS(pbody->body->GetTransform().p.x - (32 / 2)); - position.y = METERS_TO_PIXELS(pbody->body->GetTransform().p.y - (32 / 2)); - app->render->DrawTexture(texture, position.x, position.y); - for (b2Contact* contact = app->physics->world->GetContactList(); contact; contact = contact->GetNext()) { - if (contact->GetFixtureB()->GetUserData() != NULL) - { - //app->font->BlitText(20, 20, 0, "TOUCHING"); - this->pbody->body->SetLinearVelocity(b2Vec2(pbody->body->GetLinearVelocity().x, -5.0f)); - } - } - return true; -} - -bool Item::CleanUp() -{ - app->tex->UnLoad(texture); - - delete pbody; - pbody = nullptr; - - return true; -} - -void Item::OnCollision(PhysBody* physA, PhysBody* physB) -{ - -} - -void Item::DeathAnimation() -{ - app->audio->PlayFx(pickUpFx); -} \ No newline at end of file diff --git a/Game/Source/Item.h b/Game/Source/Item.h deleted file mode 100644 index f454e9a..0000000 --- a/Game/Source/Item.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __ITEM_H__ -#define __ITEM_H__ - -#include "Entity.h" -#include "Point.h" -#include "SDL/include/SDL.h" - -struct SDL_Texture; - -class Item : public Entity -{ -public: - - Item(); - virtual ~Item(); - - bool Awake(); - - bool Start(); - - bool Update(); - - bool CleanUp(); - - void OnCollision(PhysBody* physA, PhysBody* physB); - - void DeathAnimation(); - -public: - - bool isPicked = false; - -private: - - int pickUpFx; - SDL_Texture* texture; - const char* texturePath; - PhysBody* pbody; - -}; - -#endif // __ITEM_H__ \ No newline at end of file diff --git a/Game/Source/Map.cpp b/Game/Source/Map.cpp index e0c6f07..182827b 100644 --- a/Game/Source/Map.cpp +++ b/Game/Source/Map.cpp @@ -125,9 +125,7 @@ void Map::Draw() } } } - mapLayerItem = mapLayerItem->next; - } } @@ -190,10 +188,8 @@ TileSet* Map::GetTilesetFromTileId(int gid) const while (item != NULL) { set = item->data; - if (gid < item->data->firstgid + item->data->tilecount) - { - break; - } + if (gid < item->data->firstgid + item->data->tilecount) break; + item = item->next; } @@ -242,25 +238,15 @@ bool Map::Load() ret = false; } - if(ret == true) - { - ret = LoadMap(mapFileXML); - } - - if (ret == true) - { - ret = LoadTileSet(mapFileXML); - } + if(ret == true) ret = LoadMap(mapFileXML); + - if (ret == true) - { - ret = LoadAllLayers(mapFileXML.child("map")); - } + if (ret == true) ret = LoadTileSet(mapFileXML); - if (ret == true) - { - ret = LoadColliders(mapFileXML.child("map")); - } + if (ret == true) ret = LoadAllLayers(mapFileXML.child("map")); + + if (ret == true) ret = LoadColliders(mapFileXML.child("map")); + if(ret == true) { @@ -274,7 +260,8 @@ bool Map::Load() ListItem* tileset; tileset = mapData.tilesets.start; - while (tileset != NULL) { + while (tileset != NULL) + { LOG("name : %s firstgid : %d",tileset->data->name.GetString(), tileset->data->firstgid); LOG("tile width : %d tile height : %d", tileset->data->tileWidth, tileset->data->tileHeight); LOG("spacing : %d margin : %d", tileset->data->spacing, tileset->data->margin); @@ -284,7 +271,8 @@ bool Map::Load() ListItem* mapLayer; mapLayer = mapData.maplayers.start; - while (mapLayer != NULL) { + while (mapLayer != NULL) + { LOG("id : %d name : %s", mapLayer->data->id, mapLayer->data->name.GetString()); LOG("Layer width : %d Layer height : %d", mapLayer->data->width, mapLayer->data->height); mapLayer = mapLayer->next; @@ -310,7 +298,7 @@ bool Map::LoadMap(pugi::xml_node mapFile) } else { - //Load map general properties + // Load map general properties mapData.height = map.attribute("height").as_int(); mapData.width = map.attribute("width").as_int(); mapData.tileHeight = map.attribute("tileheight").as_int(); @@ -322,6 +310,7 @@ bool Map::LoadMap(pugi::xml_node mapFile) { mapData.type = MAPTYPE_ISOMETRIC; } + if ((SString)map.attribute("orientation").as_string() == "orthogonal") { mapData.type = MAPTYPE_ORTHOGONAL; @@ -515,7 +504,8 @@ Properties::Property* Properties::GetProperty(const char* name) while (item) { - if (item->data->name == name) { + if (item->data->name == name) + { p = item->data; break; } diff --git a/Game/Source/Map.h b/Game/Source/Map.h index de5bc50..9c0c4b7 100644 --- a/Game/Source/Map.h +++ b/Game/Source/Map.h @@ -133,4 +133,4 @@ class Map : public Module bool mapLoaded; }; -#endif // __MAP_H__ \ No newline at end of file +#endif // __MAP_H__ diff --git a/Game/Source/Player.cpp b/Game/Source/Player.cpp index 4db85f1..1ce83e8 100644 --- a/Game/Source/Player.cpp +++ b/Game/Source/Player.cpp @@ -761,7 +761,7 @@ bool Player::Update() if (isDead) { dashAvailable = true; app->entityManager->ReviveAllEntities(); - app->entityManager->TeleportToSpawnAllEntities(); + app->entityManager->NeedsToSpawnAllEntities(); app->entityManager->ActivateEnemies(); app->audio->PlayFx(dieFx); app->entityManager->Disable(); diff --git a/Game/Source/Scene_Die.cpp b/Game/Source/Scene_Die.cpp index 264112a..be3601b 100644 --- a/Game/Source/Scene_Die.cpp +++ b/Game/Source/Scene_Die.cpp @@ -52,11 +52,13 @@ bool Scene_Die::Awake(pugi::xml_node& config) // Called before the first frame bool Scene_Die::Start() { + active = false; + background = app->tex->Load(background_texturePath); selector = app->tex->Load(selector_texturePath); pointer = app->tex->Load(pointer_texturePath); + choice = 0; - active = false; return true; } @@ -74,10 +76,12 @@ bool Scene_Die::Update(float dt) if (app->input->GetKey(SDL_SCANCODE_DOWN) == KEY_DOWN && !hasSelected) { - if (choice == 2) { + if (choice == 2) + { choice = 0; } - else { + else + { choice++; } } diff --git a/Game/Source/Scene_Die.h b/Game/Source/Scene_Die.h index 4f6ab5d..a2bf2f7 100644 --- a/Game/Source/Scene_Die.h +++ b/Game/Source/Scene_Die.h @@ -37,6 +37,7 @@ class Scene_Die : public Module private: + iPoint oldposition; SDL_Texture* background; diff --git a/Game/Source/Scene_Intro.cpp b/Game/Source/Scene_Intro.cpp index da41c43..13bf3f1 100644 --- a/Game/Source/Scene_Intro.cpp +++ b/Game/Source/Scene_Intro.cpp @@ -38,7 +38,6 @@ bool Scene_Intro::Start() { background = app->tex->Load(background_texturePath); start = high_resolution_clock::now(); - //SDL_ShowCursor(SDL_DISABLE); return true; } diff --git a/Game/Source/Scene_Level1.cpp b/Game/Source/Scene_Level1.cpp index 7743113..41db89c 100644 --- a/Game/Source/Scene_Level1.cpp +++ b/Game/Source/Scene_Level1.cpp @@ -77,7 +77,8 @@ bool Scene_Level1::Start() bool retLoad = app->map->Load(); // Create walkability map - if (retLoad) { + if (retLoad) + { int w, h; uchar* data = NULL; @@ -142,7 +143,7 @@ bool Scene_Level1::PostUpdate() if (app->input->GetKey(SDL_SCANCODE_ESCAPE) == KEY_DOWN) { app->entityManager->ReviveAllEntities(); - app->entityManager->TeleportToSpawnAllEntities(); + app->entityManager->NeedsToSpawnAllEntities(); player->ResetGame(); app->ftb->SceneFadeToBlack(this, app->scene_menu, 20.0f); } diff --git a/Game/Source/Scene_Level1.h b/Game/Source/Scene_Level1.h index 8812751..a335924 100644 --- a/Game/Source/Scene_Level1.h +++ b/Game/Source/Scene_Level1.h @@ -3,7 +3,6 @@ #include "Module.h" #include "Player.h" -#include "Item.h" #include "Enemy_Fly.h" #include "Enemy_Walk.h" #include "Animation.h" @@ -38,6 +37,7 @@ class Scene_Level1 : public Module bool CleanUp(); bool LoadState(pugi::xml_node& data); + bool SaveState(pugi::xml_node& data); public: diff --git a/Game/Source/Scene_Menu.cpp b/Game/Source/Scene_Menu.cpp index 1b349c4..dc96b3a 100644 --- a/Game/Source/Scene_Menu.cpp +++ b/Game/Source/Scene_Menu.cpp @@ -31,7 +31,7 @@ Scene_Menu::~Scene_Menu() bool Scene_Menu::Awake(pugi::xml_node& config) { LOG("Loading Scene_Menu"); - + bool ret = true; for (pugi::xml_node node = config.child("pointer").child("pushback"); node; node = node.next_sibling("pushback")) { @@ -49,9 +49,6 @@ bool Scene_Menu::Awake(pugi::xml_node& config) background_texturePath = config.child("background").attribute("texturepath").as_string(); selector_texturePath = config.child("selector").attribute("texturepath").as_string(); pointer_texturePath = config.child("pointer").attribute("texturepath").as_string(); - bool ret = true; - - return ret; } @@ -59,15 +56,15 @@ bool Scene_Menu::Awake(pugi::xml_node& config) // Called before the first frame bool Scene_Menu::Start() { + active = false; background = app->tex->Load(background_texturePath); pointer = app->tex->Load(pointer_texturePath); selector = app->tex->Load(selector_texturePath); choice = 0; - //SDL_ShowCursor(SDL_DISABLE); + app->audio->PlayMusic("Assets/Audio/Music/bgm.ogg"); - app->win->SetTitle("Super Metal Boy"); - this->active = false; + return true; } @@ -80,7 +77,6 @@ bool Scene_Menu::PreUpdate() // Called each loop iteration bool Scene_Menu::Update(float dt) { - if (app->scene->player->level != 1) app->scene->player->level = 1; if (app->entityManager->IsEnabled()) app->entityManager->Disable(); @@ -89,7 +85,6 @@ bool Scene_Menu::Update(float dt) if (app->scene_die->IsEnabled()) app->scene_die->Disable(); - if (app->input->GetKey(SDL_SCANCODE_DOWN) == KEY_DOWN && !hasSelected) { if (choice == 1) { diff --git a/Game/Source/Scene_Menu.h b/Game/Source/Scene_Menu.h index 8c60912..652b435 100644 --- a/Game/Source/Scene_Menu.h +++ b/Game/Source/Scene_Menu.h @@ -34,6 +34,7 @@ class Scene_Menu : public Module bool CleanUp(); public: + bool hasSelected = false; private: diff --git a/Game/Source/Scene_Win.cpp b/Game/Source/Scene_Win.cpp index 1ae2a0a..e853a27 100644 --- a/Game/Source/Scene_Win.cpp +++ b/Game/Source/Scene_Win.cpp @@ -23,7 +23,10 @@ Scene_Win::Scene_Win() : Module() } // Destructor -Scene_Win::~Scene_Win() {} +Scene_Win::~Scene_Win() +{ + +} // Called before render is available bool Scene_Win::Awake(pugi::xml_node& config) @@ -52,7 +55,8 @@ bool Scene_Win::PreUpdate() // Called each loop iteration bool Scene_Win::Update(float dt) { - if (app->entityManager->IsEnabled()) { + if (app->entityManager->IsEnabled()) + { app->entityManager->Disable(); start = high_resolution_clock::now(); diff --git a/Output/save_game.xml b/Output/save_game.xml index 7d9cfc1..c04891b 100644 --- a/Output/save_game.xml +++ b/Output/save_game.xml @@ -10,17 +10,17 @@ - + - + - +