[4.5.9] Dynamic Moving Platforms that carry the player any direction

TheRetroBro

Active member
This is a great tutorial thank you @SciNEStist

i was able to take this and expand it into a falling platform like in SMB1.

If you want to make a falling platform you can do the following:

1. Add Variable detach

2. In do handleObjectcollissions_platformbaseplatform

replace the section of code from "platform code starts" (mine is about line 164) to platform code ends with the following
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;PLATFORMCODESTARTS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA Object_vulnerability, x
AND #%00000010 ; is the platform action step flag checked?
BNE +
JMP +notplatform
+
JSR getOtherColBox
JSR doCompareBoundingBoxes
BNE +doCollision
JMP +skipCollision
+doCollision

LDY Object_type,x
LDA ObjectHeight,y
STA tempy

;;Is the player falling?

LDY player1_object
LDA Object_v_speed_hi,y
BPL +falling
JMP +skipCollision
+falling

;is the players feet above the platform bottom?
LDA Object_y_hi,x
ADC tempy
CMP bounds_bottom
BPL +
JMP +skipCollision
+

;attach the player and platform
TXA
STA attachedTo,y
STA detach

;;Player has landed on platform so change action step to 00 or 01 depending on gamepad buttons pressed
ChangeActionStep player1_object, #00

LDY Object_type,x ;;;landed on platform so start moving it down
TXA
STA tempA
LDA #%00000000 ;; "down"
TAY
LDA DirectionTable,y
STA tempB
LDA FacingTable,y
STA tempC
StartMoving tempA, tempB, #$00

LDA #$00
STA tempA
LDA gamepad
AND #%11000000
BEQ +
LDA #$01
STA tempA
+
LDA Object_frame,y
LSR
LSR
LSR
AND #%00000111
CMP tempA
BEQ +
ChangeActionStep player1_object, tempA
+

;;Move player to above the platform
LDA Object_y_hi,x
SEC
SBC self_bottom
STA Object_y_hi,y
STA yHold_hi

;;;;;;;;;;;;;;;;;;;;;;;;;;;

; ===============================
; Detach check at end of routine moved to dohandleupdateobjects.asm
; ===============================

; LDA attachedTo,y ; what platform the player thinks they’re on
; CMP detach ; compare with last attached platform
; BEQ +keepGoing ; same → do nothing

; different → stop platform

; LDY Object_type,x
; LDA Object_direction,x
; AND #%00000111
; STA Object_direction,x

;+keepGoing






JMP +skipCollision
+notplatform
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;PLATFORMCODEDONE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

3. then in your dohandleupdateobjectsplatform at about line 141 you will see STA Object_screen,x
below that line place the following section of code block

;;;;;;;;;;;;;;;;;;;add detach

LDA detach ;;;;;;;;;;;;;;;;;;;;;checking detahced
CMP attachedTo
BEQ +donuthin
;PUT WHATEVER YOU WANT TO HAPPEN HERE
LDX detach

LDA Object_direction,x
AND #%00000111
STA Object_direction,x


LDA attachedTo
STA detach
+donuthin


BOOM! Now you have a platform that will slowly decsen while you are on it. When you jump off it will stop moving down. Only crappy thing about this is i havent worked in ALSO making it move.

***BONUS** If you want to make it an elevator you can add the following check in the handle object collissions:

Right under ChangeActionStep player1_object, #00 before LDY Object_type,x ;;;landed on platform so start moving it down


add the following snippet:
LDA userScreenByte6 ;;;; you can use a screentype or screenbyte for this but im using screen byte 6
BEQ +notendscreen
;;;;end screen so we move the platform up!
LDA #$FF
STA gameState
StopMoving player1_object, #$FF
LDY Object_type,x ;;;landed on platform so start moving it up
TXA
STA tempA
LDA #%00100000 ;; "up"
TAY
LDA DirectionTable,y
STA tempB
LDA FacingTable,y
STA tempC
StartMoving tempA, tempB, #$00
JMP +doneendscreencontinue
+notendscreen


put +doneendscreencontinue above the line

LDA #$00
STA tempA
LDA gamepad
 
Last edited:
Top Bottom