K7 + Python (Pyodide)
k7.cls(col) # clear, col 0–15
k7.pset(x, y, col)
k7.rect(x0, y0, x1, y1, col)
k7.rectfill(x0, y0, x1, y1, col)
k7.circ(x, y, r, col) k7.circfill(x, y, r, col)
k7.line(x0, y0, x1, y1, col)
k7.print(text, x, y, col)
k7.color(col) # set draw color (for col=-1)
k7.camera(x, y)
k7.draw_to_canvas("k7canvas") # flush to canvas
k7.switch_palette("pico8") # pico8, gameboy, cga, commodore64, atari2600
k7.btn(i) k7.btnp(i) # i: 0=left 1=right 2=up 3=down 4=Z 5=X 6=C 7=V k7.mouse_x() k7.mouse_y() # 0–255 (canvas coords) k7.mouse_btn(i) k7.mouse_btnp(i) # 0=left 1=right # Keyboard capture (for chat, text input): captures chars, Enter, Backspace k7.text_input_mode(True) # enable (False = game keys only) for c in k7.take_key_queue(): # returns list of "\n", "\b", or 1-char strings ...
k7.set_sound(id, "c4 e4 g4") # 16 slots k7.sfx(id) k7.play_sfx_chain(id) # play chain 0–3 (built in Sounds → SFX chain) k7.set_music_track(id, "c4 e4 g4 c5") k7.set_music_step_ms(200) # optional: note step interval for play_music (40–600, default 200) k7.play_music(channel, track_id) k7.stop_music(channel) k7.master_volume(0.5) # 0–1 k7.mute_sfx(1) k7.mute_music(1) # 0=on 1=mute
k7.spr(n, x, y, w, h, flip_x, flip_y, scale?) # scale: 1=8px/tile, 2=16px (optional, default 1) k7.sget(sx, sy) k7.sset(sx, sy, col) k7.mget(cx, cy) k7.mset(cx, cy, v) k7.mget_flags(cx, cy) k7.mset_flags(cx, cy, f) # f: 1=flip_x 2=flip_y 4=rotate k7.map_draw(cx, cy, sx, sy, w, h)
k7.set_font("pico8"|"bbc"|"appleii"|"cbmii"|"trollmini")
k7.print_rgba(text, x, y, r, g, b, a) # 0–255, alpha for transparency
k7.pset_rgba(x, y, r, g, b, a)
k7.rectfill_rgba(x0, y0, x1, y1, r, g, b, a)
k7.palette_swap(a, b) # swap colors 0–15 k7.flash(color, frames) # full-screen flash (color 0–15)
k7.ws_connect(url) k7.ws_send(msg) k7.ws_take_messages() # returns array of strings k7.ws_connected()
k7.ws_connect("ws://127.0.0.1:8081") # connect first (same server as multiplayer)
k7.llm_configure(endpoint?, api_key?, model?) # model optional, default gpt-4o-mini
k7.llm_send(prompt, system_prompt?)
k7.llm_pending() # True if request in flight
k7.llm_take_response() # Returns text or None
k7.llm_take_error() # Returns error message or None
Server proxies LLM to http://127.0.0.1:1234. Run cargo run -p k7-multiplayer-server, then ws_connect and llm_send. Poll llm_take_response() each frame.
Run = click Run. P = pause/resume game. Share game = encode full game (code, sounds, map, sprites) into the URL and copy link. Code tab: Space = play sound (when Sounds panel active). Hot reload = re-run on code change. Profiler = show FPS/frame time overlay.
In code: k7.paused() returns 1 if paused, 0 otherwise; k7.toggle_pause() toggles pause. k7.frame() returns the current frame number (incremented each game loop tick) for timing or “once per frame” logic.