text
stringlengths
0
721
**Color palette (COLOR command, 0–15):** 0=Black, 1=Blue, 2=Green, 3=Cyan, 4=Red, 5=Magenta, 6=Brown, 7=Lt Gray, 8=Dk Gray, 9=Lt Blue, 10=Lt Green, 11=Lt Cyan, 12=Lt Red, 13=Lt Magenta, 14=Yellow, 15=White
### Screen Control
```basic
SCREENLOCK ON ' Buffer drawing (start frame)
SCREENLOCK OFF ' Present buffer (end frame)
VSYNC(TRUE) ' Enable VSync (default, ~60 FPS)
VSYNC(FALSE) ' Disable VSync (benchmarking)
CLS ' Clear screen
' Use CLS only with console, in graphics screen its slow
' With graphics screen, prefer LINE BF
```
### Shapes & Images
```basic
' Create shape
' LOADSHAPE and LOADIMAGE return a stable integer handle never reassigned.
' SDL2 owns the resource; your code only ever holds this one reference. Use constants.
LET RECT# = LOADSHAPE("RECTANGLE", w, h, color) ' or "CIRCLE", "TRIANGLE"
LET IMG_PLAYER# = LOADIMAGE("player.png") ' PNG (alpha) or BMP
LET IMG_REMOTE# = LOADIMAGE("https://example.com/a.png") ' Download + load
' Sprite sheet sprites indexed 1-based
DIM sprites$
LOADSHEET sprites$, 128, 128, "sheet.png" ' tileW, tileH, file
MOVESHAPE sprites$(1), x, y ' sprites$(1) = first sprite
' Transform
MOVESHAPE RECT#, x, y ' Position by top-left
ROTATESHAPE RECT#, angle ' Degrees (absolute)
SCALESHAPE RECT#, scale ' 1.0 = original size
DRAWSHAPE RECT# ' Render to buffer
SHOWSHAPE RECT# / HIDESHAPE RECT# ' Toggle visibility
REMOVESHAPE RECT# ' Free memory (always clean up)
```
---
### Text Rendering (SDL2_ttf.dll required)
#### DRAWSTRING & LOADFONT
```basic
' Default font (Arial)
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
' Load alternative font becomes the new default
LOADFONT "comic.ttf", 24
DRAWSTRING "Hello!", 100, 200, RGB(255, 255, 255)
' Reset to Arial
LOADFONT
```
`DRAWSTRING x, y` positions the top-left of the text. Requires `SDL2_ttf.dll` in the same directory as the interpreter. Prefer this over PRINT, which makes graphic screen easily blinking.
---
## Sound
```basic
' LOADSOUND returns a stable integer handle SDL2 manages the resource.
' The handle never changes; store it in a constant to protect it from accidental reassignment.
LET SND_JUMP# = LOADSOUND("jump.wav") ' Load (WAV recommended)
SOUNDONCE(SND_JUMP#) ' Play once, non-blocking
SOUNDONCEWAIT(SND_JUMP#) ' Play once, wait for finish
SOUNDREPEAT(SND_JUMP#) ' Loop continuously
SOUNDSTOP(SND_JUMP#) ' Stop specific sound
SOUNDSTOPALL ' Stop all sounds
```
Load all sounds at startup. Call `SOUNDSTOPALL` before `END`.
---
## File I/O
```basic
LET data$ = FILEREAD("file.txt") ' Read as string
DIM cfg$ : LET cfg$ = FILEREAD("settings.txt") ' Read as key=value array
FILEWRITE "save.txt", data$ ' Create/overwrite
FILEAPPEND "log.txt", entry$ ' Append
LET ok$ = FILEEXISTS("file.txt") ' 1=exists, 0=not
FILEDELETE "temp.dat" ' Delete file
```
**key=value parsing:** When `FILEREAD` assigns to a `DIM`'d array, lines `key=value` become `arr$("key")`. Lines starting with `#` are comments. Perfect for `.env` files.
```basic
DIM env$
LET env$ = FILEREAD(".env")
LET API_KEY# = env$("OPENAI_API_KEY")
```
**Paths:** Use `/` or `\\` never single `\` (it's an escape char). Relative paths are from `PRG_ROOT#`.
**FILEWRITE with array** saves in key=value format (round-trips with FILEREAD).
---