text stringlengths 0 275 |
|---|
' Load/save JSON files |
LOADJSON arr$, "file.json" |
SAVEJSON arr$, "file.json" |
``` |
--- |
## Fast Trigonometry |
~20× faster than `SIN(RAD(x))`, 1-degree precision. Uses ~5.6 KB memory. |
```basic |
FastTrig(TRUE) ' Enable lookup tables (must call first) |
LET x$ = FastCos(45) ' Degrees, auto-normalized 0–359 |
LET y$ = FastSin(90) |
LET r$ = FastRad(180) ' Deg→rad (no FastTrig needed) |
FastTrig(FALSE) ' Free memory |
``` |
Use for raycasting, sprite rotation, particle systems, any high-freq trig. |
--- |
## Libraries & INCLUDE |
```basic |
INCLUDE "helpers.bas" ' Insert source at this point |
INCLUDE "MathLib.bb" ' Load compiled library |
' Compile library (functions only — no loose code) |
' bazzbasic.exe -lib MathLib.bas → MathLib.bb |
' Function names auto-prefixed: MATHLIB_functionname$ |
PRINT FN MATHLIB_add$(5, 3) |
``` |
Library functions can read main-program constants (`#`). `.bb` files are version-locked. |
--- |
## Program Structure |
```basic |
' ---- 1. CONSTANTS (or INCLUDE "constants.bas") ---- |
LET SCREEN_W# = 640 |
LET SCREEN_H# = 480 |
LET MAX_SPEED# = 5 |
' ---- 2. FUNCTIONS (or INCLUDE "functions.bas") ---- |
DEF FN Clamp$(v$, lo$, hi$) |
IF v$ < lo$ THEN RETURN lo$ |
IF v$ > hi$ THEN RETURN hi$ |
RETURN v$ |
END DEF |
' ---- 3. INIT (declare ALL variables here, not inside loops) ---- |
' Performance: variables declared outside loops avoid repeated existence checks. |
[inits] |
SCREEN 0, SCREEN_W#, SCREEN_H#, "My Game" |
LET x$ = 320 |
LET y$ = 240 |
LET running$ = TRUE |
' ---- 4. MAIN LOOP ---- |
[main] |
WHILE running$ |
IF INKEY = KEY_ESC# THEN running$ = FALSE |
GOSUB [sub:update] |
GOSUB [sub:draw] |
SLEEP 16 |
WEND |
SOUNDSTOPALL |
END |
' ---- 5. SUBROUTINES (or INCLUDE "subs.bas") ---- |
[sub:update] |
IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - MAX_SPEED# |
IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + MAX_SPEED# |
RETURN |
[sub:draw] |
SCREENLOCK ON |
LINE (0,0)-(SCREEN_W#, SCREEN_H#), 0, BF |
CIRCLE (x$, y$), 10, RGB(0, 255, 0), 1 |
SCREENLOCK OFF |
RETURN |
``` |
**Key conventions:** |
- Variables: `camelCase$` | Constants: `UPPER_SNAKE_CASE#` | Functions: `PascalCase$` |
- Labels: `[gameLoop]` for jump targets, `[sub:name]` for subroutines |
- Image/sound IDs that never change → use constants: `LET MY_IMG# = LOADIMAGE("x.png")` |
- Group many image/sound IDs → use arrays: `DIM sprites$` / `sprites$("player") = LOADIMAGE(...)` |
--- |
## Performance Tips |
- `LINE (0,0)-(W,H), 0, BF` to clear — much faster than `CLS` |
- Always wrap draw code in `SCREENLOCK ON` / `SCREENLOCK OFF` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.