junglejourney

changeset 44:5a120c2b6e89

Added projectile creation and movement.
author David Boddie <david@boddie.org.uk>
date Sun Aug 21 21:30:56 2011 +0200
parents 4d9da53995ae
children 2cf14232ef0f
files build.py mapcode.oph
diffstat 2 files changed, 367 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/build.py	Sun Aug 21 19:22:14 2011 +0200
     1.2 +++ b/build.py	Sun Aug 21 21:30:56 2011 +0200
     1.3 @@ -54,6 +54,8 @@
     1.4      #             4 and higher enemy - bits 3,4,5 are enemy type)
     1.5      #   n+1 counter/direction
     1.6      #       (player: bits 1,2 are direction, bit 0 is animation
     1.7 +    #        projectile: bits 3,4 are direction, bits 1,2 are type,
     1.8 +    #                    bit 0 is animation
     1.9      #        enemy:  bits 2,3 are direction, bits 1,0 are animation
    1.10      #        emerging, explosion: bits 4,5,6 are enemy type for emerging,
    1.11      #                             bit 3 is type 0=emerge,1=explode,
    1.12 @@ -77,7 +79,8 @@
    1.13      # 33F0 starting room (i, j)
    1.14      # 33F2 current room (i, j)
    1.15      # 33F4 lives
    1.16 -    # 33F6 score (four bytes)
    1.17 +    # 33F6 score (three bytes)
    1.18 +    # 33F9 projectile type
    1.19      # 33FA level
    1.20      # 33FB palette workspace (enough for one 5 byte palette entry)
    1.21      #       33FE is also motion counter when in a room
     2.1 --- a/mapcode.oph	Sun Aug 21 19:22:14 2011 +0200
     2.2 +++ b/mapcode.oph	Sun Aug 21 21:30:56 2011 +0200
     2.3 @@ -887,10 +887,11 @@
     2.4  
     2.5  plot8x8_y0:             ; $70,$71=source address
     2.6                          ; $72,$73=destination address
     2.7 -    ldy #31
     2.8 +    ldy #15
     2.9  
    2.10      plotloop8x8_y0_0:
    2.11          lda ($70),y
    2.12 +        eor ($72),y
    2.13          sta ($72),y
    2.14          dey
    2.15          bpl plotloop8x8_y0_0
    2.16 @@ -1032,6 +1033,8 @@
    2.17  emerge_explode_chars_low: .byte $00,$40,$80,$c0,$00,$40,$80,$c0
    2.18  emerge_explode_chars_high: .byte $41,$41,$41,$41,$42,$42,$42,$42
    2.19  
    2.20 +projectile_chars_low: .byte $40,$50,$60,$70,$80,$90,$a0,$b0
    2.21 +
    2.22  unplot_character:       ; $74,$75=character address
    2.23  
    2.24      lda $82
    2.25 @@ -1155,6 +1158,14 @@
    2.26  
    2.27      ; Plot 8x8 sprites (projectiles)
    2.28  
    2.29 +    lda $80
    2.30 +    and #7
    2.31 +    tax
    2.32 +    lda projectile_chars_low,x
    2.33 +    sta $70
    2.34 +    lda #$36
    2.35 +    sta $71
    2.36 +
    2.37      ; Use the dy value to determine which plotting routine to use.
    2.38  
    2.39      ldy #0
    2.40 @@ -1447,9 +1458,9 @@
    2.41      cmp #0
    2.42      beq move_player_leave_room_left
    2.43  
    2.44 -    sec
    2.45 -    sbc #1                      ; x - 1
    2.46 +    clc
    2.47      tay
    2.48 +    dey                         ; x - 1
    2.49      lda $3302                   ; load the y offset
    2.50      tax                         ; as an index
    2.51      lda room_row_offsets_low,x  ; read the address of the row
    2.52 @@ -1532,8 +1543,8 @@
    2.53      beq move_player_leave_room_right
    2.54  
    2.55      clc
    2.56 -    adc #1                      ; x + 1
    2.57      tay
    2.58 +    iny                         ; x + 1
    2.59      lda $3302                   ; load the y offset
    2.60      tax                         ; as an index
    2.61      lda room_row_offsets_low,x  ; read the address of the row
    2.62 @@ -1700,8 +1711,8 @@
    2.63      beq move_player_leave_room_down
    2.64  
    2.65      clc
    2.66 -    adc #1                      ; y + 1
    2.67      tax
    2.68 +    inx                         ; y + 1
    2.69      lda $3304                   ; load the x offset
    2.70      tay
    2.71      lda room_row_offsets_low,x  ; read the address of the row
    2.72 @@ -1761,6 +1772,69 @@
    2.73      rts                         ; player has left the room
    2.74  
    2.75      move_player_not_down_key:
    2.76 +
    2.77 +    ; Handle the fire key.
    2.78 +
    2.79 +    ldx #182            ; (Return)
    2.80 +    jsr check_key
    2.81 +    cpy #255
    2.82 +    bne move_player_not_fire_key
    2.83 +
    2.84 +    lda $3306
    2.85 +    cmp #0
    2.86 +    bne move_player_not_fire_key
    2.87 +
    2.88 +    jmp create_projectile   ; optimise away the rts
    2.89 +
    2.90 +    move_player_not_fire_key:
    2.91 +    clc
    2.92 +    rts
    2.93 +
    2.94 +create_projectile:
    2.95 +
    2.96 +    lda #2
    2.97 +    sta $3306
    2.98 +
    2.99 +    lda $3301
   2.100 +    and #$06        ; copy the direction information
   2.101 +    asl
   2.102 +    asl
   2.103 +    ora $33f9       ; apply the projectile type
   2.104 +    sta $3307
   2.105 +
   2.106 +    lda $3303       ; dy
   2.107 +    cmp #4
   2.108 +    bpl create_projectile_below
   2.109 +
   2.110 +    clc
   2.111 +    adc #2
   2.112 +    sta $3309       ; dy + 2
   2.113 +    lda $3302       ; y
   2.114 +    sta $3308
   2.115 +    jmp create_projectile_continue
   2.116 +
   2.117 +    create_projectile_below:
   2.118 +    sec
   2.119 +    sbc #4
   2.120 +    sta $3309       ; dy - 4
   2.121 +    clc
   2.122 +    lda $3302       ; y
   2.123 +    adc #1
   2.124 +    sta $3308
   2.125 +
   2.126 +    create_projectile_continue:
   2.127 +    lda $3304       ; x
   2.128 +    sta $330a
   2.129 +
   2.130 +    lda $3305       ; dx
   2.131 +    sta $330b
   2.132 +
   2.133 +    lda #$06
   2.134 +    sta $74
   2.135 +    lda #$33
   2.136 +    sta $75
   2.137 +    jsr plot_character
   2.138 +
   2.139      clc
   2.140      rts
   2.141  
   2.142 @@ -2301,7 +2375,6 @@
   2.143      move_enemy_leftwards:
   2.144      lda #1
   2.145      sta $8e
   2.146 -    ;jmp move_enemy_with_direction
   2.147  
   2.148      move_enemy_with_direction:
   2.149      clc
   2.150 @@ -2344,7 +2417,284 @@
   2.151      move_enemy_exit:
   2.152      clc
   2.153      rts
   2.154 +
   2.155 +move_projectile_left:
   2.156 +
   2.157 +    lda $330b
   2.158 +    cmp #0
   2.159 +    beq move_projectile_left_check_x
   2.160 +
   2.161 +    dec $330b
   2.162 +    clc
   2.163 +    rts
   2.164 +
   2.165 +    move_projectile_left_check_x:
   2.166 +
   2.167 +    lda $330a
   2.168 +    cmp #0
   2.169 +    beq move_projectile_left_exit
   2.170 +
   2.171 +    tay
   2.172 +    dey                         ; x - 1
   2.173 +    ldx $3308                   ; y
   2.174 +    lda room_row_offsets_low,x  ; read the address of the row
   2.175 +    sta $70
   2.176 +    lda #$57
   2.177 +    sta $71
   2.178 +    lda ($70),y                 ; load the tile to the left
   2.179 +
   2.180 +    cmp #0
   2.181 +    bne move_projectile_left_exit
   2.182 +
   2.183 +    lda $3309                   ; dy
   2.184 +    cmp #5
   2.185 +    bmi move_projectile_allow_left
   2.186 +
   2.187 +    clc                         ; dy > 4 so we need to check another tile
   2.188 +    lda $70
   2.189 +    adc #10
   2.190 +    sta $70
   2.191 +    lda ($70),y                 ; load the tile below and to the left
   2.192 +
   2.193 +    cmp #0
   2.194 +    bne move_projectile_left_exit
   2.195 +
   2.196 +    move_projectile_allow_left:
   2.197 +
   2.198 +    sty $330a       ; x
   2.199 +    lda #3
   2.200 +    sta $330b       ; dx = 3
   2.201 +
   2.202 +    move_projectile_left_exit:
   2.203 +    clc
   2.204 +    rts
   2.205 +
   2.206 +move_projectile_right:
   2.207 +
   2.208 +    ; Fire right.
   2.209 +
   2.210 +    lda $330b
   2.211 +    cmp #2
   2.212 +    beq move_projectile_right_check_x
   2.213 +    cmp #3
   2.214 +    beq move_projectile_right_tile
   2.215 +
   2.216 +    inc $330b
   2.217 +    clc
   2.218 +    rts
   2.219 +
   2.220 +    move_projectile_right_check_x:
   2.221 +
   2.222 +    lda $330a       ; x
   2.223 +    cmp #9
   2.224 +    beq move_projectile_right_exit
   2.225 +
   2.226 +    clc
   2.227 +    tay
   2.228 +    iny                         ; x + 1
   2.229 +    ldx $3308                   ; y
   2.230 +    lda room_row_offsets_low,x  ; read the address of the row
   2.231 +    sta $70
   2.232 +    lda #$57
   2.233 +    sta $71
   2.234 +    lda ($70),y                 ; load the tile to the right
   2.235 +
   2.236 +    cmp #0
   2.237 +    bne move_projectile_right_exit
   2.238 +
   2.239 +    lda $3309                   ; dy
   2.240 +    cmp #5
   2.241 +    bmi move_projectile_allow_right
   2.242 +
   2.243 +    clc                         ; dy > 4 so we need to check another tile
   2.244 +    lda $70
   2.245 +    adc #10
   2.246 +    sta $70
   2.247 +    lda ($70),y                 ; load the tile below and to the right
   2.248 +
   2.249 +    cmp #0
   2.250 +    bne move_projectile_right_exit
   2.251 +
   2.252 +    move_projectile_allow_right:
   2.253 +
   2.254 +    inc $330b       ; dx
   2.255 +    clc
   2.256 +    rts
   2.257 +
   2.258 +    move_projectile_right_tile:
   2.259 +
   2.260 +    inc $330a       ; x
   2.261 +    lda #0
   2.262 +    sta $330b       ; dx
   2.263 +
   2.264 +    move_projectile_right_exit:
   2.265 +    clc
   2.266 +    rts
   2.267 +
   2.268 +move_projectile_up:
   2.269 +
   2.270 +    lda $3309           ; read dy
   2.271 +    cmp #0
   2.272 +    beq move_projectile_up_check_y
   2.273 +
   2.274 +    dec $3309
   2.275 +    clc
   2.276 +    rts
   2.277      
   2.278 +    move_projectile_up_check_y:     ; Check the y offset.
   2.279 +
   2.280 +    lda $3308
   2.281 +    cmp #0
   2.282 +    beq move_projectile_up_exit
   2.283 +
   2.284 +    tax                         ; use the y offset as an index
   2.285 +    dex                         ; y - 1
   2.286 +    lda $330a                   ; load the x offset
   2.287 +    tay
   2.288 +    lda room_row_offsets_low,x  ; read the address of the row
   2.289 +    sta $70
   2.290 +    lda #$57
   2.291 +    sta $71
   2.292 +    lda ($70),y                 ; load the tile above
   2.293 +
   2.294 +    cmp #0
   2.295 +    bne move_projectile_up_exit
   2.296 +
   2.297 +    lda $330b                   ; dx
   2.298 +    cmp #3
   2.299 +    bmi move_projectile_allow_up
   2.300 +
   2.301 +    clc                     ; dx > 2 so we need to check another tile
   2.302 +    iny
   2.303 +    lda ($70),y             ; load the tile above and to the right
   2.304 +
   2.305 +    cmp #0
   2.306 +    bne move_projectile_up_exit
   2.307 +
   2.308 +    move_projectile_allow_up:
   2.309 +    txa
   2.310 +    sta $3308               ; store the new room y offset
   2.311 +    lda #5
   2.312 +    sta $3309               ; dy = 5
   2.313 +
   2.314 +    move_projectile_up_exit:
   2.315 +    clc
   2.316 +    rts
   2.317 +
   2.318 +move_projectile_down:
   2.319 +
   2.320 +    lda $3309                   ; read dy
   2.321 +    cmp #4
   2.322 +    beq move_projectile_down_check_y
   2.323 +    cmp #5
   2.324 +    beq move_projectile_down_tile
   2.325 +
   2.326 +    inc $3309                   ; 0 < dy < 5
   2.327 +    clc
   2.328 +    rts
   2.329 +    
   2.330 +    move_projectile_down_check_y:  ; Check the y offset.
   2.331 +
   2.332 +    lda $3308
   2.333 +    cmp #9
   2.334 +    beq move_projectile_down_exit
   2.335 +
   2.336 +    clc
   2.337 +    tax
   2.338 +    inx                         ; y + 1
   2.339 +    lda $330a                   ; load the x offset
   2.340 +    tay
   2.341 +    lda room_row_offsets_low,x  ; read the address of the row
   2.342 +    sta $70
   2.343 +    lda #$57
   2.344 +    sta $71
   2.345 +    lda ($70),y                 ; load the tile below
   2.346 +
   2.347 +    cmp #0
   2.348 +    bne move_projectile_down_exit
   2.349 +
   2.350 +    lda $330b                   ; dx
   2.351 +    cmp #3
   2.352 +    bmi move_projectile_allow_down
   2.353 +
   2.354 +    clc                         ; dx > 2 so we need to check another tile
   2.355 +    iny
   2.356 +    lda ($70),y                 ; load the tile below and to the right
   2.357 +
   2.358 +    cmp #0
   2.359 +    bne move_projectile_down_exit
   2.360 +
   2.361 +    move_projectile_allow_down:
   2.362 +
   2.363 +    inc $3309                   ; update dy
   2.364 +    clc
   2.365 +    rts
   2.366 +
   2.367 +    move_projectile_down_tile:
   2.368 +
   2.369 +    inc $3308                   ; store the new room y offset
   2.370 +    lda #0
   2.371 +    sta $3309                   ; dy = 0
   2.372 +
   2.373 +    move_projectile_down_exit:
   2.374 +    clc
   2.375 +    rts
   2.376 +
   2.377 +move_projectile_animate:
   2.378 +
   2.379 +    lda $3307
   2.380 +    eor #1
   2.381 +    sta $3307
   2.382 +    rts
   2.383 +
   2.384 +move_projectile:
   2.385 +
   2.386 +    lda $3306
   2.387 +    cmp #0
   2.388 +    beq move_projectile_exit
   2.389 +
   2.390 +    lda #$06
   2.391 +    sta $74
   2.392 +    lda #$33
   2.393 +    sta $75
   2.394 +    jsr unplot_character
   2.395 +
   2.396 +    lda $3307
   2.397 +    and #$18            ; direction
   2.398 +
   2.399 +    cmp #0
   2.400 +    bne move_projectile_not_left
   2.401 +
   2.402 +    jsr move_projectile_left
   2.403 +    jmp move_projectile_toggle
   2.404 +
   2.405 +    move_projectile_not_left:
   2.406 +    cmp #$08
   2.407 +    bne move_projectile_not_right
   2.408 +
   2.409 +    jsr move_projectile_right
   2.410 +    jmp move_projectile_toggle
   2.411 +
   2.412 +    move_projectile_not_right:
   2.413 +    cmp #$10
   2.414 +    bne move_projectile_not_up
   2.415 +
   2.416 +    jsr move_projectile_up
   2.417 +    jmp move_projectile_toggle
   2.418 +
   2.419 +    move_projectile_not_up:
   2.420 +    cmp #$18
   2.421 +    bne move_projectile_toggle
   2.422 +
   2.423 +    jsr move_projectile_down
   2.424 +
   2.425 +    move_projectile_toggle:
   2.426 +    jsr move_projectile_animate
   2.427 +    jmp plot_character          ; optimise away the rts
   2.428 +
   2.429 +    move_projectile_exit:
   2.430 +    clc
   2.431 +    rts
   2.432  
   2.433  move_characters:
   2.434  
   2.435 @@ -2371,6 +2721,7 @@
   2.436          move_characters_read_character:
   2.437          clc
   2.438  
   2.439 +        move_characters_not_projectile:
   2.440          cmp #3
   2.441          bne move_characters_not_emerge_explode
   2.442  
   2.443 @@ -2522,6 +2873,10 @@
   2.444      lda #0
   2.445      sta $33fa
   2.446  
   2.447 +    ; Set the projectile type.
   2.448 +    lda #0
   2.449 +    sta $33f9
   2.450 +
   2.451      ; Set starting room and current room.
   2.452  
   2.453      lda #5
   2.454 @@ -2592,6 +2947,8 @@
   2.455                  jsr reset_unplot_buffer
   2.456                  jsr reset_plot_buffer
   2.457                  jsr move_characters
   2.458 +                jsr move_projectile
   2.459 +
   2.460                  jsr move_player
   2.461                  bcs after_room_loop
   2.462