diff --git a/common.asm b/common.asm index 0052142..27fad76 100644 --- a/common.asm +++ b/common.asm @@ -82,18 +82,19 @@ road_row: adc #6 ; road runs from char row 6 to row 24 tax jsr row_ptr - lda #19 ; left edge: one column left per row + ldx drtmp ; use perspective curve for the edge offset + lda #19 sec - sbc drtmp + sbc road_off,x tay sty drleft lda #$4e ; '/' diagonal sta (scrlo),y lda #COL_EDGE sta (collo),y - lda #20 ; right edge: one column right per row + lda #20 clc - adc drtmp + adc road_off,x tay lda #$4d ; '\' diagonal sta (scrlo),y @@ -158,6 +159,33 @@ draw_tree: sta (collo),y rts +; ---- erase one tree (write spaces at trow/tcol positions) ---- +erase_tree: + ldx trow + dex + jsr row_ptr + ldy tcol + iny + lda #$20 + sta (scrlo),y + ldx trow + jsr row_ptr + ldy tcol + lda #$20 + sta (scrlo),y + iny + sta (scrlo),y + iny + sta (scrlo),y + ldx trow + inx + jsr row_ptr + ldy tcol + iny + lda #$20 + sta (scrlo),y + rts + tree_ball: lda #$51 ; foliage ball sta (scrlo),y @@ -165,11 +193,10 @@ tree_ball: sta (collo),y rts -NTREES = 6 tree_tbl: ; middle row, left column - far trees sit !byte 9, 4 ; higher and closer to the road !byte 14, 6 - !byte 19, 3 + !byte 18, 2 !byte 8, 31 !byte 12, 34 !byte 17, 36 diff --git a/defs.asm b/defs.asm index f8393db..600cdb1 100644 --- a/defs.asm +++ b/defs.asm @@ -63,6 +63,8 @@ T_BIG = 112 ; rabbit distance where the big frames start T_EXP = 192 ; ... and where the sprite gets double-sized REP_HOLD = 12 ; frames before a held direction auto-repeats REP_PERIOD = 6 ; frames between auto-repeat steps +TREE_SPEED = 3 ; frames between tree scroll steps +NTREES = 6 ; roadside trees per side-pair RAS_SYNC = 251 ; raster line polled for the frame sync RAS_SPLIT = 97 ; horizon line: sky/grass background split diff --git a/play.asm b/play.asm index eefeed9..90dfe1d 100644 --- a/play.asm +++ b/play.asm @@ -13,6 +13,20 @@ play_init: jsr clear_screen jsr draw_road + ; Copy static tree positions into dynamic arrays + ldx #0 + ldy #0 +pti_loop: + lda tree_tbl,y + sta t_row,x + iny + lda tree_tbl,y + sta t_col,x + iny + inx + cpx #NTREES + bne pti_loop + ; HUD: score on the left, miss slots on the right +prtext 0, 1, BLACK, txt_score, 5 +prtext 0, 30, BLACK, txt_miss, 4 @@ -25,6 +39,7 @@ play_init: sta miss sta flash sta spawnt + sta tree_timer sta lcnt sta rcnt sta p2lcnt @@ -236,6 +251,7 @@ pu_rnext: bpl pu_rab jsr write_shadows + jsr animate_trees ; -- third miss ends the round -- lda miss @@ -315,6 +331,96 @@ sr_ramp: sta r_sphi,x rts +; ---- animate roadside trees: scroll down + fan outward ---- +animate_trees: + inc tree_timer + lda tree_timer + cmp #TREE_SPEED + bcs at_go + rts +at_go: + lda #0 + sta tree_timer + + ; Phase 1: erase all trees at current positions + ldx #NTREES-1 +at_erase: + stx at_idx + lda t_row,x + sta trow + lda t_col,x + sta tcol + jsr erase_tree + ldx at_idx + dex + bpl at_erase + + ; Phase 2: update all positions + ldx #NTREES-1 +at_move: + inc t_row,x + lda t_col,x + cmp #20 + bcs at_mright + ; left side: move one column left + lda t_col,x + beq at_mresp + dec t_col,x + jmp at_mcheck +at_mright: + ; right side: move one column right + lda t_col,x + cmp #37 + bcs at_mresp + inc t_col,x +at_mcheck: + lda t_row,x + cmp #23 + bcc at_mnext +at_mresp: + ; respawn near the horizon + lda t_col,x + cmp #20 + bcs at_mrespr + ; left side: random col 10-13 + jsr rand8 + and #3 + clc + adc #10 + sta t_col,x + jmp at_mresprow +at_mrespr: + ; right side: random col 24-27 + jsr rand8 + and #3 + clc + adc #24 + sta t_col,x +at_mresprow: + jsr rand8 + and #1 + clc + adc #7 + sta t_row,x +at_mnext: + dex + bpl at_move + + ; Phase 3: redraw all trees at new positions + ldx #NTREES-1 +at_draw: + stx at_idx + lda t_row,x + sta trow + lda t_col,x + sta tcol + jsr draw_tree + ldx at_idx + dex + bpl at_draw +at_done: + rts + ; ---- score: bump the decimal digits and the difficulty byte ---- add_score: lda score8 @@ -379,6 +485,12 @@ rcnt: !byte 0 p2lcnt: !byte 0 ; the same for player 2's steering p2rcnt: !byte 0 +; ---- dynamic tree state ---- +t_row: !fill NTREES, 0 ; current row of each tree +t_col: !fill NTREES, 0 ; current column of each tree +tree_timer: !byte 0 ; frames since last tree scroll +at_idx: !byte 0 ; animate_trees loop index + ; ---- rabbit slots (hardware sprites 1-7) ---- r_act: !fill NRABBITS, 0 r_lane: !fill NRABBITS, 0 diff --git a/tables.asm b/tables.asm index b4c3ecd..ac35348 100644 --- a/tables.asm +++ b/tables.asm @@ -45,3 +45,9 @@ sprxreg: ; rabbit slot -> sprite enable/MSB/expand bit sprbit: !byte 2, 4, 8, 16, 32, 64, 128 + +; road edge offset per row (0-18): perspective curve +; wider at the horizon (offset 2) so it looks like a real road, +; not a sharp pyramid; only delta 0/1 steps, no visible jumps +road_off: + !byte 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18