Skip to content

Commit

Permalink
Cleaned code. Done the following:
Browse files Browse the repository at this point in the history
- Removed unnecessary Item.cpp / .h
- Deactivate all DEBUG features when disabling it.
  • Loading branch information
xGauss05 committed Dec 18, 2022
1 parent 679b705 commit 168291d
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 310 deletions.
2 changes: 0 additions & 2 deletions Game/Game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<ClCompile Include="Source\EntityManager.cpp" />
<ClCompile Include="Source\FadeToBlack.cpp" />
<ClCompile Include="Source\Fonts.cpp" />
<ClCompile Include="Source\Item.cpp" />
<ClCompile Include="Source\Main.cpp" />
<ClCompile Include="Source\App.cpp" />
<ClCompile Include="Source\Audio.cpp" />
Expand All @@ -130,7 +129,6 @@
<ClInclude Include="Source\EntityManager.h" />
<ClInclude Include="Source\FadeToBlack.h" />
<ClInclude Include="Source\Fonts.h" />
<ClInclude Include="Source\Item.h" />
<ClInclude Include="Source\Map.h" />
<ClInclude Include="Source\Pathfinding.h" />
<ClInclude Include="Source\Physics.h" />
Expand Down
6 changes: 0 additions & 6 deletions Game/Game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<ClCompile Include="Source\EntityManager.cpp">
<Filter>Application\Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Item.cpp">
<Filter>Application\Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Scene_Level1.cpp">
<Filter>Modules\Gameplay\Scenes</Filter>
</ClCompile>
Expand Down Expand Up @@ -120,9 +117,6 @@
<ClInclude Include="Source\Entity.h">
<Filter>Application\Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Item.h">
<Filter>Application\Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Scene_Level1.h">
<Filter>Modules\Gameplay\Scenes</Filter>
</ClInclude>
Expand Down
24 changes: 10 additions & 14 deletions Game/Source/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ bool App::Start()
item = modules.start;

while (item != NULL && ret == true)

{
ret = item->data->Start();
item = item->next;
Expand Down Expand Up @@ -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());
}

Expand All @@ -175,6 +176,7 @@ bool App::LoadConfig()
// ---------------------------------------------
void App::PrepareUpdate()
{

}

// ---------------------------------------------
Expand All @@ -196,10 +198,8 @@ bool App::PreUpdate()
{
pModule = item->data;

if (pModule->active == false) {
continue;
}

if (pModule->active == false) continue;

ret = item->data->PreUpdate();
}

Expand All @@ -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);
}
Expand All @@ -239,10 +237,8 @@ bool App::PostUpdate()
{
pModule = item->data;

if (pModule->active == false) {
continue;
}

if (pModule->active == false) continue;

ret = item->data->PostUpdate();
}

Expand Down
54 changes: 45 additions & 9 deletions Game/Source/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
39 changes: 18 additions & 21 deletions Game/Source/Enemy_Fly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,38 @@ bool Enemy_Fly::Awake() {
spawn.y = position.y;
texturePath = parameters.attribute("texturepath").as_string();
level = parameters.attribute("level").as_int();

InitAnims();
return true;

}

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);
Expand All @@ -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));
Expand All @@ -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)
Expand All @@ -113,7 +119,7 @@ bool Enemy_Fly::Update()
}
}

//Movement
// Movement
if (pathToPlayer.Count() > 1)
{
int dirX = pathToPlayer.At(1)->x - pathToPlayer.At(0)->x;
Expand All @@ -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)
{
Expand All @@ -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);
}

Expand All @@ -151,34 +154,28 @@ 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)
{
if (pbody->body->GetLinearVelocity().y > -speedCap)
{
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();
}
Expand Down Expand Up @@ -216,4 +213,4 @@ void Enemy_Fly::OnCollision(PhysBody* physA, PhysBody* physB)
void Enemy_Fly::DeathAnimation()
{

}
}
1 change: 0 additions & 1 deletion Game/Source/Enemy_Fly.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Enemy_Fly : public Entity

DynArray<iPoint> pathToPlayer;

bool pendingToDelete = false;
};

#endif // ___ENEMY_FLY_H__
Loading

0 comments on commit 168291d

Please sign in to comment.