Moved and renamed entities.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user