1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 08:55:38 +00:00

Add example games and quick-start guide

Two example .ne programs with compiled .nes ROMs:
- hello_sprite: d-pad controlled sprite movement
- bouncing_ball: auto-bouncing sprite with edge detection

Includes README with build instructions and emulator setup.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-11 22:17:18 +00:00
parent 39ca246151
commit a20ddcbbab
No known key found for this signature in database
3 changed files with 125 additions and 0 deletions

65
examples/README.md Normal file
View file

@ -0,0 +1,65 @@
# NEScript Examples
## Quick Start
### 1. Build the compiler
```
cargo build --release
```
### 2. Compile an example
```
cargo run -- build examples/hello_sprite.ne
```
This produces `examples/hello_sprite.nes` — a valid iNES ROM file.
### 3. Run in an emulator
Open the `.nes` file in any NES emulator:
- **[Mesen](https://www.mesen.ca/)** (recommended — best debugging support)
- **[FCEUX](https://fceux.com/)**
- **[Nestopia](http://nestopia.sourceforge.net/)**
Use the d-pad (arrow keys in most emulators) to move the sprite.
## Examples
| File | Description |
|------|-------------|
| `hello_sprite.ne` | Move a smiley face with the d-pad |
| `bouncing_ball.ne` | A sprite that bounces around the screen automatically |
## What you'll see
The ROM displays a small smiley-face sprite (an 8x8 tile built into the
compiler's default CHR data). In `hello_sprite`, you control it with the d-pad.
In `bouncing_ball`, it moves on its own and bounces off the screen edges.
## Emulator controls
| NES Button | Typical Key |
|------------|-------------|
| D-pad | Arrow keys |
| A | Z |
| B | X |
| Start | Enter |
| Select | Right Shift |
(Exact mappings vary by emulator — check your emulator's input settings.)
## Compiler commands
```
# Compile to ROM
cargo run -- build examples/hello_sprite.ne
# Compile with custom output path
cargo run -- build examples/hello_sprite.ne --output my_game.nes
# Type-check only (no ROM output)
cargo run -- check examples/hello_sprite.ne
```

37
examples/bouncing_ball.ne Normal file
View file

@ -0,0 +1,37 @@
// Bouncing Ball — a sprite that bounces around the screen automatically.
//
// Build: cargo run -- build examples/bouncing_ball.ne
// Output: examples/bouncing_ball.nes
game "Bouncing Ball" {
mapper: NROM
}
var px: u8 = 64
var py: u8 = 64
var dx: u8 = 1 // 1 = moving right, 0 = moving left
var dy: u8 = 1 // 1 = moving down, 0 = moving up
on frame {
// Move horizontally
if dx == 1 {
px += 1
if px >= 240 { dx = 0 }
} else {
px -= 1
if px == 0 { dx = 1 }
}
// Move vertically
if dy == 1 {
py += 1
if py >= 224 { dy = 0 }
} else {
py -= 1
if py == 0 { dy = 1 }
}
draw Ball at: (px, py)
}
start Main

23
examples/hello_sprite.ne Normal file
View file

@ -0,0 +1,23 @@
// Hello Sprite — the simplest NEScript program.
//
// Displays a smiley-face sprite on screen and moves it with the d-pad.
// Build: cargo run -- build examples/hello_sprite.ne
// Output: examples/hello_sprite.nes (open in any NES emulator)
game "Hello Sprite" {
mapper: NROM
}
var px: u8 = 128
var py: u8 = 120
on frame {
if button.right { px += 2 }
if button.left { px -= 2 }
if button.down { py += 2 }
if button.up { py -= 2 }
draw Smiley at: (px, py)
}
start Main