lemm: modularize level code a bit

This commit is contained in:
Vince Weaver 2022-03-11 01:22:51 -05:00
parent 1836502a67
commit fdeee10096
6 changed files with 280 additions and 204 deletions

View File

@ -41,7 +41,8 @@ lemm.o: lemm.s zp.inc hardware.inc \
graphics/graphics_test.inc \
intro_level1.s update_time.s hgr_sprite.s draw_flames.s \
draw_door.s move_lemming.s draw_lemming.s \
interrupt_handler.s keyboard.s
interrupt_handler.s keyboard.s \
level1.s
ca65 -o lemm.o lemm.s -l lemm.lst

11
games/lemm/TODO Normal file
View File

@ -0,0 +1,11 @@
proper animations
ability to explode
particle effects
proper cursors
click on menu
wait a second after last lemming gone to exit
proper check for successful vs not end of level
ability to walk up hills
level 5
let's go sound

View File

@ -110,7 +110,7 @@ level1_win_text:
.byte 12, 3,"YOU RESCUED 100%",0
.byte 12, 4,"YOU NEEDED 10%",0
.byte 2, 6,"SUPERB! YOU RESCUED EVERY LEMMING ON",0
.byte 2, 7,"THAT LEVEL. CAN YOU DO IT AGAIN...",0
.byte 3, 7,"THAT LEVEL. CAN YOU DO IT AGAIN...",0
.byte 6,15,"YOUR ACCESS CODE FOR LEVEL 2",0
.byte 14,16,"IS WEH8ATARI",0
.byte 6,20,"PRESS RETURN FOR NEXT LEVEL",0

View File

@ -166,28 +166,6 @@ skip_all_checks:
lda $C083
lda $C083
; actually load it
; set up music
lda #0
sta CURRENT_CHUNK
sta DONE_PLAYING
sta BASE_FRAME_L
lda #$D0
sta CHUNK_NEXT_LOAD ; Load at $D0
jsr load_song_chunk
lda #$D0 ; music starts at $d000
sta CHUNK_NEXT_PLAY
sta BASE_FRAME_H
lda #1
sta LOOP
sta CURRENT_CHUNK
jsr mockingboard_patch ; patch to work in slots other than 4?
@ -213,189 +191,15 @@ zurg:
jsr wait_until_keypress
;=======================
; show title screen
;=======================
jsr intro_level1
;=======================
; Load Graphics
;=======================
lda #$20
sta HGR_PAGE
jsr hgr_make_tables
bit SET_GR
bit PAGE0
bit HIRES
bit FULLGR
lda #<level1_lzsa
sta getsrc_smc+1 ; LZSA_SRC_LO
lda #>level1_lzsa
sta getsrc_smc+2 ; LZSA_SRC_HI
lda #$20
jsr decompress_lzsa2_fast
lda #<level1_lzsa
sta getsrc_smc+1 ; LZSA_SRC_LO
lda #>level1_lzsa
sta getsrc_smc+2 ; LZSA_SRC_HI
lda #$40
jsr decompress_lzsa2_fast
;=======================
; Setup cursor
;=======================
lda #0
sta OVER_LEMMING
lda #10
sta CURSOR_X
lda #100
sta CURSOR_Y
;=======================
; Play "Let's Go"
; do level1
;=======================
play_level1:
jsr do_level1
;=======================
; start music
;=======================
; cli
;=======================
; init vars
;=======================
lda #0
sta LEVEL_OVER
sta DOOR_OPEN
sta FRAMEL
sta LOAD_NEXT_CHUNK
sta JOYSTICK_ENABLED
sta LEMMINGS_OUT
jsr update_lemmings_out
lda #1
sta LEMMINGS_TO_RELEASE
jsr save_bg_14x14 ; save initial bg
; set up time
lda #$5
sta TIME_MINUTES
lda #$00
sta TIME_SECONDS
sta TIMER_COUNT
;===================
;===================
; Main Loop
;===================
;===================
main_loop:
lda LOAD_NEXT_CHUNK ; see if we need to load next chunk
beq no_load_chunk ; outside IRQ to avoid glitch in music
jsr load_song_chunk
lda #0 ; reset
sta LOAD_NEXT_CHUNK
no_load_chunk:
lda DOOR_OPEN
bne door_is_open
jsr draw_door
door_is_open:
;======================
; release lemmings
;======================
lda LEMMINGS_TO_RELEASE
beq done_release_lemmings
lda DOOR_OPEN
beq done_release_lemmings
lda FRAMEL
and #$f
bne done_release_lemmings
inc LEMMINGS_OUT
jsr update_lemmings_out
lda #1
sta lemming_out
dec LEMMINGS_TO_RELEASE
done_release_lemmings:
jsr draw_flames
lda TIMER_COUNT
cmp #$50
bcc timer_not_yet
jsr update_time
lda #$0
sta TIMER_COUNT
timer_not_yet:
jsr erase_lemming
jsr move_lemmings
jsr draw_lemming
jsr handle_keypress
; jsr draw_pointer
lda #$ff
jsr wait
inc FRAMEL
lda LEVEL_OVER
bne level_over
jmp main_loop
level_over:
bit SET_TEXT
jsr disable_music
jsr outro_level1
loop_forever:
jmp loop_forever
jmp play_level1
@ -445,7 +249,8 @@ load_song_chunk_good:
.include "keyboard.s"
.include "joystick.s"
; .include "print_help.s"
.include "level1.s"
.include "gr_fast_clear.s"
.include "hgr_partial_save.s"

223
games/lemm/level1.s Normal file
View File

@ -0,0 +1,223 @@
do_level1:
;==============
; set up music
;==============
lda #0
sta CURRENT_CHUNK
sta DONE_PLAYING
sta BASE_FRAME_L
lda #$D0
sta CHUNK_NEXT_LOAD ; Load at $D0
jsr load_song_chunk
lda #$D0 ; music starts at $d000
sta CHUNK_NEXT_PLAY
sta BASE_FRAME_H
lda #1
sta LOOP
sta CURRENT_CHUNK
;=======================
; show title screen
;=======================
jsr intro_level1
;=======================
; Load Graphics
;=======================
lda #$20
sta HGR_PAGE
jsr hgr_make_tables
bit SET_GR
bit PAGE0
bit HIRES
bit FULLGR
lda #<level1_lzsa
sta getsrc_smc+1 ; LZSA_SRC_LO
lda #>level1_lzsa
sta getsrc_smc+2 ; LZSA_SRC_HI
lda #$20
jsr decompress_lzsa2_fast
lda #<level1_lzsa
sta getsrc_smc+1 ; LZSA_SRC_LO
lda #>level1_lzsa
sta getsrc_smc+2 ; LZSA_SRC_HI
lda #$40
jsr decompress_lzsa2_fast
;=======================
; Setup cursor
;=======================
lda #0
sta OVER_LEMMING
lda #10
sta CURSOR_X
lda #100
sta CURSOR_Y
;=======================
; Init Lemmings
;=======================
lda #0
sta lemming_out
lda #12
sta lemming_x
lda #45
sta lemming_y
lda #1
sta lemming_direction
lda #LEMMING_FALLING
sta lemming_status
;=======================
; Play "Let's Go"
;=======================
;=======================
; start music
;=======================
; cli
;=======================
; init vars
;=======================
lda #0
sta LEVEL_OVER
sta DOOR_OPEN
sta FRAMEL
sta LOAD_NEXT_CHUNK
sta JOYSTICK_ENABLED
sta LEMMINGS_OUT
jsr update_lemmings_out
lda #1
sta LEMMINGS_TO_RELEASE
jsr save_bg_14x14 ; save initial bg
; set up time
lda #$5
sta TIME_MINUTES
lda #$00
sta TIME_SECONDS
sta TIMER_COUNT
;===================
;===================
; Main Loop
;===================
;===================
main_loop:
lda LOAD_NEXT_CHUNK ; see if we need to load next chunk
beq no_load_chunk ; outside IRQ to avoid glitch in music
jsr load_song_chunk
lda #0 ; reset
sta LOAD_NEXT_CHUNK
no_load_chunk:
lda DOOR_OPEN
bne door_is_open
jsr draw_door
door_is_open:
;======================
; release lemmings
;======================
lda LEMMINGS_TO_RELEASE
beq done_release_lemmings
lda DOOR_OPEN
beq done_release_lemmings
lda FRAMEL
and #$f
bne done_release_lemmings
inc LEMMINGS_OUT
jsr update_lemmings_out
lda #1
sta lemming_out
dec LEMMINGS_TO_RELEASE
done_release_lemmings:
jsr draw_flames
lda TIMER_COUNT
cmp #$50
bcc timer_not_yet
jsr update_time
lda #$0
sta TIMER_COUNT
timer_not_yet:
jsr erase_lemming
jsr move_lemmings
jsr draw_lemming
jsr handle_keypress
; jsr draw_pointer
lda #$ff
jsr wait
inc FRAMEL
lda LEVEL_OVER
bne level_over
jmp main_loop
level_over:
bit SET_TEXT
jsr disable_music
jsr outro_level1
rts

View File

@ -5,7 +5,7 @@ move_lemmings:
lda lemming_out,Y
bne really_move_lemming
jmp done_move_lemming
jmp done_checking_lemming
really_move_lemming:
lda lemming_status
@ -100,8 +100,44 @@ done_digging:
done_move_lemming:
; see if beat level
lda lemming_y
cmp #116
bcc not_done_level
cmp #127
bcs not_done_level
lda lemming_x
cmp #31
bcc not_done_level
; done level
jsr remove_lemming
lda #1
sta LEVEL_OVER
not_done_level:
done_checking_lemming:
rts
;==========================
; remove lemming from game
remove_lemming:
lda #0
sta lemming_out
dec LEMMINGS_OUT
jsr update_lemmings_out
rts
lemming_direction:
.byte 1