[4.5.6] A fully fonctonnal moving platform ?

CamdenTown

New member
Thanks - I ve tried this but when I hit the monster set as my platform it still results in generating a death collision - Is there something else I need to do?

UPDATE - it works now I've created the platform as an object and unclicked the monster box.
 
Last edited:

LaffinJoker

New member
Hi, I am new to NESmaker and I am trying to add this routine to version 4.5.9 for the Arcade Style Platformer module. I have created a monster and added the code but the platform kills the player when they collide.

Apologies in advance if this is a really obvious question but in the following line of code

CMP #18 ;;replace this number with the number for your platform monster

Do I just change CMP #18 to CMP #2 if my new monster is the second one I have created?

Is there anything else I need to amend?

Is there anything I need to amend in the object details?

Thanks in advance
Did you give the platform “monster” the NPC Flag in Object Details, that may stop the death?
 

tbizzle

Well-known member
Based on this tutorial : https://www.nesmakers.com/index.php?threads/moving-bouncing-platform-ver-4-1-5.5616/
I managed to get something kind of working (some polishing still needed) with the ArcadePlatformer module (v4.5.9).

This is what I've done :

In doHandleObjectCollisions

After +isNotPlayerNPCCol

Code:
                            ;;;;;;;;;;;;;;;;;;;;;;;;;;add this for "platform monster"
                            LDA Object_type,x  ;; Is it a platform?
                            CMP #18                ;;replace this number with the number for your platform monster
                            BEQ +isMovingPlatform
                                JMP +isNotMovingPlatform
                            +isMovingPlatform
                                JSR getOtherColBox
                                JSR doCompareBoundingBoxes
                                BEQ +skipCollision
                                    JMP +standOnP
                                  
                                    ;JMP +done
                            +isNotMovingPlatform

And, at the end of the file
Code:
    JMP +theEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;
+standOnP
        LDY selfObject
        LDA Object_direction,x
        STA Object_direction,y
        LDA Object_y_hi,x
        SEC
        SBC #$08
        STA Object_y_hi,y
        STA yHold_hi
      
        LDA Object_h_speed_hi,x
        STA Object_h_speed_hi,y
        LDA Object_h_speed_lo,x
        SEC
        SBC #$1F
        STA Object_h_speed_lo,y
      
        LDA gamepad
        AND #%00000001
        BEQ +
            LDA #$09
            STA temp
            LDA #$03
            STA temp1
            JMP ++
        +
        LDA #$00
        STA temp
        STA temp1
        ++
      
        LDA temp
        EOR #$FF
        STA Object_v_speed_lo,y
        LDA temp1
        EOR #$FF
        STA Object_v_speed_hi,y

        PLA
        TAY
        PLA
        TAX
      
        ReturnBank 
+theEnd
This works really good for left and right, have you managed to get it working for up and down?
 

Bucket Mouse

Active member
This works really good for left and right, have you managed to get it working for up and down?
This only seems to work if the player and the platform are moving at the exact same speed. It isn't changing the player sprite's speed to match the platform's, and I can't figure out why, as it looks like it's written to do that.
 

SciNEStist

Well-known member

This thread has been such a huge help! Wasn't the simplest to get working. Had to exclude the object from regular physics, then add in my own downward movement part. Also check for the jump button for both player 1 and 2 that forces the players to jump. Then I had to make a custom tile at the bottom of the screen that launches players off the object so they dont get sucked through and back to the top..
 
Last edited:

SciNEStist

Well-known member
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.
 
Last edited:

SciNEStist

Well-known member
I have edited the script to help people with 2 players, trimmed it down a bit, and added a bunch of comments. If anyone has questions or if anything is unclear, please message me.
 

Jonny

Well-known member
@SciNEStist did you have to do anything extra elsewhere to get the player object to 'land' on the platform? If I run onto the platform, action states work fine but if I jump and land on it player just goes into jump state, or at least jump animation. I can still leave the platform but in jump state. I've been checking my hurt scripts but can't think what else would make player not land into right state.
 

SciNEStist

Well-known member
I've altered my movement scripts a lot, so I guess that's why I hadn't noticed this, but I do see what you mean. If I press jump and land on the platform, it stays jumping (until i press a direction button). I suppose the fix is to check the action state, and change it if needed. Honestly, there might be a better way to do a moving platform though.
 

Jonny

Well-known member
Thanks, I got that part sorted. For the life in my I can't seem to ever get my players speed to change. I'm thinking it must be something I've done in error with physics script. I'm speaking in general. I've tried other speed chaning things like the slow tile tutorial but never any change.
 
Top Bottom