|
| #define | BULLET_ATTR 0x34 /* tile 128, pal 2, prio 3 (max), no flip */ |
| #define | BULLET_CX_OFFSET 8 /* ball centre in the 16×16 bullet canvas */ |
| #define | BULLET_CY_OFFSET 8 |
| #define | BULLET_HIDE_Y 240 |
| #define | BULLET_OAM_BASE (ENEMY_OAM_BASE + MAX_ENEMIES) /* = 9 */ |
| #define | BULLET_PALETTE 2 |
| #define | BULLET_SPEED 4 |
| #define | BULLET_SPRITE 32 /* full 32×32 OAM slot — visible bullet is centred top */ |
| #define | BULLET_TILE 128 /* OBJ tile 128 = VRAM word $6800 */ |
| #define | ENEMY_ATTR 0xA2 /* tile 64, pal 1, prio 2, V-flip */ |
| #define | ENEMY_HIDE_Y 240 |
| #define | ENEMY_HITBOX_END (32 - ENEMY_HITBOX_INSET) |
| #define | ENEMY_HITBOX_INSET 6 |
| #define | ENEMY_OAM_BASE 1 |
| #define | ENEMY_PALETTE 1 |
| #define | ENEMY_SPAWN_MASK (ENEMY_SPAWN_PERIOD - 1) |
| #define | ENEMY_SPAWN_PERIOD 32 /* power of 2 → mask, not modulo (cc65816 has no fast %) */ |
| #define | ENEMY_SPEED 2 |
| #define | ENEMY_SPRITE 32 |
| #define | ENEMY_TILE 64 /* OBJ tile 64 = VRAM word $6400 */ |
| #define | FIRE_COOLDOWN 8 /* frames between consecutive shots */ |
| #define | MAP_HEIGHT_PX 512 |
| #define | MAX_BULLETS 8 |
| #define | MAX_ENEMIES 8 |
| #define | OAM_WRITE(_id, _x, _y, _tile, _attr) |
| #define | PLAYER_ATTR 0x20 /* tile 0, pal 0, prio 2, no flip */ |
| #define | PLAYER_MAX_X 216 |
| #define | PLAYER_MAX_Y 176 |
| #define | PLAYER_MIN_X 8 |
| #define | PLAYER_MIN_Y 16 |
| #define | PLAYER_SPEED 2 |
shmup — a vertical shoot 'em up: scrolling, enemies, bullets
Kit's delivery glider over the city at night, against the security's hunters. The city scrolls down on BG1; the glider moves with the D-pad and fires with A (a small cooldown between shots). Shots travel at 4 px/frame; when a shot's bounding box overlaps a hunter, both deactivate. Hunters spawn from a pool of eight and dive down (the sprite is drawn nose up; the OAM's vertical flip turns it).
- SNES Concepts
- Sprite pools as fixed-size arrays of {x, y, active} slots (player gets OAM slot 0, enemies 1-8, bullets 9-16)
- Multiple sprite types in the same OAM grid: distinct VRAM regions (player @ $6000, enemy @ $6400, bullet @ $6800 — all word addresses) plus distinct sprite palettes (0/1/2)
- Axis-aligned bounding-box (AABB) overlap test for 32×32 sprites
- Input edge detection via padPressed() for one-shot fire
- oamMemory[] written directly, the escape hatch beside oamSet(): 17 sprites rewritten each frame from the pools, oam_update_flag set once a frame
- What to Observe
- Press A to fire a shot upward from the glider's nose
- Bullets travel at 4 px/frame; they despawn at the top of the screen or on hitting an enemy
- Hunters hit by a shot vanish immediately
- The city keeps scrolling (it wraps every 512 lines) and the hunter pool keeps spawning
- Modules Used
- console, dma, background, asset, sprite, input
- See also
- background.h, asset.h, sprite.h, input.h, dma.h