|
| #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_1942 — S5: bullets, collision and enemy destruction
Adds player bullets and bullet↔enemy AABB collision on top of S4. Pressing A fires a bullet upward (with a small cooldown). Bullets travel at 4 px/frame; when a bullet's bounding box overlaps an enemy, both deactivate. The scene composition, scroll direction and enemy spawn logic are unchanged from S4.
- 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
- What to Observe
- Press A to fire a bullet upward from the player's nose
- Bullets travel at 4 px/frame; they despawn at the top of the screen or on hitting an enemy
- Enemies hit by a bullet vanish immediately (S5.1 will add explosion animations)
- The terrain keeps scrolling and the enemy pool keeps spawning
- Modules Used
- console, dma, background, asset, sprite, input
- See also
- background.h, asset.h, sprite.h, input.h, dma.h