duke: can shoot enemies now

This commit is contained in:
Vince Weaver 2020-12-16 14:44:50 -05:00
parent c33743ee43
commit 9b898272f2
5 changed files with 174 additions and 12 deletions

View File

@ -40,12 +40,14 @@ duke_start:
sta LEVEL_OVER
sta LASER_OUT
sta DUKE_XL
sta SCORE0
sta SCORE1
sta SCORE2
sta DUKE_FALLING
sta DUKE_SHOOTING
sta KICK_UP_DUST
sta DOOR_ACTIVATED
sta INVENTORY
lda #<enemy_data
sta ENEMY_DATAL
@ -53,11 +55,12 @@ duke_start:
sta ENEMY_DATAH
; FIXME: temporary
lda #INV_RED_KEY
sta INVENTORY
; lda INVENTORY
; ora #INV_RED_KEY
; sta INVENTORY
lda #$10
sta SCORE0
; lda #$10
; sta SCORE0
lda #1
sta FIREPOWER

View File

@ -1,5 +1,66 @@
NUM_ENEMIES = 4
;=======================
; laser enemies
;=======================
; see if laser hits any enemies
laser_enemies:
ldy #0
laser_enemies_loop:
; see if out
lda enemy_data+ENEMY_DATA_OUT,Y
beq done_laser_enemy
; get local tilemap co-ord
sec
lda enemy_data+ENEMY_DATA_TILEX,Y
sbc TILEMAP_X
sta TILE_TEMP
sec
lda enemy_data+ENEMY_DATA_TILEY,Y
sbc TILEMAP_Y
asl
asl
asl
asl
clc
adc TILE_TEMP
cmp LASER_TILE
bne done_laser_enemy
; hit something
hit_something:
lda #0
sta LASER_OUT
sta FRAMEL
; sta enemy_data+ENEMY_DATA_OUT,Y
lda #1
sta enemy_data+ENEMY_DATA_EXPLODING,Y
jsr enemy_noise
jsr inc_score_by_10
jmp exit_laser_enemy
done_laser_enemy:
tya
clc
adc #8
tay
cpy #(NUM_ENEMIES*8)
bne laser_enemies_loop
exit_laser_enemy:
rts
;=======================
; move enemy
@ -100,9 +161,36 @@ draw_enemies_loop:
sta YPOS
; see if exploding
lda enemy_data+ENEMY_DATA_EXPLODING,Y
beq draw_proper_enemy
draw_exploding_enemy:
asl
tax
lda enemy_explosion_sprites,X
sta INL
lda enemy_explosion_sprites+1,X
sta INH
lda FRAMEL
and #$3
bne done_exploding
; move to next frame
lda enemy_data+ENEMY_DATA_EXPLODING,Y
clc
adc #1
sta enemy_data+ENEMY_DATA_EXPLODING,Y
cmp #4
bne done_exploding
lda #0
sta enemy_data+ENEMY_DATA_OUT,Y
done_exploding:
jmp draw_enemy
; otherwise draw proper sprite
draw_proper_enemy:
lda enemy_data+ENEMY_DATA_TYPE,Y
tax
lda enemy_sprites,X
@ -110,6 +198,7 @@ draw_enemies_loop:
lda enemy_sprites+1,X
sta INH
draw_enemy:
tya
pha
@ -127,8 +216,10 @@ done_draw_enemy:
adc #8
tay
cpy #(NUM_ENEMIES*8)
bne draw_enemies_loop
beq exit_draw_enemy
jmp draw_enemies_loop
exit_draw_enemy:
rts
enemy_sprites:
@ -172,6 +263,11 @@ enemy_camera_sprite2:
.byte $76,$AA
.byte $A5,$f7
enemy_explosion_sprites:
.word enemy_explosion_sprite1
.word enemy_explosion_sprite1
.word enemy_explosion_sprite2
.word enemy_explosion_sprite3
enemy_explosion_sprite1:
.byte 2,2

View File

@ -1,5 +1,7 @@
; draw/move laser
; o/~ carrying a laser, down the road that I must travel o/~
; o/~ carrying a laser, in the darkness of the night o/~
;====================
; move laser
@ -13,15 +15,52 @@ move_laser:
adc LASER_DIRECTION
sta LASER_X
cmp #31
bcc not_too_far_right
lda #0
sta LASER_OUT
beq done_move_laser
laser_check_tiles:
; collision detect with tiles
not_too_far_right:
; laser location is roughly
; (y/4)*16 + (x/2) - 2
lda LASER_Y
lsr
lsr
asl
asl
asl
asl
sta LASER_TILE
lda LASER_X
lsr
clc
adc LASER_TILE
sec
sbc #2
sta LASER_TILE
ldx LASER_TILE
lda TILEMAP,X
cmp #HARD_TILES
bcs destroy_laser
laser_check_enemies:
; collision detect with enemies
jsr laser_enemies
; detect if off screen
laser_check_right:
lda LASER_X
cmp #31
bcc laser_check_left ; not_too_far_right
bcs destroy_laser
laser_check_left:
cmp #6
bcs done_move_laser
bcc destroy_laser
destroy_laser:
lda #0
sta LASER_OUT

View File

@ -101,3 +101,25 @@ done_buzzer_noise:
;======================
; enemy noise
enemy_noise:
lda SOUND_STATUS
bmi done_enemy_noise
lda #NOTE_A3
sta speaker_frequency
lda #20
sta speaker_duration
jsr speaker_tone
lda #NOTE_A4
sta speaker_frequency
lda #10
sta speaker_duration
jsr speaker_tone
done_enemy_noise:
rts

View File

@ -114,6 +114,8 @@ SUPPRESS_WALK = $98
ENEMY_DATAL = $99
ENEMY_DATAH = $9A
DOOR_ACTIVATED = $9B
LASER_TILE = $9C
TILE_TEMP = $9D
; done game puzzle state