Hi, again! lol I'm sorry to be making so many threads, but here I am again with another problem. I have a rule of I'll try to figure something out and if I can't after a couple of days I'll post a help thread. So here I am with about 4 days (about an hour per day) of trying to update a collision buffer correctly during screen scrolling. My idea is, once the screen scroll hits a multiple of 16 (which are the dimensions of the tiles) I need to update the collison buffer. Easy? Well, it doesn't seem to work the way I want it to. The collision seems to aways be a tile or two off. I've tried multiple instances, but this seems to be the correct way if I'm right about the idea. Something just isn't right though. By the way, it's just a simple two-screen setup.
Here's my code:
The camera move code:
The parts that update the collision buffer:
Here's my code:
The camera move code:
Code:
CameraMovement:
LDA buttons
AND #%00000001
BEQ @ck_right
LDA Player_X ;only scroll the screen if the player is at a fixed
CMP #$90 ; camera anchor
BCC @ck_right
LDA CameraX ;make sure that the add wont go over boundries
CLC
ADC #$01
CMP #$FF
BCS @r1
@move_camera
LDA CameraX ;scroll the camera
CLC
ADC #$01 ;note: change speed later
STA CameraX
JSR UpdateCollisionBuffer ;update the collision buffer
LDA Player_X ;make the player not move faster than the scroll rate
SEC
SBC #$02
STA Player_X
@r1
RTS
@ck_right
LDA buttons
AND #%00000010
BEQ @r
LDA Player_X ;only scroll the screen if the player is at fixed achor
CMP #$60
BCS @r
LDA CameraX ;make sure that the subtract wont go over boundries
SEC
SBC #$01
BCC @r
LDA CameraX ;scroll the camera
SEC
SBC #$01
STA CameraX
JSR UpdateCollisionBuffer ;update the collision buffer
LDA Player_X ;make the player not move faster than the scroll rate
CLC
ADC #$02
STA Player_X
@r
RTS
LDA buttons
AND #%00000001
BEQ @ck_right
LDA Player_X ;only scroll the screen if the player is at a fixed
CMP #$90 ; camera anchor
BCC @ck_right
LDA CameraX ;make sure that the add wont go over boundries
CLC
ADC #$01
CMP #$FF
BCS @r1
@move_camera
LDA CameraX ;scroll the camera
CLC
ADC #$01 ;note: change speed later
STA CameraX
JSR UpdateCollisionBuffer ;update the collision buffer
LDA Player_X ;make the player not move faster than the scroll rate
SEC
SBC #$02
STA Player_X
@r1
RTS
@ck_right
LDA buttons
AND #%00000010
BEQ @r
LDA Player_X ;only scroll the screen if the player is at fixed achor
CMP #$60
BCS @r
LDA CameraX ;make sure that the subtract wont go over boundries
SEC
SBC #$01
BCC @r
LDA CameraX ;scroll the camera
SEC
SBC #$01
STA CameraX
JSR UpdateCollisionBuffer ;update the collision buffer
LDA Player_X ;make the player not move faster than the scroll rate
CLC
ADC #$02
STA Player_X
@r
RTS
The parts that update the collision buffer:
Code:
UpdateCollisionBuffer:
LDA CameraX
;xxxxxxxx
AND #$0F ;every time a new 16x16 tile is scrolled on screen
BEQ @getNewData ; we update the collision buffer
RTS
@getNewData
JSR RefreshCollisionTable
RTS
RefreshCollisionTable:
LDA CameraX ;get absolute
AND #$10 ;only take the multiple of 16
LSR A ; shift into low nybble
LSR A ; as index to coll. data
LSR A
LSR A
STA Scratch ;index into scratch
STA Temp ; monitor ram
LDA LevelDataPtr
PHA
LDA LevelDataPtr+1 ;preserve the pointer to the level data
PHA ; because were fixin to mess it up
LDA LevelDataPtr
CLC
ADC Scratch ;add the collison index we resolved earlier
STA LevelDataPtr
LDA LevelDataPtr+1
ADC #$00
STA LevelDataPtr+1
TXA
PHA
LDY #$00 ;copy the collision buffer from top to bottom
@coll_loop
LDA (LevelDataPtr), y ; using the index as a start point
TAX
LDA TileCollisionBytes,x
STA CollisionBuffer,y
INY
CPY #$F0
BNE @coll_loop
PLA
TAX
PLA
STA LevelDataPtr+1
PLA
STA LevelDataPtr
RTS
LDA CameraX
;xxxxxxxx
AND #$0F ;every time a new 16x16 tile is scrolled on screen
BEQ @getNewData ; we update the collision buffer
RTS
@getNewData
JSR RefreshCollisionTable
RTS
RefreshCollisionTable:
LDA CameraX ;get absolute
AND #$10 ;only take the multiple of 16
LSR A ; shift into low nybble
LSR A ; as index to coll. data
LSR A
LSR A
STA Scratch ;index into scratch
STA Temp ; monitor ram
LDA LevelDataPtr
PHA
LDA LevelDataPtr+1 ;preserve the pointer to the level data
PHA ; because were fixin to mess it up
LDA LevelDataPtr
CLC
ADC Scratch ;add the collison index we resolved earlier
STA LevelDataPtr
LDA LevelDataPtr+1
ADC #$00
STA LevelDataPtr+1
TXA
PHA
LDY #$00 ;copy the collision buffer from top to bottom
@coll_loop
LDA (LevelDataPtr), y ; using the index as a start point
TAX
LDA TileCollisionBytes,x
STA CollisionBuffer,y
INY
CPY #$F0
BNE @coll_loop
PLA
TAX
PLA
STA LevelDataPtr+1
PLA
STA LevelDataPtr
RTS