-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderUtils.cpp
99 lines (85 loc) · 2.53 KB
/
RenderUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "pch.h"
#include "include/RenderUtils.h"
#include "include/GameState.h"
#include "include/Constants.h"
void RefreshView(sf::RenderWindow &window, sf::View &view)
{
window.clear(sf::Color(31, 31, 31));
window.setView(view);
}
void DrawMazeEnvironment(sf::RenderWindow &window, std::optional<sf::Color> colour)
{
bool setWallColour = colour.has_value();
for (auto &wall : GameState::walls)
{
if (setWallColour &&
wall.type == CellType::WALL)
{
wall.shape.setOutlineColor(colour.value());
}
window.draw(wall.shape);
}
for (auto &pu : GameState::pickUps)
{
if (pu.show)
{
window.draw(pu.shape);
}
}
for (auto &frt : GameState::fruits)
{
frt.Draw(window);
}
}
void DrawFooterGameStatuses(sf::RenderWindow &window, int lives)
{
float xOffset = 6.0f;
for (int i = 0; i < lives - 1; ++i)
{
sf::Sprite life = GameState::pacmanLives[i];
life.setPosition(xOffset + float(i), Constants::GRID_HEIGHT - 0.75f);
window.draw(life);
}
for (auto &fruit : GameState::fruits)
{
fruit.DrawStatusIcon(window);
}
}
void DrawGhosts(sf::RenderWindow &window, std::optional<GhostPersonality> skipGhostPersonality)
{
for (auto &gst : GameState::ghosts)
{
if (!skipGhostPersonality.has_value() ||
gst.GetPersonality() != skipGhostPersonality.value())
{
gst.Draw(window);
}
}
}
void FlashWalls(sf::RenderWindow &window, sf::View &view, TextManager &textManager)
{
float duration = 2.5f;
float interval = 0.25f;
float startTime = GameState::gameClock.getElapsedTime().asSeconds();
while (GameState::gameClock.getElapsedTime().asSeconds() - startTime < duration)
{
float elapsed = GameState::gameClock.getElapsedTime().asSeconds() - startTime;
sf::Color colour = (static_cast<int>(elapsed / interval) % 2 == 0)
? sf::Color::White
: Constants::WALL_COLOUR;
RefreshView(window, view);
DrawMazeEnvironment(window, colour);
DrawFooterGameStatuses(window, GameState::lives);
textManager.Draw(window, GameState::gameStatus, GameState::gameClock.getElapsedTime().asSeconds());
window.display();
sf::sleep(sf::milliseconds(50));
}
}
void HideFruits(TextManager &textManager)
{
textManager.ForceClearFruitPoints();
for (auto &frt : GameState::fruits)
{
frt.Hide();
}
}