summaryrefslogtreecommitdiff
path: root/in_practice/breakout/ball.c
diff options
context:
space:
mode:
authorpryazha <pryadeiniv@mail.ru>2025-08-16 10:11:00 +0500
committerpryazha <pryadeiniv@mail.ru>2025-08-16 10:11:00 +0500
commit1f93c3ef62af6c71217f06491ca2b859d4065740 (patch)
tree4f07192788df29446aa1ddb73a20839e4ddf9b3f /in_practice/breakout/ball.c
parent99337878eca2807436bcf11d36946b90db44a2d3 (diff)
in practice chapter
Diffstat (limited to 'in_practice/breakout/ball.c')
-rw-r--r--in_practice/breakout/ball.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/in_practice/breakout/ball.c b/in_practice/breakout/ball.c
new file mode 100644
index 0000000..9aa42a2
--- /dev/null
+++ b/in_practice/breakout/ball.c
@@ -0,0 +1,24 @@
+#include "ball.h"
+
+void move_ball(ball_t *ball, f32 dt, i32 width)
+{
+ if (ball->stuck)
+ return;
+ ball->o.pos = add_v2(ball->o.pos, scale_v2(ball->o.vel, dt));
+ if (ball->o.pos.x < 0.0f) {
+ ball->o.vel.x = -ball->o.vel.x;
+ ball->o.pos.x = 0.0f;
+ }
+ if (ball->o.pos.x + ball->o.size.x > width) {
+ ball->o.vel.x = -ball->o.vel.x;
+ ball->o.pos.x = width - ball->o.size.x;
+ }
+ if (ball->o.pos.y < 0.0f) {
+ ball->o.vel.y = -ball->o.vel.y;
+ ball->o.pos.y = 0.0f;
+ }
+}
+
+void reset_ball(ball_t *ball, v2 pos, v2 vel)
+{
+}