110 lines
9.2 KiB
Markdown
110 lines
9.2 KiB
Markdown
# My GBA Game
|
||
|
||
An original Game Boy Advance adventure, built one small step at a time.
|
||
|
||
## Play your game
|
||
|
||
Double-click **Build and Play.command** in this folder. It builds your ROM, runs the checks, and opens mGBA.
|
||
|
||
Or open Terminal and run:
|
||
|
||
```sh
|
||
cd ~/Developer/pokemon-gba
|
||
make play
|
||
```
|
||
|
||
The game file is **game.gba**. You can also open it directly in mGBA without rebuilding.
|
||
|
||
### Controls (mGBA defaults)
|
||
|
||
- **Arrow keys:** walk and turn to face that direction, including when a wall blocks movement.
|
||
- **X (GBA A button):** talk to Mila, the person in green below the house. Walk close first, then press X again to turn the page and once more to close the conversation. Walking pauses while talking. You can also greet the golden creature when nearby.
|
||
- **X at the house door:** stand on the steps below the door and press X to open it and go inside. Walk to the bottom doorway inside and press X to return outside.
|
||
- **Leave Greenleaf Village:** follow the central sandy path down through the gap in the bottom fence. Keep walking down to enter **Sunpetal Trail** automatically.
|
||
- **Return to the village:** on Sunpetal Trail, follow the central path up to the top edge. Press X beside the wooden sign to read the directions.
|
||
- **Visit Professor Mellon:** follow the village's horizontal sandy path right through the fence opening. His blue-roofed house is in the garden. Press X on its steps to enter, then walk close to the professor and press X to talk. Leave through the bottom doorway, then follow the garden path left to return to town.
|
||
- **Get your first partner:** talk to Professor Mellon and press X to advance his conversation. He gives you **Sprout**, an original Grass-type partner at level five. This is a one-time gift; later conversations check on Sprout instead.
|
||
- **Backspace (GBA Select button):** open your team to see Sprout. Press Backspace, X (A), or Z (B) to return. Movement pauses while the team screen is open.
|
||
- **Sprout follows you:** after receiving Sprout, walk a few steps and it follows your path. It travels through doors and map exits with you.
|
||
- **Battle the golden creature:** with Sprout on your team, walk close to the golden creature in Greenleaf Village and press X. Use Left/Right to choose **Tackle** or **Leaf Tap**, then X to attack. The golden creature responds with Bump. Press Z (B) to run away. At the result screen, press X or Z to return to the map. Sprout recovers fully after each battle.
|
||
- **Wild encounters:** with Sprout, walk around either tall-grass patch on Sunpetal Trail. **Fernfox** (Grass), **Emberwing** (Fire), or **Pebblit** (Rock) can appear automatically. Each has its own original 24×24 sprite, palette, health, and attack. Encounters only happen while moving in grass, with a short breather between battles. Leaf Tap is stronger against Pebblit and weaker against Emberwing. Fighting and running use the same keys as the golden-creature battle.
|
||
- **Get Poké Balls:** talk to **Ranger Finn**, the person in orange just left of Sunpetal Trail's central path. Press X again to receive **five Poké Balls**. This gift is given once. Press Backspace to see the count on the team screen, even if you do not have Sprout yet. Catching creatures is not implemented yet.
|
||
- **Return (GBA Start button):** return to your starting position in the current map.
|
||
|
||
If those keys do not match your emulator settings, check mGBA's keyboard input settings.
|
||
|
||
### Your first change
|
||
|
||
Open `source/actors.c` in a text editor. Find:
|
||
|
||
```c
|
||
TEST_INTERNAL const u16 shirt = RGB(5, 14, 29);
|
||
```
|
||
|
||
Those numbers mean red, green, and blue, each from 0 to 31. Try `RGB(29, 6, 6)` for a red shirt. Save, then double-click **Build and Play.command** again.
|
||
|
||
## Project files
|
||
|
||
- `source/main.c`: GBA hardware, timers, and the main game loop.
|
||
- `source/game.h`: shared game types and module declarations.
|
||
- `source/video.c`: frame buffer, dirty rows, text, and sprite renderer.
|
||
- `source/scenery.c`: map artwork and the scenery cache.
|
||
- `source/world.c`: movement, collisions, doors, map travel, and following.
|
||
- `source/actors.c`: character and creature artwork and drawing.
|
||
- `source/battle.c`: species, battle rules, and the battle screen.
|
||
- `source/story.c`: conversations, gifts, and cartridge SRAM saves.
|
||
- `source/hud.c`: map status, scene drawing, and the team screen.
|
||
- `source/wild_creatures.h`: original wild-creature sprites and palettes.
|
||
- `source/start.s`: code that starts the GBA hardware.
|
||
- `gba.ld`: tells the compiler where cartridge code and working memory go.
|
||
- `tools/rom_header.py`: adds the cartridge header the GBA expects.
|
||
- `Makefile`: builds the game with the installed ARM compiler.
|
||
- `tests/`: cartridge header, NPC interaction, drawing, house entry/exit, and room collision tests. `make check` also generates scene previews in `build/`.
|
||
|
||
Run `make check-host` to check C game behavior on your Mac using only host clang, generating scene previews in `build/`. It does not need a ROM or the ARM compiler. The C tests are grouped by maps, story, battles, rendering, and movement, with shared helpers in `tests/test_support.c`. `make check` builds the ROM, checks its header, runs the ROM-dependent Python tests, and runs these host checks.
|
||
|
||
Graphics are drawn into a RAM buffer first. Only the changed spans of each row are copied to the GBA screen during VBlank, so walking does not expose a half-erased character. Full map changes are copied while the display is temporarily blanked.
|
||
|
||
The active map's scenery is cached in a separate 76,800-byte RAM buffer. Walking and dialogue cleanup copy background rows from that cache instead of recalculating every pixel. The cache rebuilds when maps change; opening or closing an exterior door updates only its 13×18-pixel patch. Actors and UI are never stored in the scenery cache.
|
||
|
||
Sprite artwork is decoded once into cached palette indices. Character and creature bodies are drawn directly in clipped rows, with dirty-region tracking once per source row instead of a rectangle operation per opaque pixel. Mirroring, transparent pixels, dynamic palettes, and scaled battle sprites use the same renderer.
|
||
|
||
Movement has a separate 60 Hz fixed-step clock using cascaded GBA timers 2 and 3, independent of rendering. Walking is two pixels per tick (120 pixels/second), with normalized diagonal speed. Every pixel is collision-checked and recorded for Sprout and grass encounters, so faster movement does not skip walls or map exits or double the following distance. Missed updates can catch up by at most five ticks; older backlog is dropped after a long stall. Menus, conversations, battles, and map-loading time do not build up movement backlog. The existing footstep artwork is unchanged, with its phase now clocked by simulation ticks rather than rendered frames.
|
||
|
||
## Saving your partner and items
|
||
|
||
Receiving Sprout or Finn's Poké Balls automatically writes a small cartridge SRAM save, stored by mGBA alongside the ROM as `game.sav`. Keep that file to retain your partner and item count after reopening the game. Older Sprout-only saves remain compatible. Partner ownership, the ball count, and whether Finn's gift was claimed are saved, but your map and position are not. The golden-creature battle is a repeatable practice battle with two moves, health bars, victory, defeat, and running away. Sprout recovers afterward. Experience and catching creatures are not implemented yet.
|
||
|
||
### Change what Mila says
|
||
|
||
Find `dialogue` in `source/story.c`. Each pair of strings is one page of her conversation. Use CAPITAL letters and spaces, with no more than 34 characters on each line. Save and rebuild to try your new conversation.
|
||
|
||
## Mac setup
|
||
|
||
We are using Homebrew's standalone ARM compiler, not devkitPro.
|
||
The project includes its own minimal startup code and linker script; it does not require devkitPro or an additional GBA library.
|
||
|
||
1. From the account that owns Homebrew, install the compiler and binary tools:
|
||
|
||
```sh
|
||
/opt/homebrew/bin/brew install arm-none-eabi-gcc arm-none-eabi-binutils
|
||
```
|
||
|
||
2. Install [mGBA](https://mgba.io/downloads.html), an emulator for testing our game, either from its website or with:
|
||
|
||
```sh
|
||
/opt/homebrew/bin/brew install --cask mgba
|
||
```
|
||
|
||
Do not run Homebrew with sudo. Homebrew installations and updates should be handled by its owning account. Rory can use the installed compiler to build this project without administrator access.
|
||
|
||
Never share your Mac password in chat. Enter it only in the Mac's installer or Terminal prompt.
|
||
|
||
We are making an original game. No existing Pokémon ROM or separate BIOS download is needed for this first project in mGBA.
|
||
|
||
## Project status
|
||
|
||
Greenleaf Village connects south to Sunpetal Trail and east to Professor Mellon's garden and house. Both houses have working doors. Mila and the professor have conversations, and Mellon gives you Sprout once. Ranger Finn gives you five Poké Balls once, with a saved inventory count. Sprout is saved to SRAM, appears on your team screen, follows your footsteps, and can battle the village's golden creature. Three wild species appear in the route's tall grass, using distinct shaded sprites rather than recolors. Battles support two moves, species-specific replies, health bars, victory, defeat, running away, and free recovery.
|
||
|
||
All artwork is original; no Pokémon game assets or ROMs are included. Experience, catching creatures, sound, and full progress saving are not implemented yet.
|