Skip to content

Commit

Permalink
🚀 completed wall control
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN committed Jul 11, 2023
1 parent 77e0cde commit 08e593a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);

Expand Down
30 changes: 25 additions & 5 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion src/map/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 08e593a

Please sign in to comment.