Moderatorer: Fanta_gbg, e5frog, stonan, Zlasher, hollowman
ldx #MAX_FIREBALLS - 1
{
lda state,x
cmp #STATE_UNSPAWNED
beq .not_spawned
// check left of fireball against right of entity
lda _x,x
sec
sbc #WIDTH/2
cmp .entity_right:#0
bcs .no_collision
// check right of fireball against left of entity
clc
adc #WIDTH
cmp .entity_left:#0
bcc .no_collision
// check top of fireball against bottom of entity
lda _y,x
sec
sbc #HEIGHT/2
cmp .entity_bottom:#0
bcs .no_collision
// check bottom of fireball against top of entity
clc
adc #HEIGHT
cmp .entity_top:#0
bcc .no_collision
// remove fireball to avoid double collision when bruce respawns
jsr despawn
sec
rts
.not_spawned:
.no_collision:
dex
bpl @loop
}
// -> x: index of entity 1
// -> y: index of entity 2
// <- C: set if a collision occurred
subroutine collides
{
// check left of entity 1 against right of entity 2
lda _left_positions,x
cmp _right_positions,y
bcs .no_collision
// check right of entity 1 against left of entity 2
lda _right_positions,x
cmp _left_positions,y
bcc .no_collision
// check top of entity 1 against bottom of entity 2
lda _top_positions,x
cmp _bottom_positions,y
bcs .no_collision
// check bottom of entity 1 against top of entity 2
lda _bottom_positions,x
cmp _top_positions,y
bcc .no_collision
sec
rts
.no_collision:
clc
rts
}
hitbox
lda #$00
sta var_hitbox_collision
sec
lda var_hitbox_msb ;objekt1
sbc var_hitbox_msb + $01 ;objekt2
beq hitbox_same_msb
ldx #$00
sec
lda var_hitbox_x ;check if +01 is bigger. x, left side
sbc var_hitbox_x + $01
bcs hitbox_different_msb
inx
sec ;check if 00 is bigger
lda var_hitbox_x + $01
sbc var_hitbox_x
hitbox_different_msb
clc
adc var_hitbox_x_length,x ;längden på x utifrån x, left side.
bcs hitbox_x_hit
jmp hitbox_end
hitbox_same_msb
sec
lda var_hitbox_x + $01
sbc var_hitbox_x
bcs hitbox_x_test1
sec
lda var_hitbox_x
sbc var_hitbox_x + $01
sbc var_hitbox_x_length + $01
bcc hitbox_x_hit
jmp hitbox_end
hitbox_x_test1
sbc var_hitbox_x_length
bcc hitbox_x_hit
jmp hitbox_end
hitbox_x_hit
sec
lda var_hitbox_y + $01
sbc var_hitbox_y
bcs hitbox_y_test1
sec
lda var_hitbox_y
sbc var_hitbox_y + $01
sbc var_hitbox_y_length + $01
bcc hitbox_y_hit
jmp hitbox_end
hitbox_y_test1
sbc var_hitbox_y_length
bcc hitbox_y_hit
jmp hitbox_end
hitbox_y_hit
inc var_hitbox_collision
hitbox_end
rts
var_hitbox_x byte $00, $00
var_hitbox_y byte $00, $00
var_hitbox_msb byte $00, $00
var_hitbox_x_length byte $00, $00
var_hitbox_y_length byte $00, $00
var_hitbox_collision byte $00
Återgå till Programmering/prog.-verktyg
Användare som besöker denna kategori: Inga registrerade användare och 3 gäster