Files use .rex, the command is rex, and the crate, runtime prefixes, docs, editor files and examples all use the new name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.6 KiB
Rexx
53 lines
1.6 KiB
Rexx
// A ball bouncing around a window, drawn with raylib (https://www.raylib.com).
|
|
// Needs raylib installed: `rex run bounce.rex`. Space adds a ball, Escape quits.
|
|
|
|
import "raylib.h"
|
|
|
|
const WIDTH = 800
|
|
const HEIGHT = 450
|
|
|
|
struct Ball {
|
|
pos: raylib.Vector2
|
|
speed: raylib.Vector2
|
|
radius: f32
|
|
color: raylib.Color
|
|
|
|
func step(dt: f32) {
|
|
pos.x += speed.x * dt
|
|
pos.y += speed.y * dt
|
|
if pos.x < radius || pos.x > f32(WIDTH) - radius { speed.x = -speed.x }
|
|
if pos.y < radius || pos.y > f32(HEIGHT) - radius { speed.y = -speed.y }
|
|
}
|
|
}
|
|
|
|
func new_ball(n: int): Ball {
|
|
var colors = [raylib.RED, raylib.GOLD, raylib.SKYBLUE, raylib.LIME, raylib.VIOLET]
|
|
var x = f32(100 + n * 37 % 600)
|
|
var y = f32(80 + n * 53 % 290)
|
|
return Ball{raylib.Vector2{x, y}, raylib.Vector2{f32(180 + n * 20), 140.0}, 20.0, colors[n % colors.len()]}
|
|
}
|
|
|
|
func main() {
|
|
raylib.InitWindow(WIDTH, HEIGHT, "Rex + raylib")
|
|
raylib.SetTargetFPS(60)
|
|
var balls = [new_ball(0)]
|
|
for !raylib.WindowShouldClose() {
|
|
if raylib.IsKeyPressed(raylib.KEY_SPACE) {
|
|
balls.push(new_ball(balls.len()))
|
|
}
|
|
var dt = raylib.GetFrameTime()
|
|
for i in 0..balls.len() {
|
|
balls[i].step(dt)
|
|
}
|
|
|
|
raylib.BeginDrawing()
|
|
raylib.ClearBackground(raylib.RAYWHITE)
|
|
for b in balls {
|
|
raylib.DrawCircleV(b.pos, b.radius, b.color)
|
|
}
|
|
raylib.DrawText("balls: {balls.len()} (space adds one)", 10, 10, 20, raylib.DARKGRAY)
|
|
raylib.EndDrawing()
|
|
}
|
|
raylib.CloseWindow()
|
|
}
|