junglejourney
changeset 35:dfc945305302
Added basic enemy movement.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Aug 21 03:09:04 2011 +0200 |
| parents | 125080c5c19b |
| children | 4dfd1a194717 |
| files | mapcode.oph |
| diffstat | 1 files changed, 436 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/mapcode.oph Sun Aug 21 01:25:03 2011 +0200 1.2 +++ b/mapcode.oph Sun Aug 21 03:09:04 2011 +0200 1.3 @@ -1607,9 +1607,8 @@ 1.4 cmp #0 1.5 beq move_player_leave_room_up 1.6 1.7 - sec 1.8 - sbc #1 ; y - 1 1.9 tax ; use the y offset as an index 1.10 + dex ; y - 1 1.11 lda $3304 ; load the x offset 1.12 tay 1.13 lda room_row_offsets_low,x ; read the address of the row 1.14 @@ -1878,6 +1877,433 @@ 1.15 clc 1.16 rts 1.17 1.18 +animate_enemy_left: ; $74,$75=character address 1.19 + 1.20 + ; Set the direction and toggle the animation bit. 1.21 + 1.22 + ldy #1 1.23 + lda ($74),y 1.24 + and #1 1.25 + eor #1 ; toggle animation flag 1.26 + sta ($74),y ; left (directional bits are 0) 1.27 + 1.28 + jsr plot_character 1.29 + rts 1.30 + 1.31 +move_enemy_left: ; $74,$75=character address 1.32 + 1.33 + ldy #5 1.34 + lda ($74),y ; read dx 1.35 + cmp #0 1.36 + beq move_enemy_left_check_x 1.37 + 1.38 + sta $81 ; temporary 1.39 + jsr unplot_character ; unplot the enemy character 1.40 + dec $81 1.41 + lda $81 1.42 + ldy #5 1.43 + sta ($74),y ; dx 1.44 + clc 1.45 + jmp animate_enemy_left ; optimise away the rts 1.46 + 1.47 + move_enemy_left_check_x: 1.48 + 1.49 + ; Check the x offset. 1.50 + 1.51 + ldy #4 1.52 + lda ($74),y ; x 1.53 + cmp #0 1.54 + beq move_enemy_left_exit 1.55 + 1.56 + sec 1.57 + sbc #1 ; x - 1 1.58 + sta $81 ; temporary 1.59 + ldy #2 1.60 + lda ($74),y ; load the y offset 1.61 + tax ; as an index 1.62 + lda room_row_offsets_low,x ; read the address of the row 1.63 + sta $70 1.64 + lda #$57 1.65 + sta $71 1.66 + ldy $81 ; temporary (x - 1) 1.67 + lda ($70),y ; load the tile to the left 1.68 + 1.69 + cmp #0 1.70 + bne move_enemy_left_exit 1.71 + 1.72 + ldy #3 1.73 + lda ($74),y ; dy 1.74 + cmp #3 1.75 + bmi move_enemy_allow_left 1.76 + 1.77 + clc 1.78 + lda $70 ; dy > 2 so we need to check another tile 1.79 + adc #10 1.80 + sta $70 1.81 + ldy $81 ; temporary (x - 1) 1.82 + lda ($70),y ; load the tile below and to the left 1.83 + 1.84 + cmp #0 1.85 + bne move_enemy_left_exit 1.86 + 1.87 + move_enemy_allow_left: 1.88 + jsr unplot_character ; unplot the enemy character 1.89 + lda $81 1.90 + ldy #4 1.91 + sta ($74),y ; store the new room x offset 1.92 + lda #3 1.93 + ldy #5 1.94 + sta ($74),y ; dx = 3 1.95 + clc 1.96 + jmp animate_enemy_left ; optimise away the rts 1.97 + 1.98 + move_enemy_left_exit: 1.99 + clc 1.100 + rts 1.101 + 1.102 +animate_enemy_right: ; $74,$75=character address 1.103 + 1.104 + ; Set the direction and toggle the animation bit. 1.105 + 1.106 + ldy #1 1.107 + lda ($74),y 1.108 + and #1 ; remove direction information (result is 0) 1.109 + eor #1 ; toggle animation flag 1.110 + ora #2 ; right 1.111 + sta ($74),y 1.112 + 1.113 + jsr plot_character 1.114 + rts 1.115 + 1.116 +move_enemy_right: ; $74,$75=character_address 1.117 + 1.118 + ldy #5 1.119 + lda ($74),y ; read dx 1.120 + cmp #0 1.121 + beq move_enemy_right_check_x 1.122 + cmp #3 1.123 + beq move_enemy_right_tile 1.124 + 1.125 + sta $81 ; temporary 1.126 + jsr unplot_character ; unplot the enemy character 1.127 + inc $81 ; 0 < dy < 5 1.128 + lda $81 1.129 + ldy #5 1.130 + sta ($74),y 1.131 + clc 1.132 + jmp animate_enemy_right ; optimise away the rts 1.133 + 1.134 + move_enemy_right_check_x: ; Check the x offset. 1.135 + 1.136 + ldy #4 1.137 + lda ($74),y ; x 1.138 + cmp #9 1.139 + beq move_enemy_right_exit 1.140 + 1.141 + clc 1.142 + adc #1 ; x + 1 1.143 + sta $81 ; temporary (x + 1) 1.144 + ldy #2 1.145 + lda ($74),y ; load the y offset 1.146 + tax ; as an index 1.147 + lda room_row_offsets_low,x ; read the address of the row 1.148 + sta $70 1.149 + lda #$57 1.150 + sta $71 1.151 + ldy $81 ; temporary (x + 1) 1.152 + lda ($70),y ; load the tile to the right 1.153 + 1.154 + cmp #0 1.155 + bne move_enemy_right_exit 1.156 + 1.157 + ldy #3 1.158 + lda ($74),y ; dy 1.159 + cmp #3 1.160 + bmi move_enemy_allow_right 1.161 + 1.162 + clc ; dy > 2 so we need to check another tile 1.163 + lda $70 1.164 + adc #10 1.165 + sta $70 1.166 + ldy $81 1.167 + lda ($70),y ; load the tile below and to the right 1.168 + 1.169 + cmp #0 1.170 + bne move_enemy_right_exit 1.171 + 1.172 + move_enemy_allow_right: 1.173 + 1.174 + jsr unplot_character ; unplot the enemy character 1.175 + ldy #5 1.176 + lda ($74),y ; dx 1.177 + adc #1 1.178 + sta ($74),y ; update dx 1.179 + clc 1.180 + jmp animate_enemy_right ; optimise away the rts 1.181 + 1.182 + move_enemy_right_tile: 1.183 + 1.184 + jsr unplot_character ; unplot the enemy character 1.185 + ldy #4 1.186 + lda ($74),y ; x 1.187 + adc #1 1.188 + sta ($74),y ; store the new room x offset 1.189 + lda #0 1.190 + iny 1.191 + sta ($74),y ; dx = 0 1.192 + clc 1.193 + jmp animate_enemy_right ; optimise away the rts 1.194 + 1.195 + move_enemy_right_exit: 1.196 + clc 1.197 + rts 1.198 + 1.199 +animate_enemy_up: ; $74,$75=character address 1.200 + 1.201 + ; Set the direction and toggle the animation bit. 1.202 + 1.203 + ldy #1 1.204 + lda ($74),y 1.205 + and #1 ; remove direction information (result is 0) 1.206 + eor #1 ; toggle animation flag 1.207 + ora #4 ; up 1.208 + sta ($74),y 1.209 + 1.210 + jsr plot_character 1.211 + rts 1.212 + 1.213 +move_enemy_up: ; $74,$75=character address 1.214 + 1.215 + ldy #3 1.216 + lda ($74),y ; read dy 1.217 + cmp #0 1.218 + beq move_enemy_up_check_y 1.219 + 1.220 + sta $81 1.221 + jsr unplot_character ; unplot the enemy character 1.222 + dec $81 1.223 + lda $81 1.224 + ldy #3 1.225 + sta ($74),y ; dy 1.226 + clc 1.227 + jmp animate_enemy_up ; optimise away the rts 1.228 + 1.229 + move_enemy_up_check_y: 1.230 + 1.231 + ; Check the y offset. 1.232 + 1.233 + ldy #2 1.234 + lda ($74),y ; y 1.235 + cmp #0 1.236 + beq move_enemy_up_exit 1.237 + 1.238 + tax ; use the y offset as an index 1.239 + dex ; y - 1 1.240 + ldy #4 1.241 + lda ($74),y ; load the x offset 1.242 + sta $81 ; temporary (x) 1.243 + tay 1.244 + lda room_row_offsets_low,x ; read the address of the row 1.245 + sta $70 1.246 + lda #$57 1.247 + sta $71 1.248 + lda ($70),y ; load the tile above 1.249 + 1.250 + cmp #0 1.251 + bne move_enemy_up_exit 1.252 + 1.253 + ldy #5 1.254 + lda ($74),y ; dx 1.255 + cmp #0 1.256 + beq move_enemy_allow_up 1.257 + 1.258 + clc ; dx != 0 so we need to check another tile 1.259 + ldy $81 1.260 + iny 1.261 + lda ($70),y ; load the tile above and to the right 1.262 + 1.263 + cmp #0 1.264 + bne move_enemy_up_exit 1.265 + 1.266 + move_enemy_allow_up: 1.267 + txa 1.268 + sta $81 ; temporary 1.269 + jsr unplot_character ; unplot the enemy character 1.270 + lda $81 1.271 + ldy #2 1.272 + sta ($74),y ; store the new room y offset 1.273 + lda #5 1.274 + iny 1.275 + sta ($74),y ; dy = 5 1.276 + clc 1.277 + jmp animate_enemy_up ; optimise away the rts 1.278 + 1.279 + move_enemy_up_exit: 1.280 + clc 1.281 + rts 1.282 + 1.283 +animate_enemy_down: ; $74,$75=character address 1.284 + 1.285 + ; Set the direction and toggle the animation bit. 1.286 + 1.287 + ldy #1 1.288 + lda ($74),y 1.289 + and #1 ; remove direction information (result is 0) 1.290 + eor #1 ; toggle animation flag 1.291 + ora #6 ; down 1.292 + sta ($74),y 1.293 + 1.294 + jsr plot_character 1.295 + rts 1.296 + 1.297 +move_enemy_down: ; $74,$75=character address 1.298 + 1.299 + ldy #3 1.300 + lda ($74),y ; dy 1.301 + cmp #2 1.302 + beq move_enemy_down_check_y 1.303 + cmp #5 1.304 + beq move_enemy_down_tile 1.305 + 1.306 + sta $81 ; temporary 1.307 + jsr unplot_character ; unplot the character 1.308 + inc $81 ; 0 < dy < 5 1.309 + lda $81 1.310 + ldy #3 1.311 + sta ($74),y ; dy 1.312 + clc 1.313 + jmp animate_enemy_down ; optimise away the rts 1.314 + 1.315 + move_enemy_down_check_y: 1.316 + 1.317 + ; Check the y offset. 1.318 + 1.319 + ldy #2 1.320 + lda ($74),y 1.321 + cmp #9 1.322 + beq move_enemy_down_exit 1.323 + 1.324 + clc 1.325 + adc #1 ; y + 1 1.326 + tax 1.327 + ldy #4 1.328 + lda ($74),y ; load the x offset 1.329 + sta $81 ; temporary 1.330 + tay 1.331 + lda room_row_offsets_low,x ; read the address of the row 1.332 + sta $70 1.333 + lda #$57 1.334 + sta $71 1.335 + lda ($70),y ; load the tile below 1.336 + 1.337 + cmp #0 1.338 + bne move_enemy_down_exit 1.339 + 1.340 + ldy #5 1.341 + lda ($74),y ; dx 1.342 + cmp #0 1.343 + beq move_enemy_allow_down 1.344 + 1.345 + clc ; dx != 0 so we need to check another tile 1.346 + ldy $81 ; x 1.347 + iny 1.348 + lda ($70),y ; load the tile below and to the right 1.349 + 1.350 + cmp #0 1.351 + bne move_enemy_down_exit 1.352 + 1.353 + move_enemy_allow_down: 1.354 + 1.355 + jsr unplot_character ; unplot the character 1.356 + ldy #3 1.357 + lda ($74),y ; dy 1.358 + adc #1 1.359 + sta ($74),y ; update dy 1.360 + clc 1.361 + jmp animate_enemy_down ; optimise away the rts 1.362 + 1.363 + move_enemy_down_tile: 1.364 + 1.365 + jsr unplot_character ; unplot the character 1.366 + ldy #2 1.367 + lda ($74),y ; y 1.368 + adc #1 1.369 + sta ($74),y ; store the new room y offset 1.370 + lda #0 1.371 + iny 1.372 + sta ($74),y ; dy = 0 1.373 + clc 1.374 + jmp animate_enemy_down ; optimise away the rts 1.375 + 1.376 + move_enemy_down_exit: 1.377 + clc 1.378 + rts 1.379 + 1.380 +move_enemy: ; $74,$75=character address 1.381 + 1.382 + ;and #16 ; A contains the object type 1.383 + ;beq move_enemy_with_inbuilt_direction 1.384 + 1.385 + ldy #2 1.386 + lda ($74),y ; y 1.387 + cmp $3302 ; player y 1.388 + beq move_enemy_horizontally 1.389 + bpl move_enemy_upwards 1.390 + 1.391 + ; Move the enemy downwards. 1.392 + lda #4 1.393 + jmp move_enemy_with_direction 1.394 + 1.395 + move_enemy_upwards: 1.396 + lda #3 1.397 + jmp move_enemy_with_direction 1.398 + 1.399 + move_enemy_horizontally: 1.400 + ldy #4 1.401 + lda ($74),y ; x 1.402 + cmp $3304 ; player x 1.403 + beq move_enemy_exit 1.404 + bpl move_enemy_leftwards 1.405 + 1.406 + ; Move the enemy to the right. 1.407 + lda #2 1.408 + jmp move_enemy_with_direction 1.409 + 1.410 + move_enemy_leftwards: 1.411 + lda #1 1.412 + jmp move_enemy_with_direction 1.413 + 1.414 + move_enemy_with_inbuilt_direction: 1.415 + 1.416 + ldy #1 ; direction/animation 1.417 + lda ($74),y 1.418 + and #6 1.419 + 1.420 + move_enemy_with_direction: 1.421 + 1.422 + cmp #1 1.423 + bne move_enemy_not_left 1.424 + jmp move_enemy_left ; optimise away the rts 1.425 + 1.426 + move_enemy_not_left: 1.427 + cmp #2 1.428 + bne move_enemy_not_right 1.429 + jmp move_enemy_right ; optimise away the rts 1.430 + 1.431 + move_enemy_not_right: 1.432 + cmp #3 1.433 + bne move_enemy_not_up 1.434 + jmp move_enemy_up ; optimise away the rts 1.435 + 1.436 + move_enemy_not_up: 1.437 + cmp #4 1.438 + bne move_enemy_exit 1.439 + jmp move_enemy_down ; optimise away the rts 1.440 + 1.441 + move_enemy_exit: 1.442 + clc 1.443 + rts 1.444 + 1.445 1.446 move_characters: 1.447 1.448 @@ -1907,9 +2333,16 @@ 1.449 clc 1.450 1.451 cmp #3 1.452 - bne move_characters_next 1.453 + bne move_characters_not_emerge_explode 1.454 1.455 jsr emerge_explode 1.456 + jmp move_characters_next 1.457 + 1.458 + move_characters_not_emerge_explode: 1.459 + cmp #4 1.460 + bmi move_characters_next 1.461 + 1.462 + jsr move_enemy 1.463 1.464 move_characters_next: 1.465 clc
