diff --git a/Faceball2030/Editor.cpp b/Faceball2030/Editor.cpp index 9575482..f044a1d 100644 --- a/Faceball2030/Editor.cpp +++ b/Faceball2030/Editor.cpp @@ -6,11 +6,63 @@ using namespace olc; extern FaceBall* game; void Editor::Update(float fElapsedTime){ - vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth()/2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight()/2 }; + MouseWheelEnemySelection(); + RenderLevel(); + WaveLayerSelection(); + game->DrawStringDecal({ 2,16 }, "Selected Enemy ("+std::to_string(selectedEnemy) + "): " + game->GetData(selectedEnemy).name, WHITE, {3,3}); + game->DrawStringDecal({ 2,(float)game->ScreenHeight() - 50 }, "Layer " + std::to_string(waveLayer), WHITE, { 5,5 }); + LoadLevelHandling(); +} + +void Editor::LoadLevelHandling() { + if (!game->IsTextEntryEnabled()) { + if (promptState == PromptState::NONE) { + if (game->GetKey(F1).bPressed) { + promptState = PromptState::ENTER_LEVEL; + game->TextEntryEnable(true); + } + if (game->GetKey(F2).bPressed) { + promptState = PromptState::ENTER_WIDTH; + game->TextEntryEnable(true,std::to_string(MAP_SIZE.x)); + } + } + if (reEnableTextEntry) { + switch (promptState) { + case PromptState::ENTER_LEVEL: { + game->TextEntryEnable(true); + }break; + case PromptState::ENTER_WIDTH: { + game->TextEntryEnable(true, std::to_string(MAP_SIZE.y)); + }break; + case PromptState::ENTER_HEIGHT: { + game->TextEntryEnable(true,std::to_string(MAP_SIZE.y)); + }break; + } + reEnableTextEntry = false; + } + } + else { + game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK); + switch (promptState) { + case PromptState::ENTER_LEVEL: { + game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + case PromptState::ENTER_WIDTH: { + game->DrawStringDecal({ 0,0 }, "Enter Level Width: " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + case PromptState::ENTER_HEIGHT: { + game->DrawStringDecal({ 0,0 }, "Enter Level Height: " + game->TextEntryGetString(), WHITE, { 4,4 }); + }break; + } + } +} + +void Editor::MouseWheelEnemySelection() +{ if (game->GetMouseWheel() != 0) { if (game->GetMouseWheel() > 0) { if (selectedEnemy < 63) { - selectedEnemy=EnemyID(selectedEnemy+1); + selectedEnemy = EnemyID(selectedEnemy + 1); } else { selectedEnemy = EnemyID::NONE; @@ -25,9 +77,14 @@ void Editor::Update(float fElapsedTime){ } } } +} + +void Editor::RenderLevel() +{ + vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth() / 2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight() / 2 }; for (int y = 0; y < MAP_SIZE.y; y++) { for (int x = 0; x < MAP_SIZE.x; x++) { - Tile&t = map[y][x]; + Tile& t = map[y][x]; vf2d squarePos = vf2d{ (float)x,(float)y }*GRID_SIZE + center; if (game->GetMouseX() >= squarePos.x && game->GetMouseX() <= squarePos.x + GRID_SIZE.x && game->GetMouseY() >= squarePos.y && game->GetMouseY() <= squarePos.y + GRID_SIZE.y) { @@ -40,30 +97,57 @@ void Editor::Update(float fElapsedTime){ } if (game->GetKey(D).bPressed) { t.wallE = !t.wallE; - if (x < MAP_SIZE.x-1) { - Tile& neighbor = map[y][x+1]; + if (x < MAP_SIZE.x - 1) { + Tile& neighbor = map[y][x + 1]; neighbor.wallW = t.wallE; } } if (game->GetKey(S).bPressed) { t.wallS = !t.wallS; if (y < MAP_SIZE.y - 1) { - Tile& neighbor = map[y+1][x]; + Tile& neighbor = map[y + 1][x]; neighbor.wallN = t.wallS; } } if (game->GetKey(A).bPressed) { t.wallW = !t.wallW; if (x > 0) { - Tile& neighbor = map[y][x-1]; + Tile& neighbor = map[y][x - 1]; neighbor.wallE = t.wallW; } } if (game->GetMouse(0).bPressed) { t.enemyId = selectedEnemy; + switch (waveLayer) { + case 0: { + t.wave1 = true; + }break; + case 1: { + t.wave2 = true; + }break; + case 2: { + t.wave3 = true; + }break; + } + if (t.enemyId == EnemyID::NONE) { + t.wave1 = t.wave2 = t.wave3 = false; + } } if (game->GetMouse(1).bPressed) { - t.enemyId = EnemyID::NONE; + switch (waveLayer) { + case 0: { + t.wave1 = false; + }break; + case 1: { + t.wave2 = false; + }break; + case 2: { + t.wave3 = false; + }break; + } + if (!(t.wave1 || t.wave2 || t.wave3)) { + t.enemyId = EnemyID::NONE; + } } if (game->GetKey(DOWN).bHeld) { t.facingDir = FacingDirection::SOUTH; @@ -83,69 +167,48 @@ void Editor::Update(float fElapsedTime){ if (t.enemyId != EnemyID::NONE) { if (t.enemyId >= COIN) { game->DrawPolygonDecal(nullptr, { - vf2d{0,(float) GRID_SIZE.y / 2} + squarePos , + vf2d{0,(float)GRID_SIZE.y / 2} + squarePos , vf2d{(float)GRID_SIZE.x / 2,0} + squarePos , vf2d{(float)GRID_SIZE.x,(float)GRID_SIZE.y / 2} + squarePos , vf2d{(float)GRID_SIZE.x / 2,(float)GRID_SIZE.y} + squarePos , }, { {0,0},{0,0} ,{0,0} ,{0,0} }, game->GetData(t.enemyId).col); } else { - game->DrawDecal(squarePos, game->circle, { 1,1 }, game->GetData(t.enemyId).col); + game->DrawDecal(squarePos, game->circle, { 1,1 }, { + game->GetData(t.enemyId).col.r, + game->GetData(t.enemyId).col.g, + game->GetData(t.enemyId).col.b, + (uint8_t)(waveLayer == 0 && t.wave1||waveLayer==1&&t.wave2||waveLayer==2&&t.wave3 ? 255 : 64) + }); if (t.enemyId >= START) { - game->DrawRotatedDecal(squarePos + vf2d{16, 16}, game->arrow, PI / 2 * (int)t.facingDir, { 16,16 }, { 1,1 }, WHITE); + game->DrawRotatedDecal(squarePos + vf2d{ 16, 16 }, game->arrow, PI / 2 * (int)t.facingDir, { 16,16 }, { 1,1 }, { + WHITE.r, + WHITE.g, + WHITE.b, + (uint8_t)(waveLayer == 0 && t.wave1 || waveLayer == 1 && t.wave2 || waveLayer == 2 && t.wave3 ? 255 : 64) + } + ); } } } - game->DrawLineDecal(squarePos,{squarePos.x+ (float)GRID_SIZE.x,squarePos.y},t.wallN?WHITE:Pixel{64,64,64}); + game->DrawLineDecal(squarePos, { squarePos.x + (float)GRID_SIZE.x,squarePos.y }, t.wallN ? WHITE : Pixel{ 64,64,64 }); game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y }, { squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, t.wallE ? WHITE : Pixel{ 64,64,64 }); game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, { squarePos.x,squarePos.y + (float)GRID_SIZE.y }, t.wallS ? WHITE : Pixel{ 64,64,64 }); game->DrawLineDecal({ squarePos.x,squarePos.y + (float)GRID_SIZE.y }, squarePos, t.wallW ? WHITE : Pixel{ 64,64,64 }); } } - game->DrawStringDecal({ 2,16 }, "Selected Enemy ("+std::to_string(selectedEnemy) + "): " + game->GetData(selectedEnemy).name, WHITE, {3,3}); - LoadLevelHandling(); } -void Editor::LoadLevelHandling() { - if (!game->IsTextEntryEnabled()) { - if (promptState == PromptState::NONE) { - if (game->GetKey(F1).bPressed) { - promptState = PromptState::ENTER_LEVEL; - game->TextEntryEnable(true); - } - if (game->GetKey(F2).bPressed) { - promptState = PromptState::ENTER_WIDTH; - game->TextEntryEnable(true,std::to_string(MAP_SIZE.x)); - } - } - if (reEnableTextEntry) { - switch (promptState) { - case PromptState::ENTER_LEVEL: { - game->TextEntryEnable(true); - }break; - case PromptState::ENTER_WIDTH: { - game->TextEntryEnable(true, std::to_string(MAP_SIZE.y)); - }break; - case PromptState::ENTER_HEIGHT: { - game->TextEntryEnable(true,std::to_string(MAP_SIZE.y)); - }break; - } - reEnableTextEntry = false; - } +void Editor::WaveLayerSelection() +{ + if (game->GetKey(K1).bPressed) { + waveLayer = 0; } - else { - game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK); - switch (promptState) { - case PromptState::ENTER_LEVEL: { - game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 }); - }break; - case PromptState::ENTER_WIDTH: { - game->DrawStringDecal({ 0,0 }, "Enter Level Width: " + game->TextEntryGetString(), WHITE, { 4,4 }); - }break; - case PromptState::ENTER_HEIGHT: { - game->DrawStringDecal({ 0,0 }, "Enter Level Height: " + game->TextEntryGetString(), WHITE, { 4,4 }); - }break; - } + if (game->GetKey(K2).bPressed) { + waveLayer = 1; + } + if (game->GetKey(K3).bPressed) { + waveLayer = 2; } } diff --git a/Faceball2030/Editor.h b/Faceball2030/Editor.h index 907dd08..3316e1c 100644 --- a/Faceball2030/Editor.h +++ b/Faceball2030/Editor.h @@ -65,10 +65,14 @@ class Editor { const vi2d GRID_SIZE = { 32,32 }; EnemyID selectedEnemy=SHOOTME; PromptState promptState = PromptState::NONE; + int waveLayer = 0; public: Editor() {} void Update(float fElapsedTime); void OnTextEntryComplete(const std::string& sText); void LoadLevel(); void LoadLevelHandling(); + void MouseWheelEnemySelection(); + void RenderLevel(); + void WaveLayerSelection(); }; \ No newline at end of file