Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sonic_PanCamera:
- move.w #159+16,d0 ; NTP: Sets the right-most edge of the camera deadzone (center screen x coordinate + rounded-up deadzone radius; actual deadzone width is 31px)
- btst.b #0,status(a0) ; NTP: Check the direction the player is facing
- beq.s .isRight ; NTP: If facing right, branch
- addq.w #1,d0 ; NTP: If facing left, we adjust the right-most edge of the deadzone, since the deadzone width is an odd number (175 -> 176)
- ; NTP: What this means is the camera will pan one less pixel ahead if the player happens to be facing opposite the direction that they're moving
- .isRight:
- tst.b obj_control(a0) ; NTP: Check if the player is under control of another object (CPZ Tubes, CNZ Flippers, etc.)
- bne.s .centerTarget ; NTP: If so, branch ahead & use the deadzone edge as the target coordinate
- btst.b #1,status(a0) ; NTP: Check if the player is in the air
- beq.s .onGround ; NTP: If not, branch to the "on ground" code
- .inAir:
- move.w x_vel(a0),d1 ; NTP: Load the player's horizontal veloctiy
- beq.s .centerTarget ; NTP: If it's 0, branch ahead & use the deadzone edge as the target coordinate; we don't need to do math on that
- bra.s .setTarget ; NTP: Otherwise, we skip ahead to the capping code
- .onGround:
- move.w inertia(a0),d1 ; NTP: Load the player's ground veloctiy
- beq.s .centerTarget ; NTP: If it's 0, branch ahead & use the deadzone edge as the target coordinate; we don't need to do math on that
- .setTarget:
- cmpi.w #$1000,d1 ; NTP: Is the loaded velocity value higher than 16px/f?
- ble.s .noPosCap ; NTP: If not, branch
- move.w #$1000,d1 ; NTP: If so, cap it at a max of 16px/f
- bra.s .noNegCap ; NTP: And skip ahead to the target value calculation
- .noPosCap:
- cmpi.w #-$1000,d1 ; NTP: Is the loaded velocity value lower than -16px/f?
- bge.s .noNegCap ; NTP: If not, branch
- move.w #-$1000,d1 ; NTP: If so, cap it at a min of -16px/f
- .noNegCap:
- asr.w #6,d1 ; NTP: Divide the velocity value by 64 (sort of; due to how shifting works, negative number don't always produce accurate results)
- sub.w d1,d0 ; NTP: Subtract the velocity factor to get our target value
- .centerTarget:
- move.w (Horiz_scroll_pan).w,d1 ; NTP: Load the previous horizontal pan value
- add.w d1,d0 ; NTP: All of the following add/shift mess is, for the most part, identical to this equation, sans rounding differences: (d0 + 31(d1)) / 32
- add.w d1,d0 ; NTP: What this accomplishes is the calculation an intermediate values that is heavily biased towards the pan value on the previous frame...
- add.w d1,d0 ; NTP: ...That the pan value will be set to, allowing us to create a nice, smooth, dynamic camera pan that isn't too jarring or jerky.
- asr.w #2,d0
- add.w d1,d0 ; NTP: Now the lot of you are probably wondering what causes the "deadzone" at the center of the screen, where slowing down doesn't scroll...
- add.w d1,d0 ; NTP: ...the camera back towards the center of the screen until you begin moving in the opposite direction entirely, or why we need one at...
- add.w d1,d0 ; NTP: ...all instead of just panning back to the center of the screen entirely. Well, truth be told... I have no ide what causes the deadzone!
- asr.w #2,d0 ; NTP: It's true; it was a quirk in the code that popped up while I was writting this camera system that I loved so much that I fully embraced...
- add.w d1,d0 ; NTP: ...it instead of investigating what had caused it to begin with. I personally think it's useful to still be able to see a slight bit...
- asr.w #1,d0 ; NTP: ...ahead of you even after coming to a complete stop, but I could not even begin to tell you what caused it. I'll leave that to you all! :P
- move.w d0,(Horiz_scroll_pan).w ; NTP: Oh yeah, and uh, this line just sets the new pan value once we're done running all the calculations & such
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement