It's pretty much the same as what
Pep31 wrote down, but some extra steps
In project settings, I added a "platform" in user CONSTANTS, but you can instead just replace any instance of "#Platform" with just the number of the platform object id.
In the "Handle Physics" script, I added this part right before the gravity checks under the "doneWithH:" part
Code:
;;; What should we do if vulnerability bit 0 is flipped?
;;;BELOW IS THE NEW STUFF
LDA Object_type,x
CMP #Platform ;; replace this with the object id of your platform
BNE +
JMP platformmove
+
JMP doneWithGravity
+skip
This will make it so the platform is immune to gravity.
Then at the bottom of the same Handle Physics script, immediatly above the "doneWithGravity:" part:
Code:
platformmove
LDY Object_type,x
LDA ObjectMaxSpeed,y
ASL
ASL
ASL
ASL
STA myMaxSpeed
LDA ObjectMaxSpeed,y
LSR
LSR
LSR
LSR
STA myMaxSpeed+1
TXA
LDA Object_direction,x
CMP #DOWN
BNE +
TXA
LDA Object_y_lo,x
ADC myMaxSpeed
STA yHold_lo
LDA Object_y_hi,x
ADC myMaxSpeed+1
STA Object_y_hi,x
STA yHold_hi
CLC
JMP skipPhysics
+
CMP #UP
BNE +
TXA
LDA Object_y_lo,x
SBC myMaxSpeed
STA yHold_lo
LDA Object_y_hi,x
SBC myMaxSpeed+1
STA Object_y_hi,x
STA yHold_hi
CLC
JMP skipPhysics
+
That part handles the movement by reading the object direction and the object max speed setting, This handles up and down movement. All 4 directions is not available yet
After all that, its time to hit up the Handle Object collisions script just like Pep31's script has
I put my check for a platform object right below "+isNotPlayerPowerupCol" because I actually removed all the NPC collision stuff, but you can put it in either spot
Code:
+isNotPlayerPowerupCol
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;NEW STUFF AFTER HERE;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_type,x ;; Is it a platform?
CMP #Platform ;;replace this with the object number for your platform
BEQ +isMovingPlatform
JMP +skipCollision
+isMovingPlatform
TXA
JSR getOtherColBox
JSR doCompareBoundingBoxes
BEQ +skipCollision
JMP +standOnP
+skipCollision
Then you slap this bit in at the very end of the Handle Object Collisions script
Code:
;;;;;;;;;;;;;;;;;THIS PART HANDLES THE PLATFORM INTERACTION;;;;;;;;;;;;;;;;;;;;;;;;;;;
+standOnP
LDA ObjectBboxTop,y
CLC
ADC ObjectHeight,y
STA temp2 ;this part takes the players height to determine where to stick the player in relation to the platform
LDY selfObject
LDA Object_v_speed_hi,y
BMI +doneplat; is the player moving downward? (like a 1 way plattform)
LDA Object_type,y
CMP #$00 ; Is this player1? (change if your player1 object is different)
BEQ +p1check
CMP #$09 ; Is this player2? (change this to whatever your player 2 object is)
BEQ +p2check
JMP +doneplat ; if its neither, then skip the whole ordeal
+p1check
LDA gamepad
JMP +lookforjump
+p2check
LDA gamepad2
+lookforjump ;;This part simulates the player jumping if it detects the jump button is pressed while the player is touching the platform
AND #%00000001 ; is the player holding the A button? (change this if your jump button is different)
BEQ +
LDA ObjectJumpSpeedLo,y
EOR #$FF
STA Object_v_speed_lo,y
LDA ObjectJumpSpeedHi,y
EOR #$FF
STA Object_v_speed_hi,y
ChangeActionStep selfObject, #$02 ;; this assumes action step 2 for players is jumping
PlaySound #sfx_jump ; change this to whatever sound you have set for player jumping
JMP +doneplat
+
;;everything below this is attaching the player to the platform
LDA Object_y_hi,x
SEC
SBC temp2
ADC #$02 ; lowers player by 2 extra pixels to keep the player touching the platform (no bouncing)
STA Object_y_hi,y
STA yHold_hi
LDA #$00 ; turns player speed to 0
STA Object_v_speed_lo,y
STA Object_v_speed_hi,y
+doneplat
PLA
TAY
PLA
TAX
ReturnBank
RTS
You will need to read the comments I have in there and alter the script to suit your needs.