junglejourney

changeset 22:2315e8b48a4a

Fixed horizontal movement checks and added vertical movement.
author David Boddie <david@boddie.org.uk>
date Mon Aug 15 00:21:45 2011 +0200
parents a8765ab185b8
children 774827fce02a
files mapcode.oph
diffstat 1 files changed, 208 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/mapcode.oph	Sun Aug 14 23:17:41 2011 +0200
     1.2 +++ b/mapcode.oph	Mon Aug 15 00:21:45 2011 +0200
     1.3 @@ -859,6 +859,7 @@
     1.4          ; dy
     1.5          iny
     1.6          lda ($74),y
     1.7 +        sta $76
     1.8          tax
     1.9          lda screen_subrows_low,x
    1.10          adc $72
    1.11 @@ -891,8 +892,7 @@
    1.12  
    1.13          ; Use the dy value to determine which plotting routine to use.
    1.14  
    1.15 -        iny
    1.16 -        lda ($74),y
    1.17 +        lda $76
    1.18          and #1
    1.19          bne plot_characters_plot_player1
    1.20  
    1.21 @@ -903,13 +903,22 @@
    1.22          clc
    1.23          jsr plot8x24_y1
    1.24  
    1.25 -        plot_characters_next:
    1.26 -        clc
    1.27 -
    1.28          ; Examine the next character.
    1.29  
    1.30          iny
    1.31 -        bcc plot_characters_loop
    1.32 +        cpy #$f0
    1.33 +        bmi plot_characters_loop
    1.34 +
    1.35 +        plot_characters_next:
    1.36 +        clc
    1.37 +        
    1.38 +        ; Examine the next character.
    1.39 +        tya
    1.40 +        adc #6
    1.41 +        tay
    1.42 +
    1.43 +        cpy #$f0
    1.44 +        bmi plot_characters_loop
    1.45  
    1.46      plot_characters_exit:
    1.47      clc
    1.48 @@ -923,9 +932,9 @@
    1.49      ; Set the direction and toggle the animation bit.
    1.50  
    1.51      lda $3301
    1.52 -    and #1      ; remove direction information (result is 0)
    1.53 +    and #1
    1.54      eor #1      ; toggle animation flag
    1.55 -    sta $3301
    1.56 +    sta $3301   ; left (directional bits are 0)
    1.57      rts
    1.58  
    1.59  animate_player_right:
    1.60 @@ -939,6 +948,28 @@
    1.61      sta $3301
    1.62      rts
    1.63  
    1.64 +animate_player_up:
    1.65 +
    1.66 +    ; Set the direction and toggle the animation bit.
    1.67 +
    1.68 +    lda $3301
    1.69 +    and #1      ; remove direction information (result is 0)
    1.70 +    eor #1      ; toggle animation flag
    1.71 +    ora #4      ; up
    1.72 +    sta $3301
    1.73 +    rts
    1.74 +
    1.75 +animate_player_down:
    1.76 +
    1.77 +    ; Set the direction and toggle the animation bit.
    1.78 +
    1.79 +    lda $3301
    1.80 +    and #1      ; remove direction information (result is 0)
    1.81 +    eor #1      ; toggle animation flag
    1.82 +    ora #6      ; down
    1.83 +    sta $3301
    1.84 +    rts
    1.85 +
    1.86  move_player:
    1.87  
    1.88      ; Handle the left key.
    1.89 @@ -978,9 +1009,12 @@
    1.90  
    1.91      lda $3303               ; dy
    1.92      cmp #0
    1.93 -    bne move_player_allow_left
    1.94 -    lda $70
    1.95 +    beq move_player_allow_left
    1.96 +
    1.97 +    clc
    1.98 +    lda $70                 ; dy > 0 so we need to check another tile
    1.99      adc #10
   1.100 +    sta $70
   1.101      lda ($70),y             ; load the tile below and to the left
   1.102  
   1.103      cmp #0
   1.104 @@ -1050,9 +1084,12 @@
   1.105  
   1.106      lda $3303                   ; dy
   1.107      cmp #0
   1.108 -    bne move_player_allow_right
   1.109 +    beq move_player_allow_right
   1.110 +
   1.111 +    clc                         ; dy > 0 so we need to check another tile
   1.112      lda $70
   1.113      adc #10
   1.114 +    sta $70
   1.115      lda ($70),y                 ; load the tile below and to the right
   1.116  
   1.117      cmp #0
   1.118 @@ -1096,6 +1133,166 @@
   1.119                                  ; rts)
   1.120  
   1.121      move_player_not_right_key:
   1.122 +
   1.123 +    ; Handle the up key.
   1.124 +
   1.125 +    ldx #183            ; (:)
   1.126 +    jsr check_key
   1.127 +    cpy #255
   1.128 +    bne move_player_not_up_key
   1.129 +
   1.130 +    lda $3303           ; read dy
   1.131 +    cmp #0
   1.132 +    beq move_player_up_check_y
   1.133 +
   1.134 +    dec $3303
   1.135 +    clc
   1.136 +    jmp animate_player_up       ; optimise away the rts
   1.137 +    
   1.138 +    move_player_up_check_y:     ; Check the y offset.
   1.139 +
   1.140 +    lda $3302
   1.141 +    cmp #0
   1.142 +    beq move_player_leave_room_up
   1.143 +
   1.144 +    sec
   1.145 +    sbc #1                      ; y - 1
   1.146 +    tax                         ; use the y offset as an index
   1.147 +    lda $3304                   ; load the x offset
   1.148 +    tay
   1.149 +    lda room_row_offsets_low,x  ; read the address of the row
   1.150 +    sta $70
   1.151 +    lda #$57
   1.152 +    sta $71
   1.153 +    lda ($70),y                 ; load the tile above
   1.154 +
   1.155 +    cmp #0
   1.156 +    bne move_player_not_up_key
   1.157 +
   1.158 +    lda $3305                   ; dx
   1.159 +    cmp #3
   1.160 +    bmi move_player_allow_up
   1.161 +
   1.162 +    clc                     ; dx > 2 so we need to check another tile
   1.163 +    iny
   1.164 +    lda ($70),y             ; load the tile above and to the right
   1.165 +
   1.166 +    cmp #0
   1.167 +    bne move_player_not_up_key
   1.168 +
   1.169 +    move_player_allow_up:
   1.170 +    txa
   1.171 +    sta $3302               ; store the new room y offset
   1.172 +    lda #5
   1.173 +    sta $3303               ; dy = 5
   1.174 +    clc
   1.175 +    jmp animate_player_up   ; optimise away the rts
   1.176 +
   1.177 +    move_player_leave_room_up:
   1.178 +    sec
   1.179 +    lda $33f2
   1.180 +    sbc #1
   1.181 +    sta $33f2
   1.182 +    clc
   1.183 +
   1.184 +    ; Set the player's position on the bottom of the screen.
   1.185 +
   1.186 +    lda #9      ; y = 9
   1.187 +    sta $3302
   1.188 +    lda #0      ; dy = 0
   1.189 +    sta $3303
   1.190 +
   1.191 +    sec                     ; indicate to the calling routine that the player
   1.192 +    jmp animate_player_up   ; has left the room (optimising away the rts)
   1.193 +
   1.194 +    move_player_not_up_key:
   1.195 +
   1.196 +    ; Handle the down key.
   1.197 +
   1.198 +    ldx #151            ; (/)
   1.199 +    jsr check_key
   1.200 +    cpy #255
   1.201 +    bne move_player_not_down_key
   1.202 +
   1.203 +    lda $3303                   ; read dy
   1.204 +    cmp #0
   1.205 +    beq move_player_down_check_y
   1.206 +    cmp #5
   1.207 +    beq move_player_down_check_y
   1.208 +
   1.209 +    inc $3303                   ; 0 < dy < 5
   1.210 +    clc
   1.211 +    jmp animate_player_down    ; optimise away the rts
   1.212 +    
   1.213 +    move_player_down_check_y:  ; Check the y offset.
   1.214 +
   1.215 +    lda $3302
   1.216 +    cmp #9
   1.217 +    beq move_player_leave_room_down
   1.218 +
   1.219 +    clc
   1.220 +    adc #1                      ; y + 1
   1.221 +    tax
   1.222 +    lda $3304                   ; load the x offset
   1.223 +    tay
   1.224 +    lda room_row_offsets_low,x  ; read the address of the row
   1.225 +    sta $70
   1.226 +    lda #$57
   1.227 +    sta $71
   1.228 +    lda ($70),y                 ; load the tile below
   1.229 +
   1.230 +    cmp #0
   1.231 +    bne move_player_not_down_key
   1.232 +
   1.233 +    lda $3305                   ; dx
   1.234 +    cmp #3
   1.235 +    bmi move_player_allow_down
   1.236 +
   1.237 +    clc                         ; dx > 2 so we need to check another tile
   1.238 +    iny
   1.239 +    lda ($70),y                 ; load the tile below and to the right
   1.240 +
   1.241 +    cmp #0
   1.242 +    bne move_player_not_down_key
   1.243 +
   1.244 +    move_player_allow_down:
   1.245 +
   1.246 +    lda $3303                   ; only if the player is leaving the tile
   1.247 +    cmp #5                      ; do we update the y offset
   1.248 +    beq move_player_down_tile
   1.249 +
   1.250 +    inc $3303                   ; otherwise, we update dy instead
   1.251 +    clc
   1.252 +    jmp animate_player_down     ; optimise away the rts
   1.253 +
   1.254 +    move_player_down_tile:
   1.255 +
   1.256 +    txa
   1.257 +    sta $3302                   ; store the new room y offset
   1.258 +    lda #0
   1.259 +    sta $3303                   ; dy = 0
   1.260 +    clc
   1.261 +    jmp animate_player_down     ; optimise away the rts
   1.262 +
   1.263 +    move_player_leave_room_down:
   1.264 +    clc
   1.265 +    lda $33f2
   1.266 +    adc #1
   1.267 +    sta $33f2
   1.268 +    clc
   1.269 +
   1.270 +    ; Set the player's position on the top of the screen.
   1.271 +
   1.272 +    lda #0      ; y = 0
   1.273 +    sta $3302
   1.274 +    lda #0      ; dy = 0
   1.275 +    sta $3303
   1.276 +
   1.277 +    sec                         ; indicate to the calling routine that the
   1.278 +    jmp animate_player_down     ; player has left the room (optimising away the
   1.279 +                                ; rts)
   1.280 +
   1.281 +    move_player_not_down_key:
   1.282      clc
   1.283      rts
   1.284