Packages / snake_game

snake_game

uploaded May 24, 2026

Classic Snake game written in XCX 3.1. Terminal-based with real-time input, progressive speed scaling, and Unicode rendering.

snake_game

Classic Snake game written natively in XCX 3.0. Playable in the terminal with real-time keyboard input, progressive speed scaling, and persistent high score within a session.


Features

  • Full terminal rendering using Unicode box-drawing characters
  • WASD and arrow key input via raw terminal mode
  • Progressive difficulty — speed increases every 50 points
  • Collision detection for walls and self
  • High score tracking across rounds
  • Game over screen with cause of death and restart prompt

  • Requirements

  • XCX runtime >= 3.0
  • PAX >= 1.0
  • Terminal with Unicode support (UTF-8)

  • Installation

    text

    xcx pax clone "snake_game"


    Running

    text

    xcx pax run

    Or directly:

    text

    xcx src/main.xcx


    Controls

    KeyAction
    W / Move up
    S / Move down
    A / Move left
    D / Move right
    QQuit game
    EnterRestart

    Direction reversal (e.g. going left while moving right) is ignored — the snake continues in the current direction.


    Scoring

    EventPoints
    Eating food+10

    Speed increases by 20 ms every 50 points, down to a minimum of 60 ms per tick.


    Project Structure

    text

    snake_game/
    

    ├── project.pax # PAX project configuration

    └── src/

    └── main.xcx # Full game — single file, no dependencies


    How It Works

    The board is a flat array:i of size BOARDW × BOARDH (20 × 15). Each cell holds one of four constants: EMPTY, SNAKE, FOOD, or WALL. The snake's body is tracked as two parallel array:i lists (snakex, snakey).

    Each tick:

    1. A read_input fiber is spawned and waits for a keypress

    2. @wait speed_ms delays the frame

    3. The fiber result is consumed via .next()

    4. step() moves the snake, checks collisions, and handles food

    Food is placed by collecting all EMPTY cell indices into a set:N, then using random.choice from to pick one at random.


    License

    MIT

    Install

    xcx pax add snake_game@1.0.0
    Download v1.0.0 (tar.gz)

    Downloads

    17

    Stars

    1

    Project Explorer

    README.md
    project.pax
    src\main.xcx