Skip to content

Instantly share code, notes, and snippets.

@nulldatamap
Created March 2, 2023 10:29
Show Gist options
  • Save nulldatamap/30b10389bf91d6f25bb262da9c9e9709 to your computer and use it in GitHub Desktop.
Save nulldatamap/30b10389bf91d6f25bb262da9c9e9709 to your computer and use it in GitHub Desktop.
# We really need to log depth While here for the main game loop
# otherwise we'd run out of stack so quickly
While ← {𝕩{𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}𝕨@}´
r←{
# On Windows: raylib.dll
# On MacOS: libraylib.dylib (I think)
r←"libraylib.so"
initWindow⇐r •FFI ""‿"InitWindow"‿"i32"‿"i32"‿"&i32:c8"
windowShouldClose⇐r •FFI "i32"‿"WindowShouldClose"
closeWindow⇐r •FFI ""‿"CloseWindow"
setTargetFPS⇐r •FFI ""‿"SetTargetFPS"‿">i32"
getFrameTime⇐r •FFI "f32"‿"GetFrameTime"
getFPS⇐r •FFI "i32"‿"GetFPS"
pollInputEvents⇐r •FFI ""‿"PollInputEvents"
isKeyPressed⇐r •FFI "i32"‿"IsKeyPressed"‿">i32"
beginDrawing⇐r •FFI ""‿"BeginDrawing"
endDrawing⇐r •FFI ""‿"EndDrawing"
clearBackground⇐r •FFI ""‿"ClearBackground"‿">{u8,u8,u8,u8}"
drawCircle⇐r •FFI ""‿"DrawCircle"‿"i32"‿"i32"‿"f32"‿"{u8,u8,u8,u8}"
kEsc⇐256
cWhite⇐4⥊255 ⋄ cBlack⇐(3⥊0)∾255
cRed‿cGreen‿cBlue⇐(∾⟜255∘⌽⟜255‿0‿0)¨-↕3
cYellow‿cCyan‿cMagenta⇐(∾⟜255∘⌽⟜255‿255‿0)¨-↕3
}
s←100
pos←200‿200
w←30
r.InitWindow 400‿400‿("Raylib + BQN!"∾0)
r.SetTargetFPS 60
shouldClose←0
# Uh, WindowShoulcClose never returns true??
While {𝕤⋄¬shouldClose∨r.WindowShouldClose ⟨⟩}‿{𝕤
r.IsKeyPressed r.kEsc ? shouldClose↩1 ; @
t←r.GetFrameTime @
# 0≠ because booleans are real wacky for some reason
d←0‿0++´⟨0‿¯1,¯1‿0,0‿1,1‿0⟩/˜0≠r.IsKeyPressed¨ "WASD"-@
pos+↩s×d×t
r.BeginDrawing ⟨⟩
r.ClearBackground r.cBlack
r.DrawCircle (⌊¨pos)∾w∾<r.cRed
r.EndDrawing ⟨⟩
}
r.CloseWindow ⟨⟩
@nulldatamap
Copy link
Author

BQN_2x38ZxbIng

@Brian-ED
Copy link

btw, windowShouldClose returns "i32" when it should return "i8" since bools in C are i8, and i32 overflow, leading to what you showed in comments as "WindowShoulcClose never returns true".
easy to fix, since it's just "windowShouldClose⇐r •FFI "i8"‿"WindowShouldClose"" :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment