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

Post Reply
User avatar
dale_coop
Posts: 5160
Joined: Fri Feb 16, 2018 7:05 am
Location: France

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

Post by dale_coop » Tue Mar 10, 2020 11:49 am

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.

Image


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

Image


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

Code: Select all

;;;;; 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):

Image
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":

Image
(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":

Image


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":

Image

Image


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: Select all

;;; 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:

Image
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.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
User avatar
crazygrouptrio
Posts: 89
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

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

Post by crazygrouptrio » Tue Mar 10, 2020 11:04 pm

Awesome. A nice and simple double jump. Thanks!
User avatar
Electric cat
Posts: 153
Joined: Sun Oct 07, 2018 4:09 am

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

Post by Electric cat » Tue May 19, 2020 3:12 pm

How would this be placed on a timer as if it was a magic spell and then it locks again?
Code Name : Silencer (WIP)
Legacy Of Black(WIP)
User avatar
dale_coop
Posts: 5160
Joined: Fri Feb 16, 2018 7:05 am
Location: France

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

Post by dale_coop » Wed May 20, 2020 8:28 am

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

Code: Select all

	LDA weaponsUnlocked
	ORA #%11111011		;; remove the "MAGIC-Magic Type 2" / "Weapon 3" ability
	STA  weaponsUnlocked
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
User avatar
Electric cat
Posts: 153
Joined: Sun Oct 07, 2018 4:09 am

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

Post by Electric cat » Thu May 21, 2020 2:30 pm

I am working on a Levitation code , I am having a few errors ideas?

Code: Select all

;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
Code Name : Silencer (WIP)
Legacy Of Black(WIP)
Post Reply