Initial simple event manager.

This commit is contained in:
2026-09-15 05:42:12 +02:00
parent 106f8195e2
commit cb523a3d6f
3 changed files with 36 additions and 3 deletions
+8 -3
View File
@@ -2,7 +2,6 @@ package game
import "core:math/rand"
import rl "vendor:raylib"
import "core:log"
init_ball :: proc() -> Entity {
return Entity{
@@ -57,13 +56,13 @@ update_ball :: proc(ball: ^Entity, level: ^Level, dt: f32) {
if ball.pos.y <= field_bounds.y + ball.size.x { ball.vel.y = -ball.vel.y }
if ball.pos.x >= (field_bounds.x + field_bounds.width) - ball.size.x {
level.score_player += 1
increment_score(&level.score_player, level.score_win, true)
reset_ball(ball)
level.serve_timer = level.wait_time
}
if ball.pos.x <= field_bounds.x + ball.size.x {
level.score_enemy += 1
increment_score(&level.score_enemy, level.score_win, false)
reset_ball(ball)
level.serve_timer = level.wait_time
}
@@ -79,6 +78,12 @@ check_ball_paddle_collision :: proc(ball: Entity, paddle: Entity) -> bool {
return rl.CheckCollisionCircleRec(ball.pos, ball.size.x, paddle_rec)
}
increment_score :: proc(score_side: ^int, max_score: int, player: bool) {
score_side^ += 1
if score_side^ == max_score do emit_event(Event{ .Game_Over, player })
}
render_ball :: proc(ball: Entity, field_bounds: rl.Rectangle) {
rl.DrawCircleV(ball.pos, ball.size.x, rl.MAROON)
}