Doing a trampoline in scrolling platformer

pit.baldriz

New member
Hi guys! Is there a way to create a trampoline on a scrolling platformer game? I just want to add one to my game.
 

dale_coop

Moderator
Staff member
Here's a quick code... not perfect (it's based on the trampoline system that was in NESmaker 3)
1/ Create a new TrampolineTile.asm script (in the "Basic\ModuleScripts\TileScripts" folder), with this:
Code:
;;BOUNCY TRAMPOLINE
;; trampoline
	CPX player1_object
	BNE notAPlayer_trampoline
	LDA Object_v_speed_hi
	BPL keepCheckingForTrampoline
	;; should behave like solid.
notAPlayer_trampoline:
	;;LDA #TILE_SOLID
	;;STA tile_solidity
	JMP doneWithTrampoline
keepCheckingForTrampoline:
	ChangeObjectState #$02, #$02
	LDA #$00
	SEC
	SBC #$02
	STA Object_v_speed_hi,x
doneWithTrampoline:

2/ Assign that script to a unused "Tile Collision ??" element in your "Project Settings > Script Settings" (For this example, I will use the "Tile Collision 14").
You can also rename the corresponding Tile Type in the "Project Settings > Project Labels".

3/ Add a new constant "COL_TRAMPOLINE" in your "Project Settings > User Constant", with a value of your tile type. In my example, since I decided to use the tile type 12, my set the constant value to "12".

4/ Modify your "a_simple_jump.asm" script, around the end, just after the "dontJump:" line (but before the "RTS" line), add this bloc of code:
Code:
;; check if on trampoline:
	LDA Object_x_hi,x
	STA tileX
	LDA Object_y_hi,x
	CLC
	ADC Object_bottom,x
	CLC
	ADC #$08 ;; the height of the player + however far you want to check beneath the player
	STA tileY
	JSR GetTileAtPosition

    LDA collisionTable,y
    CMP #COL_TRAMPOLINE ;; the bounce tile type
    BEQ JumpingOnTrampoline
    LDA tileX
    CLC
    ADC #$10 ;; object width
    STA tileX
    JSR GetTileAtPosition
    LDA collisionTable,y
    CMP #COL_TRAMPOLINE ;; the bounce tile type
    BEQ JumpingOnTrampoline
    JMP notJumpingOnTrampolineTile
JumpingOnTrampoline:
    ChangeObjectState #$02, #$02
    LDA #$00
    SEC
    SBC #$08	;; <-- HERE, the TRAMPOLINE JUMP value
    STA Object_v_speed_hi,x
notJumpingOnTrampolineTile:
(you can adjust the trampoline jump value, cf my comments in the code)

Voilà, you should have a simple trampoline tile type.
 

pit.baldriz

New member
Ok, I did everything and it works in half, hahaha!

When I place the trampoline tile (here has a placeholder image) on the first screen, it works perfectly. But when the player moves to the next screens, the trampoline broke and the player can´t jump:

Trampoline.gif
 

dale_coop

Moderator
Staff member
Sounds like... a the jumping script is doing something weird (like not checking correctly)... let me test that, again.
 

dale_coop

Moderator
Staff member
Ok...
In your "a_simple_jump.asm" script, try adding a "CLC" line before each "CMP #COL_TRAMPOLINE" lines:
Like this:
Code:
	LDA collisionTable,y
	CLC
	CMP #COL_TRAMPOLINE
(there are 2 cmp, like this, in the code).
 

pit.baldriz

New member
Thanks guys for your help!

Dale, I tried adding the CLC command and now it works better but not perfect as the trampoline works one yes, the next one no, and the other yes. Is like a yes/no/yes/no combination:

TrampolineError-2.gif


I can try hiding the "no" trampolines on an inaccessible part maybe?
 

dale_coop

Moderator
Staff member
hum... OK
I will try recreating the same screen to see where the issue comes from.
Could you share screen shots of the collisions of your different screens (the first 4 screens maybe)?
 

dale_coop

Moderator
Staff member
Ok, yeah I see some weird things...
You could try this code instead for the trampoline part (to replace the one you added in your a_simple_jump.asm):

Code:
;; check if on trampoline:
    LDA Object_x_hi,x
    CLC
    ADC Object_left,x
    STA tileX
    LDA Object_y_hi,x
    CLC
    ADC Object_bottom,x
    CLC
    ADC #$0E ;; <-- HERE: however far you want to check beneath the player
    STA tileY
    JSR GetTileAtPosition
    LDA Object_scroll,x
    AND #%00000001
    BNE +
    LDA collisionTable,y
    JMP ++
    +
    LDA collisionTable2,y
    ++
    CLC
    CMP #COL_TRAMPOLINE ;; the bounce tile type
    BEQ JumpingOnTrampoline
    ; LDA tileX
    ; CLC
    ; ADC #$10 ;; object width
    ; STA tileX
    ; JSR GetTileAtPosition
    ; LDA Object_scroll,x
    ; AND #%00000001
    ; BNE +
    ; LDA collisionTable,y
    ; JMP ++
    ; +
    ; LDA collisionTable2,y
    ; ++
    ; CLC
    ; CMP #COL_TRAMPOLINE ;; the bounce tile type
    ; BEQ JumpingOnTrampoline
    JMP notJumpingOnTrampolineTile
JumpingOnTrampoline:
    ChangeObjectState #$02, #$02
    LDA #$00
    SEC
    SBC #$08    ;; <-- HERE, the TRAMPOLINE JUMP value
    STA Object_v_speed_hi,x
notJumpingOnTrampolineTile:
 

pit.baldriz

New member
Thanks a lot for the help Dale! I tried your last code and it worked perfectly. Check it out:

TrampolineWorking.gif


This game is more yours than mine, hahaha!

Thanks!!
 

TolerantX

Active member
Dale, I was curious and tried this in your 2 player single screen platformer module and the player seems to bounce on it only so slightly and wont go very high at all. like kind of vibrates on top of it. Is there a fix for this so it makes the player go upward or jump higher on it? I tried the CLC method suggested previously and it didnt help either. The new script your wrote just a few replys up didnt work and gave me errors on line 113. thank you
 

dale_coop

Moderator
Staff member
TolerantX, you could try that one:
Code:
;; check if on trampoline:
    LDA Object_x_hi,x
    CLC
    ADC Object_left,x
    STA tileX
    LDA Object_y_hi,x
    CLC
    ADC Object_bottom,x
    CLC
    ADC #$0E ;; <-- HERE: however far you want to check beneath the player
    STA tileY
    JSR GetTileAtPosition
    LDA collisionTable,y
    CLC
    CMP #COL_TRAMPOLINE ;; the bounce tile type
    BEQ JumpingOnTrampoline
    JMP notJumpingOnTrampolineTile
JumpingOnTrampoline:
    ChangeObjectState #$02, #$02
    LDA #$00
    SEC
    SBC #$08    ;; <-- HERE, the TRAMPOLINE JUMP value
    STA Object_v_speed_hi,x
notJumpingOnTrampolineTile:
 

TolerantX

Active member
In the 2 player platformer it works with this for player 1 except player 2 falls through as if it is a null tile.
 
Top Bottom