From 08e593a2c075f2cf2bd462bd5884070514678407 Mon Sep 17 00:00:00 2001 From: FelipeFTN Date: Tue, 11 Jul 2023 15:01:13 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20completed=20wall=20control?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 5 ++++- src/map/map.cpp | 30 +++++++++++++++++++++++++----- src/map/map.h | 6 +++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b34e41f..abd47d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ int main() { InitWindow(screenWidth, screenHeight, "Game"); Map map{}; + int wallTime = 0; bool show_wall_0 = true; bool show_wall_1 = false; Rectangle wall_0{-84, 111, 100, screenHeight / 1.8f}; @@ -23,12 +24,14 @@ int main() { while (!WindowShouldClose()) { + map.WallControl(&wallTime, &show_wall_0, &show_wall_1); + ball_0.Collision(&ball_1, show_wall_0, show_wall_1); ball_1.Collision(&ball_0, show_wall_0, show_wall_1); BeginDrawing(); - map.DrawMap(); + map.DrawMap(screenWidth, screenHeight); map.Wall(&wall_0, show_wall_0); map.Wall(&wall_1, show_wall_1); diff --git a/src/map/map.cpp b/src/map/map.cpp index 27ce33c..867280d 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -4,21 +4,41 @@ Map::Map() { } -void Map::DrawMap() { +void Map::DrawMap(int screenWidth, int screenHeight) { + sw = screenWidth; + sh = screenHeight; DrawTextureEx(background, (Vector2){ 0.0f, 0.0f }, 0.0f, 8.0f, WHITE); } +void Map::WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1) { + *wallTime += 1; + if (*wallTime == 600) { + *show_wall_0 = *show_wall_0 ? false : true; + *show_wall_1 = *show_wall_1 ? false : true; + *wallTime = 0; + } +} + void Map::Wall(Rectangle *wall, bool active) { - if (!active) { Map::HideWall(wall); } + if (wall->x < sw / 2.f) { wall_index = 0; } else { wall_index = 1; } + if (!active) { Map::HideWall(wall); } else { Map::ShowWall(wall); } DrawRectangleRec(*wall, DARKGRAY); } void Map::HideWall(Rectangle *wall) { - if (wall->x < background.width / 2.f) { wall_index = 0; } else { wall_index = 1; } - + // sw = Screen Width if (wall_index == 0 && wall->x > -100.f) { wall->x += -.1; - } else if (wall_index == 1 && wall->x > background.width) { + } else if (wall_index == 1 && wall->x < sw) { wall->x += .1; } } + +void Map::ShowWall(Rectangle *wall) { + // sw = Screen Width + if (wall_index == 0 && wall->x <= -84.f) { + wall->x += .1; + } else if (wall_index == 1 && wall->x > sw - 16) { + wall->x += -.1; + } +} diff --git a/src/map/map.h b/src/map/map.h index 1fba101..04d0688 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -5,11 +5,15 @@ class Map { Map(); public: - void DrawMap(); + void DrawMap(int screenWidth, int screenHeight); void Wall(Rectangle *wall, bool active); + void WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1); void HideWall(Rectangle *wall); + void ShowWall(Rectangle *wall); private: Texture2D background = LoadTexture("assets/map.png"); int wall_index; + int sw; + int sh; };