This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nub-lang-archive-2/examples/raylib/main.nub
nub31 efa12a7e55 ...
2025-10-02 14:18:47 +02:00

56 lines
1.4 KiB
Plaintext

import "core"
import "raylib"
module "main"
extern "main" func main(args: []cstring): i64
{
raylib::SetConfigFlags(raylib::FLAG_VSYNC_HINT | raylib::FLAG_WINDOW_RESIZABLE)
raylib::InitWindow(1600, 900, "Hi from nub-lang")
raylib::SetTargetFPS(240)
let width: i32 = 150
let height: i32 = 150
let x: i32 = raylib::GetScreenWidth() / 2 - (width / 2)
let y: i32 = raylib::GetScreenHeight() / 2 - (height / 2)
let direction: raylib::Vector2 = { x = 1 y = 1 }
let speed: f32 = 250
let bgColor: raylib::Color = { r = 0 g = 0 b = 0 a = 255 }
let color: raylib::Color = { r = 255 g = 255 b = 255 a = 255 }
while !raylib::WindowShouldClose()
{
if x <= 0
{
direction.x = 1
}
else if x + width >= raylib::GetScreenWidth()
{
direction.x = -1
}
else if y <= 0
{
direction.y = 1
}
else if y + height >= raylib::GetScreenHeight()
{
direction.y = -1
}
x = x + @floatToInt(i32, direction.x * speed * raylib::GetFrameTime())
y = y + @floatToInt(i32, direction.y * speed * raylib::GetFrameTime())
raylib::BeginDrawing()
{
raylib::ClearBackground(bgColor)
raylib::DrawFPS(10, 10)
raylib::DrawRectangle(x, y, width, height, color)
}
raylib::EndDrawing()
}
return 0
}