Skip to content

Commit 6407666

Browse files
authored
Merge pull request #5 from cpp-gamedev/shape
improved blinking
2 parents 8b57ed0 + d217604 commit 6407666

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/gfx/follow_eye.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
namespace misc {
77
sf::Vector2f follow_eye_t::update(sf::Vector2f target) noexcept { return (dir = maths::normalize(target - pos)); }
88
void follow_eye_t::draw(drawer_t& drawer, bool blink) {
9-
shape_t<sf::CircleShape> circle(drawer);
10-
circle.radius = 40.0f * scale;
11-
circle.outline = {sf::Color(0x221100ff), 2.0f};
12-
circle.position = pos;
13-
circle.draw();
9+
shape_t<sf::CircleShape> eye(drawer);
10+
eye.radius = 40.f * scale;
11+
eye.position = pos;
1412
if (!blink) {
15-
auto const radius = circle.radius * 0.25f;
16-
auto const offset = dir * (circle.radius - radius) * 0.80f; // 20% padding
17-
circle.radius = radius;
18-
circle.fill = sf::Color::Black;
19-
circle.outline.size = 0.0f;
20-
circle.position += offset;
21-
circle.draw();
13+
eye.outline = {sf::Color(0x221100ff), 2.0f};
14+
eye.draw();
15+
// pupil
16+
auto const offset = dir * (eye.radius * 0.75f) * 0.80f; // 20% padding
17+
eye.radius *= 0.3f;
18+
eye.fill = sf::Color::Black;
19+
eye.outline = {sf::Color(0x221100ff), 0.5f};
20+
eye.position += offset;
21+
eye.draw();
22+
} else {
23+
eye.scale = {1.0f, 0.1f};
24+
eye.fill = sf::Color::Black;
25+
eye.draw();
2226
}
2327
}
2428
} // namespace misc

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class clock_ticker_t {
8181

8282
struct {
8383
pair_t<sec_t> interval = {sec_t{3.0f}, sec_t{8.0f}};
84-
sec_t duration = sec_t{0.15f};
84+
sec_t duration = sec_t{0.1f};
8585

8686
sec_t next_blink_in{};
8787
sec_t stop_blink_in{};

0 commit comments

Comments
 (0)