Increase the Player's Character's Maximal Speed with Picked up Items

Nz17

New member
How can one increase the PC's (player character's) max speed when he picks up an item? I'd like for my character to find speed upgrades throughout the world.
 

dale_coop

Moderator
Staff member
Not an easy way... but not too difficult ;)

For example, a way to do that...
You could use a user variable like "speedBoost" with an initial value of "0".
Then, make a duplicate of your Physics_4_1_0.asm script (the script that is assigned to your "Physics" element in the "Project Settings > Script Settings") for example "Physics_withSpeedBoost.asm" and assign that script to your "Physics" element.

Now, modify the Physics_withSpeedBoost.asm, around line 41, just before the:
Code:
    LDA tempMaxSpeed
Add :
Code:
	CPX player1_object
	BNE +
		LDA tempMaxSpeed
		CLC 
		ADC speedBoost
		STA tempMaxSpeed
	+

Finally to increase the speed, just make a powerUp script (to assign to one of your pickup object) that will modify that boost variable:
Code:
	;; increase the speed by 16:
	LDA speedBoost
	CLC
	ADC #$10	;; #16
	STA speedBoost
 

vanderblade

Active member
Dale helped me with this powerup, and it works. Seems to stack, too, which is nice for gradually gaining more and more speed. If you want the player to lose the speedboost upon death, set your speed variable back to zero when the player dies (in the
"handle lose life" script):

Code:
  LDA #$00
  STA speed ;; or speedBoost if you use that variable name like in the topic
 
Top Bottom