소스 검색

chopper: water bases with helipads, fewer enemies

Bases every 256 columns (flat ground, water tower, H pad); the game starts
on one and the tank refills only when landed on a pad. The status bar shows
the direction and distance to the nearest base. Terrain tables move to
$6000/$7000 and $A800 (BASIC ROM banked out) to make room. Enemy spawns are
sparser (SPAWN_GAP 70, at most 4 at once).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
refactor/agent-workflow
Daniel Covington 1 주 전
부모
커밋
edaa8a397d
3개의 변경된 파일과 111개의 추가작업 그리고 23개의 파일을 삭제
  1. +13
    -1
      projects/chopper/src/gfx.h
  2. +91
    -22
      projects/chopper/src/main.c
  3. +7
    -0
      projects/chopper/tools/gen_gfx.py

+ 13
- 1
projects/chopper/src/gfx.h 파일 보기

@@ -3,7 +3,7 @@
#define GFX_H

#define FIRST_TILE 64
#define NUM_TILES 33
#define NUM_TILES 39
#define T_CL_TL 64
#define T_CL_TM1 65
#define T_CL_TM2 66
@@ -37,6 +37,12 @@
#define T_DIRT2 94
#define T_BURNT_TREE 95
#define T_BURNT_PINE 96
#define T_PAD 97
#define T_PAD_H1 98
#define T_PAD_H2 99
#define T_TANK_TOP 100
#define T_TANK_MID 101
#define T_TANK_LEGS 102

static const unsigned char tile_data[NUM_TILES * 8] = {
0x00,0x00,0x00,0x01,0x05,0x15,0x55,0x55, /* T_CL_TL */
@@ -72,6 +78,12 @@ static const unsigned char tile_data[NUM_TILES * 8] = {
0xAA,0xAA,0xAE,0xAA,0xEA,0xAE,0xFF,0xFF, /* T_DIRT2 */
0x82,0x22,0x88,0x28,0x88,0x28,0x28,0x28, /* T_BURNT_TREE */
0x08,0x28,0x88,0x28,0x2A,0x88,0x28,0x28, /* T_BURNT_PINE */
0x55,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xFF, /* T_PAD */
0x55,0xAA,0x9A,0x9A,0x95,0x9A,0x9A,0xFF, /* T_PAD_H1 */
0x55,0xAA,0xA6,0xA6,0x56,0xA6,0xA6,0xFF, /* T_PAD_H2 */
0x00,0x28,0xAA,0xFF,0x9A,0x9A,0x9A,0xAA, /* T_TANK_TOP */
0x9A,0x9A,0xFF,0x9A,0x9A,0xAA,0x82,0x82, /* T_TANK_MID */
0x82,0x28,0x28,0x82,0x82,0x28,0x28,0x82, /* T_TANK_LEGS */
};

#define NUM_SPRITES 49


+ 91
- 22
projects/chopper/src/main.c 파일 보기

@@ -32,9 +32,10 @@
* moves them and tests collisions; this file spawns them and handles hits.
* Three lives; a hit costs one and gives a few seconds of blinking safety.
*
* Fires: trees catch fire ahead of the chopper. Hold fire to spray water
* (the tank refills on the ground); hover low over a burning tree until it
* goes out. A fire left behind burns its tree for good (FIRE_T remembers).
* Fires: trees catch fire ahead of the chopper. Hold fire to spray water;
* hover low over a burning tree until it goes out. A fire left behind burns
* its tree for good (FIRE_T remembers). The tank refills only when landed on
* a base's helipad: there is one every 256 columns, and the game starts on one.
*/
#include <string.h>
#include <c64.h>
@@ -50,15 +51,23 @@
#define JOY2 (*(volatile unsigned char *)0xDC00)
#define BLNSW (*(unsigned char *)0x00CC) /* non-zero: Kernal cursor blink off */

/* World tables, built at startup ($5000-$7FFF; the program must end below). */
/* World tables, built at startup. RND_T sits in the RAM under the BASIC ROM,
which the game switches out ($01 = $36) before anything else. */
#define WORLD_COLS 4096
#define WORLD_MASK 0x0FFF /* the world repeats every 4096 columns */
#define MT_H ((unsigned char *)0x5000) /* mountain height per column, 2..9 */
#define HL_H ((unsigned char *)0x6000) /* hill height per column, 0..3 */
#define RND_T ((unsigned char *)0x7000) /* random byte per column */
#define DATA_LOW 0x5000
#define MT_H ((unsigned char *)0x6000) /* mountain height per column, 2..9 */
#define HL_H ((unsigned char *)0x7000) /* hill height per column, 0..3 */
#define RND_T ((unsigned char *)0xA800) /* random byte per column */
#define DATA_LOW 0x6000 /* the program must end below this */
#define FIRE_T ((unsigned char *)0x9800) /* burnt-tree bits, 1 per column (512 bytes) */

/* Bases: 8 columns every 256, laid out as
0 grass | 1 water tower | 2 grass | 3-6 helipad (H on 4-5) | 7 grass.
BASE0 puts the first pad under the chopper's starting spot. */
#define BASE0 1013
#define BASE_W 8
#define BASE_OFF(c) ((unsigned char)((c) - BASE0)) /* 0..255 within each base period */

#define CL_ROW 0
#define CL_ROWS 5
#define MT_ROW 5
@@ -176,16 +185,29 @@ static void build_ridge(unsigned char *map, unsigned char base,

static void build_world(void)
{
unsigned char hi = 0, lo, x, *p = RND_T;
unsigned char hi = 0, lo, *p = RND_T;
unsigned b, c, x;

rnd_init();
do { /* RND_T[c] = rnd[lo ^ rnd[hi]] */
x = rnd[hi * 16 + 7];
lo = 0;
do { *p++ = rnd[lo ^ x]; } while (++lo);
do { *p++ = rnd[lo ^ (unsigned char)x]; } while (++lo);
} while (++hi < WORLD_COLS / 256);
build_ridge(MT_H, 2, 0x3C, mtn_peaks);
build_ridge(HL_H, 0, 0x77, hill_peaks);

/* flat ground at every base, with the hills easing down to it */
for (b = 0; b < WORLD_COLS / 256; ++b) {
c = (BASE0 + b * 256) & WORLD_MASK;
for (lo = 0; lo < BASE_W; ++lo) HL_H[(c + lo) & WORLD_MASK] = 0;
for (lo = 1; lo <= 3; ++lo) {
x = (c - lo) & WORLD_MASK;
if (HL_H[x] > lo) HL_H[x] = lo;
x = (c + BASE_W - 1 + lo) & WORLD_MASK;
if (HL_H[x] > lo) HL_H[x] = lo;
}
}
}

/* 0 flat/valley, 1 rising "/", 2 falling "\", 3 peak */
@@ -248,17 +270,26 @@ static const unsigned char bit8[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
(and none on a hill). */
static unsigned char tree_at(unsigned c)
{
return HL_H[c] ? 7 : (RND_T[c ^ 0x5A5] >> 3) & 7;
return HL_H[c] || BASE_OFF(c) < BASE_W ? 7 : (RND_T[c ^ 0x5A5] >> 3) & 7;
}

static const unsigned char pad_tiles[4] = { T_PAD, T_PAD_H1, T_PAD_H2, T_PAD };

static void gen_hills(unsigned c)
{
unsigned char h = HL_H[c], r = RND_T[c ^ 0x5A5];
unsigned char h = HL_H[c], r = RND_T[c ^ 0x5A5], r2;

memset(colbuf, BLANK, HL_ROWS);
colbuf[6] = (r & 1) ? T_GRASS1 : T_GRASS2;
colbuf[7] = (r & 2) ? T_DIRT1 : T_DIRT2;
if (h) {
r2 = BASE_OFF(c);
if (r2 < BASE_W) { /* a base */
if (r2 == 1) {
colbuf[3] = T_TANK_TOP; colbuf[4] = T_TANK_MID; colbuf[5] = T_TANK_LEGS;
} else if (r2 >= 3 && r2 <= 6) {
colbuf[6] = pad_tiles[r2 - 3];
}
} else if (h) {
colbuf[6 - h] = hill_top[top_shape(HL_H[(c - 1) & WORLD_MASK], h, HL_H[(c + 1) & WORLD_MASK])];
memset(colbuf + 7 - h, T_H_SOLID, h - 1);
} else {
@@ -511,6 +542,8 @@ static void set_heli_sprites(unsigned char frame)

static unsigned char ri, rj;
static unsigned char spawn_t = 90;
#define SPAWN_GAP 70 /* frames between enemies: SPAWN_GAP + 0..63 */
#define MAX_ENEMIES 4 /* birds, balloons and jets on screen at once */
static unsigned spawned; /* statistics for the test */
static unsigned char peak_v; /* most hazards on screen at once */
static unsigned mux_frames; /* frames that needed more than 5 sprites */
@@ -555,7 +588,10 @@ static void spawn_hazards(void)

if (--spawn_t) return;
r = rand8();
spawn_t = 30 + (r & 63);
spawn_t = SPAWN_GAP + (r & 63);
for (i = n = 0; i < MAXH; ++i) /* enemies already up */
if (hz_type[i] && hz_type[i] <= HZ_JET) ++n;
if (n >= MAX_ENEMIES) return;
side = vx > 6 ? 1 : vx < -6 ? 0 : (r >> 7); /* 1 = right edge */
y = 64 + (rand8() & 127);
if (y > 180) y -= 60;
@@ -563,6 +599,7 @@ static void spawn_hazards(void)

switch (r & 7) {
case 0: case 1: case 2: /* a flock of three birds */
if (n + 3 > MAX_ENEMIES) return;
for (n = 0; n < 3; ++n) {
if ((i = free_slot()) == 255) return;
place(i, HZ_BIRD,
@@ -602,6 +639,19 @@ static void sound_boom(void)
SID.v1.ctrl = 0x81; /* noise, gate on */
}

/* World column under the middle of the chopper (screen column k's left edge
is at sprite X 31 + 8k - (px & 7)). */
static unsigned heli_col(void)
{
return LAY_COL(L_HILLS) + ((unsigned)(hx + 12 - 31 + (lay_px_lo[L_HILLS] & 7)) >> 3);
}

static unsigned char at_base(void)
{
unsigned char o = BASE_OFF(heli_col());
return landed && o >= 3 && o <= 6;
}

static unsigned char burning(unsigned c)
{
unsigned char i;
@@ -686,7 +736,7 @@ static void run_hazards(unsigned char stick, unsigned char frame)
/* water: fire button while flying; the tank refills on the ground */
spraying = (stick & JOY_FIRE) && !landed && water && !boom_t && !game_over;
if (spraying && (frame & 1)) --water;
if (landed && water < WATER_MAX && (frame & 1)) ++water;
if (water < WATER_MAX && at_base()) ++water; /* refill on a helipad */
spray_sound(spraying);
spray_on = spraying;
spray_xlo = (unsigned char)hx;
@@ -805,11 +855,12 @@ static void draw_hud_frame(void)
#pragma charmap (0x79, 0x19)
#pragma charmap (0x7A, 0x1A)
#define MSG_LEN 36
static const char msg[4][MSG_LEN + 1] = {
static const char msg[5][MSG_LEN + 1] = {
"demo - press fire or move the stick ",
"landed - tank refills - up: take off",
"fires out 00 trees lost 00 ",
"landed - no water here, find a base ",
"fires out 00 burnt 00 base > 000 ",
"game over - press fire to fly again ",
"base - filling the tank - up to fly ",
};
/* back to cc65's normal PETSCII mapping for the rest of the file */
#pragma charmap (0x61, 0x41)
@@ -844,6 +895,7 @@ static void update_hud(unsigned char part)
static unsigned char shown = 255;
static unsigned char shown_out = 255, shown_lost = 255;
unsigned char mode;
signed char d;

switch (part & 3) { /* one field per frame keeps frames even */
case 0: put_num(HUD1 + 7, (vx < 0 ? -vx : vx) * 3, 2); break; /* 0..96 */
@@ -851,7 +903,7 @@ static void update_hud(unsigned char part)
case 2: put_num(HUD1 + 26, water, 2); break;
case 3:
HUD1[36] = '0' + lives;
mode = demo ? 0 : game_over ? 3 : landed ? 1 : 2;
mode = demo ? 0 : game_over ? 3 : !landed ? 2 : at_base() ? 4 : 1;
if (mode != shown) {
shown = mode;
shown_out = shown_lost = 255;
@@ -859,7 +911,12 @@ static void update_hud(unsigned char part)
}
if (mode == 2) {
if (fires_out != shown_out) put_num(HUD2 + 12, shown_out = fires_out, 2);
else if (trees_lost != shown_lost) put_num(HUD2 + 28, shown_lost = trees_lost, 2);
else if (trees_lost != shown_lost) put_num(HUD2 + 22, shown_lost = trees_lost, 2);
else { /* nearest base: direction and columns */
d = (signed char)(4 - BASE_OFF(heli_col()));
HUD2[31] = d > 0 ? '>' : d < 0 ? '<' : '*';
put_num(HUD2 + 33, d < 0 ? -d : d, 3);
}
}
}
}
@@ -872,7 +929,7 @@ static void setup_screen(void)
__asm__("sei");
*(unsigned char *)1 = 0x33; /* character ROM at $D000 */
memcpy(CHARSET, (void *)0xD000, 0x800);
*(unsigned char *)1 = 0x37;
*(unsigned char *)1 = 0x36; /* back to: BASIC ROM out */
__asm__("cli");
memcpy(CHARSET + FIRST_TILE * 8, tile_data, NUM_TILES * 8);
memcpy(SPRMEM, sprite_data, NUM_SPRITES * 64);
@@ -928,7 +985,7 @@ static void self_test(void)
{
unsigned c;

/* the world tables at $5000-$7FFF must sit above the program's BSS */
/* the world tables at $6000-$7FFF must sit above the program's BSS */
c64test_check((unsigned)_BSS_RUN__ + (unsigned)_BSS_SIZE__ <= DATA_LOW, 1);

/* sub-pixel stepping and coarse-scroll detection (layer 0 as a scratch layer) */
@@ -1007,6 +1064,16 @@ static void self_test(void)
spray_on = 0;
spawned = 0;

/* bases: flat, a tower and a pad, no trees */
for (c = 0; c < BASE_W; ++c) {
c64test_check(HL_H[(BASE0 + 256 + c) & WORLD_MASK] == 0, 30);
c64test_check(tree_at((BASE0 + 512 + c) & WORLD_MASK) > 2, 31);
}
gen_hills(BASE0 + 1);
c64test_check(colbuf[3] == T_TANK_TOP && colbuf[5] == T_TANK_LEGS, 32);
gen_hills(BASE0 + 4);
c64test_check(colbuf[6] == T_PAD_H1 && colbuf[0] == BLANK, 33);

/* number formatting */
to_dec(8190);
c64test_check(memcmp(decbuf, "\x30\x38\x31\x39\x30", 5) == 0, 10);
@@ -1029,10 +1096,12 @@ int main(void)
{
unsigned char last, frame = 0, stick, raw, fire_was = 0, hud_part = 0;

*(unsigned char *)1 = 0x36; /* BASIC ROM out: RND_T lives at $A800 */
build_world();
self_test();
BLNSW = 1;
setup_screen();
c64test_check(at_base(), 34); /* the game starts on a helipad */
irq_init();
last = irq_frame;



+ 7
- 0
projects/chopper/tools/gen_gfx.py 파일 보기

@@ -400,6 +400,13 @@ TILES = [
("T_DIRT2", ["gggg", "gggg", "gg#g", "gggg", "#ggg", "gg#g", "####", "####"]),
("T_BURNT_TREE", ["g..g", ".g.g", "g.g.", ".gg.", "g.g.", ".gg.", ".gg.", ".gg."]),
("T_BURNT_PINE", ["..g.", ".gg.", "g.g.", ".gg.", ".ggg", "g.g.", ".gg.", ".gg."]),
# base: helipad on the grass row, water tower three rows tall
("T_PAD", ["wwww", "gggg", "gggg", "gggg", "gggg", "gggg", "gggg", "####"]),
("T_PAD_H1", ["wwww", "gggg", "gwgg", "gwgg", "gwww", "gwgg", "gwgg", "####"]),
("T_PAD_H2", ["wwww", "gggg", "ggwg", "ggwg", "wwwg", "ggwg", "ggwg", "####"]),
("T_TANK_TOP", ["....", ".gg.", "gggg", "####", "gwgg", "gwgg", "gwgg", "gggg"]),
("T_TANK_MID", ["gwgg", "gwgg", "####", "gwgg", "gwgg", "gggg", "g..g", "g..g"]),
("T_TANK_LEGS", ["g..g", ".gg.", ".gg.", "g..g", "g..g", ".gg.", ".gg.", "g..g"]),
]
PIX = {".": 0, "w": 1, "g": 2, "#": 3}



불러오는 중...
취소
저장

Powered by TurnKey Linux.