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

Having trouble compiling code? Getting an unexpected error? Player not appearing on screen? Seeking answers on how to do a particular thing? This is the forum you're looking for, to ask other NESmaker users for assistance.
Post Reply
User avatar
Nz17
Posts: 4
Joined: Sat Oct 06, 2018 7:19 am
Location: A Cold Place in America
Contact:

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

Post by Nz17 » Tue Oct 16, 2018 7:15 am

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.
vanderblade
Posts: 136
Joined: Mon Jan 07, 2019 5:20 am

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

Post by vanderblade » Thu Jun 25, 2020 6:18 pm

Bump.
User avatar
dale_coop
Posts: 5752
Joined: Fri Feb 16, 2018 7:05 am
Location: France

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

Post by dale_coop » Fri Jun 26, 2020 3:01 pm

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

    LDA tempMaxSpeed
Add :

Code: Select all

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

	;; increase the speed by 16:
	LDA speedBoost
	CLC
	ADC #$10	;; #16
	STA speedBoost
-----
I know... my english is not perfect
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
vanderblade
Posts: 136
Joined: Mon Jan 07, 2019 5:20 am

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

Post by vanderblade » Fri Aug 28, 2020 5:14 pm

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

  LDA #$00
  STA speed ;; or speedBoost if you use that variable name like in the topic
Post Reply