package main import rl "vendor:raylib" import "vendor:raylib/rlgl" import "core:fmt" // Virtual game field dimensions GameField := Vec2{800, 600} Pad :: struct { position: Vec2, size: Vec2, } Ball :: struct { position: Vec2, velocity: Vec2, radius: f32, } Brick :: struct { position: Vec2, size: Vec2, color: rl.Color, hits: u8, } Game :: struct { using state: GameState, lives: u8, pad: Pad, balls: [dynamic]Ball, bricks: [dynamic]Brick, camera: rl.Camera2D } game_init :: proc() -> ^GameState { state := new(Game) state.variant = state state.draw = game_draw state.update = game_update state.lives = 3 state.camera = rl.Camera2D{ zoom = 1, target = GameField / 2, } state.pad = Pad{ position = Vec2{GameField.x / 2, GameField.y - 40}, size = {80, 10}, } return state } game_update :: proc(state: ^GameState, delta: f32) { game := transmute(^Game)state using game if rl.IsKeyDown(rl.KeyboardKey.LEFT) { pad.position.x -= 100 * delta fmt.println(pad.position) } if rl.IsKeyDown(rl.KeyboardKey.RIGHT) { pad.position.x += 100 * delta } game.camera.offset = WINDOWF / 2 } game_draw :: proc(state: ^GameState) { game := transmute(^Game)state using game rl.BeginMode2D(camera) rl.ClearBackground(rl.RAYWHITE) rl.DrawRectangleV({0, 0}, GameField, rl.RED) rl.DrawRectangleV(pad.position, pad.size, rl.GREEN) rl.EndMode2D() }