45 lines
1.0 KiB
Odin
45 lines
1.0 KiB
Odin
package main
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
|
|
|
|
Brick :: struct {
|
|
position: Vec2,
|
|
velocity: Vec2,
|
|
size: Vec2,
|
|
angle: f32,
|
|
angular_velocity: f32,
|
|
is_flying: bool,
|
|
is_fixed: bool,
|
|
color: rl.Color,
|
|
hits: u8,
|
|
is_to_free: bool,
|
|
}
|
|
|
|
spawn_brick :: proc(position: Vec2, size: Vec2, is_fixed: bool = true, color: rl.Color = rl.RED, hits : u8 = 1) -> Brick {
|
|
return Brick {
|
|
position = position,
|
|
velocity = Vec2{},
|
|
size = Vec2{30,20},
|
|
is_flying = false,
|
|
is_fixed = is_fixed,
|
|
color = color,
|
|
hits = hits,
|
|
angle = 0
|
|
}
|
|
}
|
|
|
|
brick_update :: proc(brick: ^Brick, camera: rl.Camera2D, delta: f32) {
|
|
if !brick.is_flying { return }
|
|
brick.velocity.y += 500 * delta
|
|
brick.position += brick.velocity * delta
|
|
brick.angle += brick.angular_velocity * delta
|
|
screen_pos := rl.GetWorldToScreen2D(brick.position, camera)
|
|
if !rl.CheckCollisionRecs(rl.Rectangle{screen_pos.x - brick.size.x / 2, screen_pos.y - brick.size.y / 2, brick.size.x, brick.size.y},
|
|
rl.Rectangle{0, 0, WINDOWF.x, WINDOWF.y}
|
|
) {
|
|
brick.is_to_free = true
|
|
}
|
|
}
|