34 lines
726 B
Odin
34 lines
726 B
Odin
package game
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
init_ball :: proc() -> Entity {
|
|
ball_radius: f32 = 25
|
|
|
|
return Entity{
|
|
type = .Ball,
|
|
active = true,
|
|
pos = rl.Vector2{(VIEWPORT_WIDTH / 2), (VIEWPORT_HEIGHT / 2) - (ball_radius / 2)},
|
|
vel = rl.Vector2{400,0},
|
|
shape = .Circle,
|
|
size = rl.Vector2{15, 15}
|
|
}
|
|
}
|
|
|
|
update_ball :: proc(ball: ^Entity, field_bounds: rl.Rectangle, dt: f32) {
|
|
ball.pos += ball.vel * dt
|
|
|
|
if ball.pos.x >= (field_bounds.x + field_bounds.width) - ball.size.x {
|
|
ball.vel.x = -ball.vel.x
|
|
}
|
|
|
|
if ball.pos.x <= field_bounds.x + ball.size.x {
|
|
ball.vel.x = -ball.vel.x
|
|
}
|
|
|
|
}
|
|
|
|
render_ball :: proc(ball: Entity, field_bounds: rl.Rectangle) {
|
|
rl.DrawCircleV(ball.pos, ball.size.x, rl.MAROON)
|
|
}
|