[4.1.5] Adding the Double-Jump (unlockable powerup) for the Platformer module

dale_coop

Moderator
Staff member
Double Jump ability (simple/scrolling platformer module 4.1.5)
Because some of you asked me several times, here's a small tutorial for having a double-jump, unlockable as a powerup (from the "initial data" or given from a NPC or on Pickup object, ...) based on WolfMerrik's great scripts.




1) Create a new constant "didDoubleJump" in your "Project Settings > User Constants", with an initial value "0":




2) Create a new "a_double_jump.asm" script in your "Routines\Basic\ModuleScripts\InputScripts\SimplePlatformer\" folder, with that code:
Code:
;;;;; Double Jump
 
	LDX player1_object

	LDA screenFlags
	AND #%00100000 ;; does it use gravity?
	BNE +
	JMP dontPlayerJump
	+
    
	;;; let's check for if we are standing on a Jumpthrough platform,
	;;; for which "down and Jump" will Jump downwards through
	;;; comment this out if you do not want that functionality
	LDA Object_physics_byte,x
	AND #%00001000
	BEQ notStandingOnPlayerJumpThroughPlatform
	LDA gamepad
	AND #%00100000	;; checking if down is pressed 
	BEQ notStandingOnPlayerJumpThroughPlatform
	LDA Object_y_hi,x
	CLC
	ADC #$09
	STA Object_y_hi,x
	JMP dontPlayerJump
	
notStandingOnPlayerJumpThroughPlatform:   
	LDA Object_physics_byte,x
	AND #%00000001
	BNE canPlayerJump
	LDA Object_physics_byte,x
	AND #%00000100
	BNE canPlayerJump
	
	;; Double Jump ?:   
	LDA weaponsUnlocked
	AND #%00000100		;; is "MAGIC-Magic Type 2" / "Weapon 3" unlocked?
	BEQ dontPlayerJump 	
	LDA didDoubleJump 
	BNE +
	LDA #$01
	STA didDoubleJump 
	JMP canPlayerJumpAgain
	+
	JMP dontPlayerJump
	
canPlayerJump:
	LDA #$00	
	STA didDoubleJump
	
canPlayerJumpAgain:
	;;; TURN OFF "STANDING ON JumpTHROUGH PLATFORM" if it is on
	LDA Object_physics_byte,x
	AND #%11110111
	STA Object_physics_byte,x
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	LDA #$00
	SEC
	SBC #JUMP_SPEED_LO
	STA Object_v_speed_lo,x
	LDA #$00
	SEC
	SBC #JUMP_SPEED_HI
	STA Object_v_speed_hi,x
	GetCurrentActionType player1_object
	CMP #$03 ;; attack
	BEQ +
	ChangeObjectState #$02, #$04
	+
	PlaySound #SND_JUMP

dontPlayerJump:
    RTS


3) Add the new "a_double_jump.asm" in your "Scripts > Input Scripts" (also, make you you added the "varJump.asm", we need that one too):


Note: If you have the a_simple_jump.asm in your input script, remove it, you will not need it anymore (right click -> remove)

4) In the "Input Editor", assign the "a_double_jump.asm" script to the "A" "Press" button for "MainGame":


(also, make sure to have assigned the "varJump.asm" to the "A" "Release" button)
Note: If you have the a_simple_jump.asm assigned in your input editor, remove it, you will not need it anymore (right click -> remove)


Now that we have the Double Jump feature unlockable, we can implement how/when we want to give it to the player... depending of your needs:

Possiblity A)
From the start, if you want the player would be able to double-jump, just open the project "Info" (Initial Data) and set the "Wepaon 3 unlocked":




Possiblity B)
From an NPC, if you want the player get that ability from an NPC, set your End of Text Action to "NPC Gives Item" and set the "MAGIC-Magic Type 3":






Possiblity C)
From a Pickup object, if you want the player get that ability when collecting a speical pickup item...
1) Create a new script "Powerup_DoubleJump.asm" in your "Routines\Basic\ModuleScripts\PowerUpCode\" folder, with that code:
Code:
;;; Double Jump  powerup code

	LDA weaponsUnlocked
	ORA #%00000100		;; "MAGIC-Magic Type 2" / "Weapon 3" unlocked
	STA  weaponsUnlocked
	
	TriggerScreen screenType
	
	PlaySound #SND_POWERUP

2) In the "Project Settings > Script Settings", assign that "Powerup_DoubleJump.asm" to the PowerUp XX element you want to use:


For example here, I will use my "Charge pickup" object, so I assign the script to the "Power Up 01" element.

(the PowerUp script will trigger the screen, don't forget to set a unique screen-type value in your screen infos).

VoilĂ , it's not perfect but it it should work :p
Don't hesitate if you have issues, comments, modifications you want to share.
 

dale_coop

Moderator
Staff member
You would need to implement a timer countdown. And when the counter ends, you remove the ability, with that code:

Code:
	LDA weaponsUnlocked
	ORA #%11111011		;; remove the "MAGIC-Magic Type 2" / "Weapon 3" ability
	STA  weaponsUnlocked
 
I am working on a Levitation code , I am having a few errors ideas?
Code:
;Levitaiton Floating
;Warlocks and Knights
;Levitaiton floating code
;AEric Griffin 2020 May21
;
;
LDX Player1_Object
STA notPlayer_Levitation
LDA gamepad ;CHecking ofr game pad if pressed
AND #$00000001
BPL keepCheckingforlevitation
NotPLayer_Levitation:
JMP doneWithLevitation

;LDA object_v_speed_hi_x
;BMI notPlayer_Levitation
;CLC
;ADC object_Y_hi_x
;CMP #$10
;BCC notPlayer_Levitation
;CMP #$D6
;BCS notPlayer_Levitation

;LDX Player1_Object
;LDA Object_movement,x
;AND #%00001111
;CMP #%00001100
;BEQ doCollisioncheck

KeepCheckingForGravity:
LDA Player1_Object
AND#$01
BEQ +
    ChangeObjectState #$02, #$04
LDA #$00
SEC
SBC LevitaitonFloatheight
STA Object_v_speed_lo-x

;;; Levitation

    LDA weaponsUnlocked
    ORA #%00000100      ;; "MAGIC-Magic Type 2" / "Weapon 3" unlocked
    STA  weaponsUnlocked
    
    TriggerScreen screenType
    
    PlaySound #SND_POWERUP
    
    LDA weaponsUnlocked
    ORA #%11111011      ;; remove the "MAGIC-Magic Type 2" / "Weapon 3" ability
    STA  weaponsUnlocked
    
    dontPlayer_Levitation:
    RTS
 

Saulus_Lira

Member
A question. The powerUP will trigger the screen. Should I set all my screens as a "Single Screen Game" ?.
I made an NPC give the Jump power to my player, and when I leave the screen all my enemies disappear from the next screen, until I don't move any further.
I set Trigger Day Monsters too, on screens info, and nothing hapens.
i have miss something.
tela1.png[img][img]tela2.pngtela3.png[/img][/img]
 

Attachments

  • tela3.png
    tela3.png
    30 KB · Views: 1,018
  • tela2.png
    tela2.png
    17.1 KB · Views: 1,018
  • tela1.png
    tela1.png
    82.2 KB · Views: 1,018

dale_coop

Moderator
Staff member
When a screen is triggered... all the screens that have the same screen-type value will be triggered too.
On triggered screens, some tiles are removed (replaced by another gfx tiles...) and Objects are not the same.

So, don't forget to set a unique screen-type value on your trigger-able screens (in the screen "Infos")

 

Saulus_Lira

Member
now we have to make the same to others powerups in game, correct?
just changing the screen type to a different number.
 

dale_coop

Moderator
Staff member
exactly... every time you have anything that triggers your screen... make sure your screen has a unique type value.
 
@dale_coop kinda Necro'ing but hoping to get your help here.

I have a screen flag for Underwater, where I enable this powerup:

Code:
LDA screenFlags
    AND #%00000100 ;; Is it underwater?
    BEQ +finishedGravityCheck
        LDA #$05
        STA myGravity_LO
        LDA #$00
        STA myGravity_HI
        LDA #$01
        STA myAmmo
        LDA #$08
        LDA weaponsUnlocked
        ORA #%00000100 ;; Unlock "Double Jump"
        STA weaponsUnlocked

+finishedGravityCheck

This works. But I don't know how to shut it off when that flag is NOT set. I tried adding your

Code:
LDA weaponsUnlocked
    ORA #%11111011        ;; remove the "MAGIC-Magic Type 2" / "Weapon 3" ability
    STA  weaponsUnlocked
At the start of HandleScreenLoads, but that doesn't seem to do it. Once unlocked, it stays unlocked, but I only want it to work on Underwater screens (to simulate swimming)
Also, if I wanted to jump more than one extra (or unlimited) Is there something simple in the script to change?[/CODE]
 

kevin81

Active member
Try this instead:

Code:
    LDA weaponsUnlocked
    AND #%11111011        ;; remove the "MAGIC-Magic Type 2" / "Weapon 3" ability
    STA  weaponsUnlocked
 
Top Bottom