junglejourney
changeset 21:a8765ab185b8
Added right directional player movement.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Aug 14 23:17:41 2011 +0200 |
| parents | df2cb7f1ff50 |
| children | 2315e8b48a4a |
| files | mapcode.oph |
| diffstat | 1 files changed, 101 insertions(+), 9 deletions(-) [+] |
line diff
1.1 --- a/mapcode.oph Sun Aug 14 20:58:00 2011 +0200 1.2 +++ b/mapcode.oph Sun Aug 14 23:17:41 2011 +0200 1.3 @@ -928,31 +928,42 @@ 1.4 sta $3301 1.5 rts 1.6 1.7 +animate_player_right: 1.8 + 1.9 + ; Set the direction and toggle the animation bit. 1.10 + 1.11 + lda $3301 1.12 + and #1 ; remove direction information (result is 0) 1.13 + eor #1 ; toggle animation flag 1.14 + ora #2 ; right 1.15 + sta $3301 1.16 + rts 1.17 + 1.18 move_player: 1.19 1.20 - ldx #158 ; handle left key 1.21 + ; Handle the left key. 1.22 + 1.23 + ldx #158 ; (Z) 1.24 jsr check_key 1.25 cpy #255 1.26 bne move_player_not_left_key 1.27 1.28 - ; Handle the left key. 1.29 - 1.30 lda $3305 ; read dx 1.31 cmp #0 1.32 - beq move_player_check_x 1.33 + beq move_player_left_check_x 1.34 1.35 dec $3305 1.36 clc 1.37 jmp animate_player_left ; optimise away the rts 1.38 1.39 - move_player_check_x: ; Check the x offset. 1.40 + move_player_left_check_x: ; Check the x offset. 1.41 1.42 lda $3304 1.43 cmp #0 1.44 beq move_player_leave_room_left 1.45 1.46 sec 1.47 - sbc #1 ; x - 1 1.48 + sbc #1 ; x - 1 1.49 tay 1.50 lda $3302 ; load the y offset 1.51 tax ; as an index 1.52 @@ -998,12 +1009,93 @@ 1.53 sta $3305 1.54 1.55 sec ; indicate to the calling routine that the player 1.56 - jsr animate_player_left ; has left the room 1.57 - rts 1.58 + jmp animate_player_left ; has left the room (optimising away the rts) 1.59 1.60 move_player_not_left_key: 1.61 1.62 - move_player_not_up_key: 1.63 + ; Handle the right key. 1.64 + 1.65 + ldx #189 ; (X) 1.66 + jsr check_key 1.67 + cpy #255 1.68 + bne move_player_not_right_key 1.69 + 1.70 + lda $3305 ; read dx 1.71 + cmp #2 1.72 + bpl move_player_right_check_x 1.73 + 1.74 + inc $3305 1.75 + clc 1.76 + jmp animate_player_right ; optimise away the rts 1.77 + 1.78 + move_player_right_check_x: ; Check the x offset. 1.79 + 1.80 + lda $3304 1.81 + cmp #9 1.82 + beq move_player_leave_room_right 1.83 + 1.84 + clc 1.85 + adc #1 ; x + 1 1.86 + tay 1.87 + lda $3302 ; load the y offset 1.88 + tax ; as an index 1.89 + lda room_row_offsets_low,x ; read the address of the row 1.90 + sta $70 1.91 + lda #$57 1.92 + sta $71 1.93 + lda ($70),y ; load the tile to the right 1.94 + 1.95 + cmp #0 1.96 + bne move_player_not_right_key 1.97 + 1.98 + lda $3303 ; dy 1.99 + cmp #0 1.100 + bne move_player_allow_right 1.101 + lda $70 1.102 + adc #10 1.103 + lda ($70),y ; load the tile below and to the right 1.104 + 1.105 + cmp #0 1.106 + bne move_player_not_right_key 1.107 + 1.108 + move_player_allow_right: 1.109 + 1.110 + lda $3305 ; only if the player is leaving the tile 1.111 + cmp #3 ; do we update the x offset 1.112 + beq move_player_right_tile 1.113 + 1.114 + inc $3305 ; otherwise, we update dx instead 1.115 + clc 1.116 + jmp animate_player_right ; optimise away the rts 1.117 + 1.118 + move_player_right_tile: 1.119 + 1.120 + tya 1.121 + sta $3304 ; store the new room x offset 1.122 + lda #0 1.123 + sta $3305 ; dx = 0 1.124 + clc 1.125 + jmp animate_player_right ; optimise away the rts 1.126 + 1.127 + move_player_leave_room_right: 1.128 + clc 1.129 + lda $33f3 1.130 + adc #1 1.131 + sta $33f3 1.132 + clc 1.133 + 1.134 + ; Set the player's position on the left of the screen. 1.135 + 1.136 + lda #0 ; x = 0 1.137 + sta $3304 1.138 + lda #0 ; dx = 0 1.139 + sta $3305 1.140 + 1.141 + sec ; indicate to the calling routine that the 1.142 + jmp animate_player_right ; player has left the room (optimising away the 1.143 + ; rts) 1.144 + 1.145 + move_player_not_right_key: 1.146 clc 1.147 rts 1.148
