I'm working on the collisions on my map right now. I have two general options: 1) use tile numbers directly or 2) have separate array with bounding boxes + additional behavior parameters/callbacks
Because maps are dynamic and I store level ID, I cannot just use absolute,x addressing and have to use indirect. So far I came up with something like the code below. Does it make sense to use multiple pointers for each property (I will probably allocate more generic pointers to save ZP space later) or there is smarter trick to deal with this?
Edit: typo in code
Because maps are dynamic and I store level ID, I cannot just use absolute,x addressing and have to use indirect. So far I came up with something like the code below. Does it make sense to use multiple pointers for each property (I will probably allocate more generic pointers to save ZP space later) or there is smarter trick to deal with this?
Code:
; I did not test this code yet, it may contain some small mistakes. Treat is as pseudo code
.segment "ZEROPAGE"
collisionX1: .res 2
collisionY1: .res 2
collisionX2: .res 2
collisionY2: .res 2
...
Load:
; here I load labels statically, but those addresses
; will be loaded with from another array like
; lda level_num
; asl a
; tax
; lda level_collisions, x
; etc...
lda Level_1_Collisions_x1
sta collisionX1
lda Level_1_Collisions_x1+1
sta collisionX1+1
...
lda Level_1_Collisions_y2
sta collisionY2
lda Level_1_Collisions_y2+1
sta collisionY2+1
ldy #0
; get first bounding box x1
lda (collisionX1),y
; get first bounding box y1
lda (collisionY1),y
.segment "RODATA"
; Bounding box parallel array
Level_1_Collisions_x1:
.byte 32, $FF ; endmarker
Level_1_Collisions_y1:
.byte 40
Level_1_Collisions_x2:
.byte 40
Level_1_Collisions_y2:
.byte 64
.segment "ZEROPAGE"
collisionX1: .res 2
collisionY1: .res 2
collisionX2: .res 2
collisionY2: .res 2
...
Load:
; here I load labels statically, but those addresses
; will be loaded with from another array like
; lda level_num
; asl a
; tax
; lda level_collisions, x
; etc...
lda Level_1_Collisions_x1
sta collisionX1
lda Level_1_Collisions_x1+1
sta collisionX1+1
...
lda Level_1_Collisions_y2
sta collisionY2
lda Level_1_Collisions_y2+1
sta collisionY2+1
ldy #0
; get first bounding box x1
lda (collisionX1),y
; get first bounding box y1
lda (collisionY1),y
.segment "RODATA"
; Bounding box parallel array
Level_1_Collisions_x1:
.byte 32, $FF ; endmarker
Level_1_Collisions_y1:
.byte 40
Level_1_Collisions_x2:
.byte 40
Level_1_Collisions_y2:
.byte 64
Edit: typo in code