[4.1] Switching between Player and another Object (test)

dale_coop

Moderator
Staff member
I made a simple script, that can with the Player with another Object (Game Object or Monster Object)... just a test for fun (has a lot of
Issues).

[media]https://youtu.be/wqWQHZAgeyg[/media]

1/ Add a new "User Constant" in the "Script Settings > User Constants" tab, name it "OBJ_PLAYER_XTRA" and give it the value of the object index you want to use for your Player to switch to, for this example, I used "14".
But HERE, you can change to any object index you want to use to with! (monster objects start from 16).


2/ Make a script named for example "SwithPlayerToXtraObject.asm", with this code:

Code:
;; change character to OBJ_PLAYER_XTRA
switchPlayerXTRA:
	LDX player1_object
	LDA Object_x_hi,x
	STA newX
	LDA Object_y_hi,x
	STA newY
	DeactivateCurrentObject
	
	LDA playerToSpawn
	BEQ goSwitchingPlayerXTRA	
	;; put back tehe initial player object
	LDA #$00
	JMP continueSwitchingPlayerXTRA
goSwitchingPlayerXTRA:
	;; we use another one :
	LDA #OBJ_PLAYER_XTRA
continueSwitchingPlayerXTRA:
	STA playerToSpawn

	LDA Object_scroll,x
	STA temp3
	CreateObject newX, newY, playerToSpawn, #$00, temp3  ;;  currentNametable	

	TXA
	STA player1_object
	
	;PlaySound #SND_TRANSFORM
	RTS


3/ Add this script to your "Input Scripts" and add this script to the "PRESS" "Select" button for example. When you press select it switch the character (more fast one, or invincible one, ...)!

Voilà, it's just a small test script, do whatever you want with it.

In fact, I would not recommend to use this script
In your great game, because it’s full of bug ;)

Need to work more on that before being useable.
 

dale_coop

Moderator
Staff member
Yep, it's just a sample of a script, to give an idea how to do... it's not perfect, seems to have some issues with others objects and maybe some collisions...
It's just fun!

I tried also with a monster object :
[media]https://youtu.be/v4wcLFEJS_c[/media]
I made a tile, with some custom scripts (inspired from the TileCollectable.asm)
 

Bucket Mouse

Active member
dale_coop said:
3/ Add this script to your "Input Scripts" and add this script to the "PRESS" "Select" button for example. When you press select it switch the character (more fast one, or invincible one, ...)!

Voilà, it's just a small test script, do whatever you want with it.

Thing is, becoming fast or invincible is traditionally a temporary effect. This would be great for that sort of thing, but we would need a timer -- and I'm clueless as to how to build a timer. It would require making a loop that would allow for the rest of the game to pass by while it counted up or down. Possibly a subroutine. I would fail here math-wise because it would likely be a count over 255 and I wouldn't know how to get the time I want in asm/hex.

Off the top of my head....one variable, "TimerCount," increases each frame and another, "TimerArrival," equals the number TimerCount should stop at.

Code:
TimerStart
	LDA TimerCount
	CMP TimerArrival
	BEQ TimerDone
	INC TimerCount
	RTS

TimerDone
	LDX player1_object
	LDA Object_x_hi,x
	STA newX
	LDA Object_y_hi,x
	STA newY
	DeactivateCurrentObject
	
	LDA #OBJ_PLAYER
	STA playerToSpawn
	CreateObject newX, newY, playerToSpawn, #$00, currentNametable
	TXA
	STA player1_object
	
	;PlaySound #SND_TRANSFORM
	RTS

Nobody try that -- I just posted it to get corrections and suggestions from Dale, who knows more than me.
 

dale_coop

Moderator
Staff member
You 're right Bucket Mouse, I would definitely use this script for becoming invincible is traditionally a temporary effect.
For the timer...

For the timer... you should try to add it to the GamerTimer, take a look what I did with the timer for my automatic recharge Ammo: http://nesmakers.com/viewtopic.php?p=10687#p10687
 

dale_coop

Moderator
Staff member
DanielT1985 said:
If this can be possible, then does that mean people can add multiple playable characters into their game?

I guess so... but would required a lot of code and scripts to manage that.
 
Holy cow this is great,

OK SOO..
QUESTION 1. Can there we a way to make this sort of thing unlockable.

Question 2. If the above question is yes, then can this be used to give the player object a new ability?

Thank all for being so RAD!
 

dale_coop

Moderator
Staff member
It could be, yes... (using the weaponUnlocked variable to unlock the ability and check that variable when creating the Player object).
Just need to make a bunch of modifications in scripts.
 
Hey guys,

so I gave the code a shot to switch players and continued to get an error code on line 17 so after tinkering with it I changed line 17 and 18 to this . I I want to add to it so this will work to become an unlockable player. Thank you Dale Coop for the all the rest of this code and the User constraint.

I main bug I have found after testing is if you press "SELECT" again it changes you to a different state do to not defining what staue to change back to.
 

Attachments

  • New player LDA.PNG
    New player LDA.PNG
    19.7 KB · Views: 4,296
Electric cat said:
Hey guys,

so I gave the code a shot to switch players and continued to get an error code on line 17 so after tinkering with it I changed line 17 and 18 to this . I I want to add to it so this will work to become an unlockable player. Thank you Dale Coop for the all the rest of this code and the User constraint.

The one one issue I shave found with this code is that if you press the select button to go back to your pain character it wont, but at least you can die
 
OK so my idea is this for a script

I would like the screen to trigger the player object extra.
Once the screen has triggered the player object extra then that object is loaded into your select menu screen.

Press the select On the controller it takes you to a select character screen where your new obtained player object extra is located.

Now you select player extra and press select to take you back to the screen you were just on and. Bam you are the new player.
 
This is the current code I have but the screen does not trigger
any suggestions, the XTRA play still only spawns by pressing select
;; if my screen if the 01
LDA currentScreen
CMP #$01
BNE +
LDA #$03
STA temp2
JMP continueSwitchingPlayerXTRA
+
switchPlayerXTRA
LDX player1_object
LDA Object_x_hi,x
STA newX
LDA Object_y_hi,x
STA newY
DeactivateCurrentObject

LDA playerToSpawn
BEQ goSwitchingPlayerXTRA
;; put back tehe initial player object
LDA #$00






JMP continueSwitchingPlayerXTRA
goSwitchingPlayerXTRA:
;; we use another one :
LDA #$03 ;; what object you want to load.
STA temp2
continueSwitchingPlayerXTRA:
STA playerToSpawn
CreateObject newX, newY, playerToSpawn, #$00, currentNametable
TXA
STA player1_object

;PlaySound #SND_TRANSFORM
RTS
;; if my screen if the 02
;LDA currentScreen
;CMP #$02
;BNE +
;LDA #$01
;;STA temp2
;JMP continueCreatingTheProjectileObject
+
;; if my screen if the 03
;LDA currentScreen
 

MonkeyCity

New member
Having an issue with my character changing perfectly in the center of each screen but getting stuck around where the new screen load seem is on the scrolling platform module. Any Ideas on how I can remedy this? :|
 

dale_coop

Moderator
Staff member
What you mean by "stuck"? You can't change? You can't get the item? You can't move after changed?

A modification of the code I can see... could be, replacing:
Code:
  CreateObject newX, newY, playerToSpawn, #$00, currentNametable

by:
Code:
    LDA Object_scroll,x
    SBC #$00
    STA temp3
    CreateObject newX, newY, playerToSpawn, #$00, temp3  ;;  currentNametable
 

MonkeyCity

New member
Tried your modification dale and now if im in the start of a new screen it jumps me forward when pressing the input and I'm locked in place as before. it acts as though the collision is loaded prior to the screen loading but I'm just speculating. Also, just to clarify, I mean that my character cannot move forward or backward or jump more than a blocks height up. Character can still change and all animations work.
 
This code doesnt work in the adventure module, except it will allow you to switch to your player death animation which is neat.

I have had success with with theis code in the platform model. I went through all the same steps and have teied multiple diffrent objects to no out success.
Any ideas ?
 

dale_coop

Moderator
Staff member
Hmmm... I think this code should work in every modules.
Electric cat, could you explain what is your issue exacly (what's happening in your case) also share the script you are using?
 
Top Bottom