junglejourney
changeset 58:76fff1782efe
Use masks to determine if collisions occur between enemies and the player.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Thu Aug 25 01:42:30 2011 +0200 |
| parents | c632214161bc |
| children | fe9482813dc4 |
| files | mapcode.oph |
| diffstat | 1 files changed, 105 insertions(+), 43 deletions(-) [+] |
line diff
1.1 --- a/mapcode.oph Thu Aug 25 01:41:46 2011 +0200 1.2 +++ b/mapcode.oph Thu Aug 25 01:42:30 2011 +0200 1.3 @@ -2959,6 +2959,43 @@ 1.4 clc 1.5 rts 1.6 1.7 +; The player collision masks use bits to represent where the player is in a 1.8 +; tile. 1.9 + 1.10 +; Player is above, enemy is below, checking the overlap in the lower tile. 1.11 +player_collision_mask_above: .byte $00, $20, $30, $38, $3c, $3e 1.12 + 1.13 +projectile_collision_mask_above: .byte $00, $00, $00, $00, $00, $20 1.14 + 1.15 +; Player and enemy share the same tile or player is on the tile below. 1.16 +player_collision_mask_below: .byte $3f, $1f, $0f, $07, $03, $01 1.17 + 1.18 +projectile_collision_mask_below: .byte $30, $18, $0c, $06, $03, $01 1.19 + 1.20 +; Player is above or on the same tile, enemy is below, checking the overlap in 1.21 +; the lower tile. 1.22 +enemy_collision_mask_above: .byte $3c, $1e, $0f, $07, $03, $01 1.23 + 1.24 +; Enemy is above, player is below, checking the overlap in the lower tile. 1.25 +enemy_collision_mask_below: .byte $00, $00, $00, $20, $30, $38 1.26 + 1.27 +; Player is to the left, enemy is to the right, checking the overlap in the 1.28 +; right hand tile. 1.29 +player_collision_mask_left: 1.30 +projectile_collision_mask_left: .byte $00, $00, $00, $08 1.31 + 1.32 +; Player and enemy share the same tile or player is on the tile to the right. 1.33 +player_collision_mask_right: 1.34 +projectile_collision_mask_right: .byte $0c, $06, $03, $01 1.35 + 1.36 +; Player is to the left, enemy is to the right or on the same tile, checking 1.37 +; the overlap in the right hand tile. 1.38 +enemy_collision_mask_left: .byte $0f, $07, $03, $01 1.39 + 1.40 +; Enemy is to the left, player is to the right, checking the overlap in the 1.41 +; right hand tile. 1.42 +enemy_collision_mask_right: .byte $00, $08, $0c, $0e 1.43 + 1.44 player_collide: 1.45 1.46 lda #$0c ; set the character address 1.47 @@ -2990,37 +3027,47 @@ 1.48 jmp player_collide_next 1.49 1.50 player_check_collide_y_equal: 1.51 + ; The enemy is on the same tile as the player so look at the collision 1.52 + ; on their common tile. 1.53 + ldx $3303 ; player dy 1.54 + lda player_collision_mask_below,x 1.55 + sta $80 1.56 ldy #3 1.57 - lda ($74),y ; dy 1.58 - sec 1.59 - sbc $3303 ; dy - player dy ; this appears to be 1.60 - bmi player_check_collide_y_equal_n ; required to deal with 1.61 - ; negative results 1.62 - 1.63 - jmp player_check_collide_x 1.64 - 1.65 - player_check_collide_y_equal_n: ; dy - dpy <= -4 (to miss) 1.66 - cmp #253 ; dy - dpy > -3 (to hit) 1.67 - bpl player_check_collide_x 1.68 + lda ($74),y ; dy 1.69 + tax 1.70 + lda enemy_collision_mask_above,x 1.71 + and $80 1.72 + bne player_check_collide_x 1.73 1.74 jmp player_collide_next 1.75 1.76 - player_check_collide_y_greater: ; DY - dpy >= 6 (to miss) 1.77 - ldy #3 ; DY = 6 + dy (coordinates) 1.78 - lda ($74),y ; dy ; 6 + dy - dpy >= 6 1.79 - sec ; dy - py >= 0 1.80 - sbc $3303 ; dy - player dy ; dy - py < 0 (to hit) 1.81 - bmi player_check_collide_x 1.82 + player_check_collide_y_greater: 1.83 + ; The enemy is on the tile below the player so look at the collision on 1.84 + ; the enemy's tile. 1.85 + ldx $3303 ; player dy 1.86 + lda player_collision_mask_above,x 1.87 + sta $80 1.88 + ldy #3 1.89 + lda ($74),y ; dy 1.90 + tax 1.91 + lda enemy_collision_mask_above,x 1.92 + and $80 1.93 + bne player_check_collide_x 1.94 1.95 jmp player_collide_next 1.96 1.97 - player_check_collide_y_less: ; DPY - dy >= 4 (to miss) 1.98 - ldy #3 ; DPY = 6 + dpy 1.99 - lda ($74),y ; dy ; 6 + dpy - dy >= 4 1.100 - sec ; dy - dpy <= 2 1.101 - sbc $3303 ; dy - player dy 1.102 - cmp #3 1.103 - bpl player_check_collide_x 1.104 + player_check_collide_y_less: 1.105 + ; The enemy is on the tile above the player so look at the collision on 1.106 + ; the player's tile. 1.107 + ldx $3303 ; player dy 1.108 + lda player_collision_mask_below,x 1.109 + sta $80 1.110 + ldy #3 1.111 + lda ($74),y ; dy 1.112 + tax 1.113 + lda enemy_collision_mask_below,x 1.114 + and $80 1.115 + bne player_check_collide_x 1.116 1.117 jmp player_collide_next 1.118 1.119 @@ -3038,32 +3085,47 @@ 1.120 jmp player_collide_next 1.121 1.122 player_check_collide_x_equal: 1.123 + ; The enemy is on the same tile as the player so look at the collision 1.124 + ; on their common tile. 1.125 + ldx $3305 ; player dx 1.126 + lda player_collision_mask_right,x 1.127 + sta $80 1.128 ldy #5 1.129 - lda ($74),y ; dx 1.130 - sec 1.131 - sbc $3305 ; dx - player dx 1.132 - cmp #2 ; dx - dpx >= 2 (to miss) 1.133 - bpl player_collide_next ; dx - dpx < 2 (to hit) 1.134 - jmp player_check_collide_destroy 1.135 + lda ($74),y ; dx 1.136 + tax 1.137 + lda enemy_collision_mask_left,x 1.138 + and $80 1.139 + bne player_check_collide_destroy 1.140 + 1.141 + jmp player_collide_next 1.142 1.143 player_check_collide_x_greater: 1.144 + ; The enemy is the tile to the right of the player so look at the 1.145 + ; collision on the enemy's tile. 1.146 + ldx $3305 ; player dx 1.147 + lda player_collision_mask_left,x 1.148 + sta $80 1.149 ldy #5 1.150 - lda $3305 ; player dx 1.151 - sec 1.152 - sbc ($74),y ; player dx - dx 1.153 - cmp #3 ; dpx - dx > 2 (to hit) 1.154 - bpl player_check_collide_destroy 1.155 + lda ($74),y ; dx 1.156 + tax 1.157 + lda enemy_collision_mask_left,x 1.158 + and $80 1.159 + bne player_check_collide_destroy 1.160 1.161 jmp player_collide_next 1.162 1.163 - player_check_collide_x_less: ; PX - x >= 4 (to miss) 1.164 - ldy #5 ; PX = 4 + px 1.165 - lda ($74),y ; dx ; 4 + px - x >= 4 1.166 - sec ; x - px <= 0 1.167 - sbc $3305 ; dx - player dx 1.168 - bmi player_collide_next 1.169 - cmp #1 ; x - px >= 1 (to hit) 1.170 - bpl player_check_collide_destroy 1.171 + player_check_collide_x_less: 1.172 + ; The enemy is the tile to the left of the player so look at the 1.173 + ; collision on the player's tile. 1.174 + ldx $3305 ; player dx 1.175 + lda player_collision_mask_right,x 1.176 + sta $80 1.177 + ldy #5 1.178 + lda ($74),y ; dx 1.179 + tax 1.180 + lda enemy_collision_mask_right,x 1.181 + and $80 1.182 + bne player_check_collide_destroy 1.183 1.184 player_collide_next: 1.185 clc
