; In Town ; Puzzle Room ; Get through office ; Have to run away? What happens if die? No save game? Code? ; Construct the LED circuit ; Zaps through cloud ; Susie joins your party ; Final Battle ; Play music, lightning effects? ; TFV only hit for one damage, susie for 100 handle_overworld: ;=================== ; Clear screen/pages ;=================== jsr clear_screens bit PAGE0 lda #0 sta DISP_PAGE lda #4 sta DRAW_PAGE ;=============== ; Init Variables ;=============== lda #HERO_DIRECTION ; have us face right (1) sta HERO_STATE lda #$1 sta REFRESH lda #3 sta HERO_LIMIT lda #5 sta MAP_X lda #15 sta TFV_X lda #20 sta TFV_Y ;================== ; MAIN LOOP ;================== worldmap_loop: lda #$0 sta HERO_MOVED lda TFV_X sta NEWX lda TFV_Y sta NEWY worldmap_keyboard: jsr get_keypress ; get keypress worldmap_handle_q: cmp #'Q' ; if quit, then return bne worldmap_handle_up rts worldmap_handle_up: cmp #'W' bne worldmap_handle_down dec NEWY dec NEWY inc HERO_MOVED jmp worldmap_done_keyboard worldmap_handle_down: cmp #'S' bne worldmap_handle_left inc NEWY inc NEWY inc HERO_MOVED jmp worldmap_done_keyboard worldmap_handle_left: cmp #'A' bne worldmap_handle_right lda HERO_STATE and #HERO_DIRECTION ; 0=left, 1=right beq go_left ; if (0) already left, keep going left_turn: lda HERO_STATE and #<(~HERO_DIRECTION) ; change direction to left (0) and #<(~HERO_ODD) ; stand (not walk) if changing sta HERO_STATE jmp done_handle_left ; skip ahead go_left: dec NEWX ; decrement x inc HERO_MOVED ; we moved done_handle_left: jmp worldmap_done_keyboard worldmap_handle_right: cmp #('D') bne worldmap_handle_enter lda HERO_STATE and #HERO_DIRECTION ; 0=left, 1=right bne go_right ; if (1) already right, keep going right_turn: lda HERO_STATE ora #HERO_DIRECTION ; change direction to right (1) and #<(~HERO_ODD) ; change to standing sta HERO_STATE jmp done_handle_right ; skip ahead go_right: inc NEWX ; increment X inc HERO_MOVED done_handle_right: jmp worldmap_done_keyboard worldmap_handle_enter: cmp #13 bne worldmap_handle_help ; jsr city_map inc REFRESH jmp worldmap_done_keyboard worldmap_handle_help: cmp #('H') bne worldmap_handle_battle jsr print_help jmp worldmap_done_keyboard worldmap_handle_battle: cmp #'B' bne worldmap_handle_info jsr do_battle inc REFRESH jmp worldmap_done_keyboard worldmap_handle_info: cmp #'I' bne worldmap_handle_map jsr print_info inc REFRESH jmp worldmap_done_keyboard worldmap_handle_map: cmp #('M') bne worldmap_done_keyboard jsr show_map inc REFRESH ; jmp worldmap_done_keyboard worldmap_done_keyboard: ;=========================== ; Handle Movement ;=========================== lda HERO_MOVED beq worldmap_refresh_screen lda HERO_STATE ; toggle ODD eor #HERO_ODD sta HERO_STATE inc HERO_STEPS ; Handle Collision Detection lda NEWX sta TFV_X lda NEWY sta TFV_Y check_high_x: lda TFV_X cmp #36 bmi check_low_x ; Off screen to right lda #0 sta TFV_X inc MAP_X inc REFRESH bne check_high_y check_low_x: lda TFV_X bpl check_high_y dec MAP_X lda #35 sta TFV_X inc REFRESH check_high_y: lda TFV_Y ; load Y value cmp #28 bmi check_low_y ; if less than 28, check low Y clc lda #$4 sta TFV_Y adc MAP_X sta MAP_X inc REFRESH bne done_map_check check_low_y: lda TFV_Y cmp #4 bpl done_map_check lda #28 sta TFV_Y dec MAP_X dec MAP_X dec MAP_X dec MAP_X inc REFRESH done_map_check: ;============================ ; Refresh screen if needed ;============================ worldmap_refresh_screen: lda REFRESH beq worldmap_copy_background jsr load_map_bg dec REFRESH worldmap_copy_background: ;================ ; Copy background ;================ jsr gr_copy_to_current_40x40 ;================================= ; Handle background ground scatter ;================================= ; if (map_x==1) if (tfv_y>=22) grsim_put_sprite(snowy_tree,10,20); lda MAP_X cmp #1 bne back_not_snow lda TFV_Y cmp #22 bmi no_back_scatter ; snowy tree lda #>snowy_tree sta INH lda #=16) grsim_put_sprite(pine_tree,25,16); cmp #4 bne back_not_pine lda TFV_Y cmp #16 bmi no_back_scatter ; pine tree lda #>pine_tree sta INH lda #=22) grsim_put_sprite(palm_tree,10,20); cmp #8 bne back_not_palm lda #10 sta XPOS bne back_palm back_not_palm: ; palm tree 2 ; if (map_x==12) if (tfv_y>=22) grsim_put_sprite(palm_tree,20,20); cmp #12 bne back_not_palm2 lda #20 sta XPOS back_palm: lda TFV_Y cmp #22 bmi no_back_scatter lda #>palm_tree sta INH lda #=16) grsim_put_sprite(cactus,25,16); lda #>cactus sta INH lda #tfv_walk_left_sprite sta INH lda #tfv_walk_right_sprite sta INH lda #tfv_stand_left_sprite sta INH lda #tfv_stand_right_sprite sta INH lda #snowy_tree sta INH lda #pine_tree sta INH lda #palm_tree sta INH lda #cactus sta INH lda #lightning sta INH lda #25) && (tfv_x<30) && (tfv_y<12)) { ; printf("HIT! %d %d\n\n",steps,hp); ; if (hp>11) { ; hp=10; no_lightning: jsr page_flip ;============ ; Update Time ;============ ; if (steps>=60) { ; steps=0; ; time_minutes++; ; if (time_minutes>=60) { ; time_hours++; ; time_minutes=0; ; } ; } jmp worldmap_loop ; Map ; ; 0 1 2 3 ; ; 0 BEACH ARCTIC ARCTIC BELAIR ; TREE MOUNATIN ; ; 1 BEACH LANDING GRASS FOREST ; PINETREE MOUNTAIN ; ; 2 BEACH GRASS GRASS FOREST ; PALMTREE MOUNTAIN ; ; 3 BEACH DESERT COLLEGE BEACH ; CACTUS PARK ;============================================= ;============================================= ; Load World Map background ;============================================= ;============================================= load_map_bg: ; Set target for the background drawing ; Check for special cases lda MAP_X map_harfco: cmp #3 ; if map_x==3, harfco bne map_landing lda #<(harfco_lzsa) sta getsrc_smc+1 lda #>(harfco_lzsa) sta getsrc_smc+2 lda #$c jsr decompress_lzsa2_fast rts map_landing: cmp #5 ; if map_x==5, landing site bne map_collegep lda #<(landing_lzsa) sta getsrc_smc+1 lda #>(landing_lzsa) sta getsrc_smc+2 lda #$c jsr decompress_lzsa2_fast rts map_collegep: cmp #14 ; if map_x==14, collegep bne map_custom lda #<(collegep_lzsa) sta getsrc_smc+1 lda #>(collegep_lzsa) sta getsrc_smc+2 lda #$c jsr decompress_lzsa2_fast rts ;============================ ; draw parametric background ;============================ map_custom: ; Draw the Sky lda DRAW_PAGE ; save the DRAW_PAGE value for later pha lda #$8 ; temporarily draw to 0xc00 sta DRAW_PAGE lda #COLOR_BOTH_MEDIUMBLUE ; MEDIUMBLUE color sta COLOR lda #0 map_sky: ; draw line across screen ldy #39 ; from y=0 to y=10 sty V2 ldy #0 pha jsr hlin_double ; hlin y,V2 at A pla clc adc #2 cmp #10 bne map_sky ;================= ; Set Ground Color ;================= ldx #COLOR_BOTH_LIGHTGREEN ; default is grass color lda MAP_X cmp #4 bpl not_artic ldx #COLOR_BOTH_WHITE ; snow white not_artic: cmp #13 bne not_desert ldx #COLOR_BOTH_ORANGE ; desert orange not_desert: stx GROUND_COLOR ;=========================================== ; sloped left beach, of left side of island ;=========================================== lda #3 and MAP_X bne not_sloped_left lda #10 sloped_left_loop: pha eor #$ff ; temp=4+(39-i)/8; sec adc #39 lsr lsr lsr sec adc #3 sta TEMP sta V2 pla pha ldx #COLOR_BOTH_DARKBLUE stx COLOR ldy #0 jsr hlin_double ldx #COLOR_BOTH_LIGHTBLUE stx COLOR ldx #2 jsr hlin_double_continue ldx #COLOR_BOTH_YELLOW stx COLOR ldx #2 jsr hlin_double_continue ldx GROUND_COLOR stx COLOR lda TEMP eor #$ff sec adc #35 tax jsr hlin_double_continue pla clc adc #2 cmp #40 bne sloped_left_loop beq done_base not_sloped_left: ;============================================= ; sloped right beach, on right side of island ;============================================= lda #3 and MAP_X cmp #3 bne not_sloped_right lda #10 sloped_right_loop: pha lsr ; temp=24+(A/4) lsr ; A/4 clc adc #24 sta TEMP sta V2 pla pha ldx GROUND_COLOR stx COLOR ldy #0 jsr hlin_double ldx #COLOR_BOTH_YELLOW stx COLOR ldx #2 jsr hlin_double_continue ldx #COLOR_BOTH_LIGHTBLUE stx COLOR ldx #2 jsr hlin_double_continue ldx #COLOR_BOTH_DARKBLUE stx COLOR lda TEMP eor #$ff sec adc #35 tax jsr hlin_double_continue ; color_equals(ground_color); ; hlin(PAGE2,0,temp,i); ; color_equals(COLOR_YELLOW); ; hlin_continue(2); ; color_equals(COLOR_LIGHTBLUE); ; hlin_continue(2); ; color_equals(COLOR_DARKBLUE); ; hlin_continue(36-temp); pla clc adc #$2 cmp #40 bne sloped_right_loop beq done_base ;============================== ; grassland ;============================== not_sloped_right: lda GROUND_COLOR sta COLOR lda #10 grassland_loop: ; draw line across screen ldy #40 ; from y=0 to y=10 sty V2 ldy #0 pha jsr hlin_double ; hlin y,V2 at A pla clc adc #2 cmp #40 bne grassland_loop done_base: ;============================== ; Draw North Shore ;============================== draw_north_shore: lda MAP_X cmp #4 bpl draw_south_shore ldx #COLOR_BOTH_DARKBLUE stx COLOR lda #39 sta V2 ldy #0 lda #10 jsr hlin_double ;============================== ; Draw South Shore ;============================== draw_south_shore: lda MAP_X cmp #12 bmi draw_mountains ldx #COLOR_BOTH_DARKBLUE stx COLOR lda #39 sta V2 ldy #0 lda #38 jsr hlin_double ; hlin 0,39 at 38 ldx #COLOR_BOTH_LIGHTBLUE stx COLOR lda #39 sta V2 lda #15 cmp MAP_X bne lblue_15 lda #35 sta V2 lblue_15: ldy #0 lda #12 cmp MAP_X bne lblue_12 ldy #6 lblue_12: lda #36 jsr hlin_double ; hlin 0,39 at 36 ldx #COLOR_BOTH_YELLOW stx COLOR lda #39 sta V2 lda #15 cmp MAP_X bne yellow_15 lda #32 sta V2 yellow_15: ldy #0 lda #12 cmp MAP_X bne yellow_12 ldy #8 yellow_12: lda #34 jsr hlin_double ; hlin 0,39 at 34 ;=============================== ; Draw Mountains ;=============================== draw_mountains: lda MAP_X and #3 cmp #2 bne done_drawing lda #0 mountain_loop: pha lda #>mountain sta INH lda #