Multiple Character Game Object switching

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
Raftronaut
Posts: 3
Joined: Mon Sep 03, 2018 4:47 pm

Multiple Character Game Object switching

Post by Raftronaut » Thu Sep 27, 2018 5:06 pm

Hoping to get some advice as to how I can achieve character switching in the adventure module.

I have a specific need to have 4 switchable characters in my adventure game. I have my initial player set up and the remaining 3 player characters set up in the monster banks ready to go . However, I am entirely uncertain how I would go about actually switching the player object Persistent tag from one character to the other.

Obviously this would require some custom ASM code, but hoping I could accomplish this by using the select button to change character states.

Could anyone here recommend where I should get started in order to solve this?

I am still a bit foggy regarding the scripts as well, once some custom ASM code like this is written it can be imported as a module script
Correct? I would assume this would be helpful to others that would require separate character states for their designs as well, I.E. charcter powerups, or costume changes etc...


This is my first post to the forum, please let me know if I am directing my questions to the correct area!!!!
:roll:
Knietfeld
Posts: 5
Joined: Fri Oct 05, 2018 1:48 pm

Re: Multiple Character Game Object switching

Post by Knietfeld » Fri Oct 05, 2018 3:06 pm

I just came across your post last night. It's been a while since you posted, did you figure anything out yet?
I tried to create a complete solution for you but I barely got started on it when my baby woke up and that was the end of that. I have some ideas though, and hopefully can work on it more tonight. I was able to replace my player character with another object but I couldn't make the new one move yet. You specifically mentioned the persistent tag and that, which is stored in the ObjectFlags variable, should be pretty simple to copy over into the new object's variable if we need to.
Anyway, I'm mostly just letting you know someone is trying to figure this out for you. I wish I could have done more already. It seems like a fun problem to solve and I've been trying to figure out a similar problem for my game. I've been coding in asm for a couple years now, but I'm still learning how nesmaker's code is all laid out and where I can plug stuff in to make it do what I want.

This is also my first post to this forum... My first post to any forum, I think. I don't know if it's in the right spot, but it makes sense to me.
User avatar
Nz17
Posts: 4
Joined: Sat Oct 06, 2018 7:19 am
Location: A Cold Place in America
Contact:

Re: Multiple Character Game Object switching

Post by Nz17 » Sat Oct 06, 2018 7:24 am

I would also like to switch among multiple playable characters a la The Lost Vikings. Any help is appreciated!
Raftronaut
Posts: 3
Joined: Mon Sep 03, 2018 4:47 pm

Re: Multiple Character Game Object switching

Post by Raftronaut » Mon Oct 08, 2018 10:28 pm

Knietfeld wrote:
Fri Oct 05, 2018 3:06 pm
I just came across your post last night. It's been a while since you posted, did you figure anything out yet?
I tried to create a complete solution for you but I barely got started on it when my baby woke up and that was the end of that. I have some ideas though, and hopefully can work on it more tonight. I was able to replace my player character with another object but I couldn't make the new one move yet. You specifically mentioned the persistent tag and that, which is stored in the ObjectFlags variable, should be pretty simple to copy over into the new object's variable if we need to.
Anyway, I'm mostly just letting you know someone is trying to figure this out for you. I wish I could have done more already. It seems like a fun problem to solve and I've been trying to figure out a similar problem for my game. I've been coding in asm for a couple years now, but I'm still learning how nesmaker's code is all laid out and where I can plug stuff in to make it do what I want.

This is also my first post to this forum... My first post to any forum, I think. I don't know if it's in the right spot, but it makes sense to me.

HI Knietfeld! I appreciate your response and interest! I have not solved the problem as of yet. Although I did get some clues from JOE today on the facebook forum earlier today. According to him, the solution to having multiple character states is as follows:

1) Understand how to create and destroy objects...like when the player turns into the "death" version of the player.
2) Understand how the variable player1_object works.

this is what i'll be focusing on tinkering with on my next nesmaker session, hopefully I will learn some things with trial and error. Once I come up with some answers I will be sure to post them here as I am sure others will find it helpful. This could be a very good way to handle player upgrades, vehicles, costume changes, power ups ETC...
Knietfeld
Posts: 5
Joined: Fri Oct 05, 2018 1:48 pm

Re: Multiple Character Game Object switching

Post by Knietfeld » Tue Oct 09, 2018 1:06 pm

Yep, those are exactly the things I was playing with. I used the handle player death script as a base and switched some things around so the player character is destroyed first then the new object is created. Since the createobject macro just searches for the first available spot to place the new object, it places the new object in the player object's recently vacated place. This lets you control the new objects left and right movement (I've been using the platformer module, in the adventure module it may let you control other directions) but the action states don't change. So I was trying to figure out more about all the parts of code that affect player1_object, and what I can do to control or change it. Anyway, good luck! I'll keep toying with it too and let you know what I figure out.
Raftronaut
Posts: 3
Joined: Mon Sep 03, 2018 4:47 pm

Re: Multiple Character Game Object switching

Post by Raftronaut » Sat Oct 13, 2018 5:51 am

Could you post the script you're working with?

I found the handle player death script, but I am confused to a few things, wondering where my variables should be
Knietfeld
Posts: 5
Joined: Fri Oct 05, 2018 1:48 pm

Re: Multiple Character Game Object switching

Post by Knietfeld » Thu Oct 18, 2018 6:37 am

I started to work on other parts of my game and haven't come back to this in a while. but this is what I was dealing with. any comment that start with ;kn, are things I wrote either to help you understand or to help me understand as I was working with it. I set this chunk of code as an input scrip and told it to run when I released the select button so I could test in in my game. I can't remember if I was messing with it and made it stop working the last time I played with it and my game isn't in a state where I can easily try again, but Here's what I was working with

Code: Select all

TXA
    STA tempx
    TYA 
    STA tempy
    
    ;;;;;;;;;;;;;;;;;;;
    LDX player1_object 
    LDA Object_x_hi,x ;kn copy player x location
    STA temp
    LDA Object_y_hi,x ;kn copy player y location
    STA temp1
    lda Object_type,x 
    sta temp2 
    
    
    LDX player1_object
    DeactivateCurrentObject ;kn, if you compare these to handleplayerDeath, 
							;   you'll see that they did it the opposite way in that script because they didn't
							;	want the death animation to take the spot of player1_object, we do, so in this script 
							;	these two macros are refered to this way, 
							;	first destroy the old object then replace it with the new one.
    CreateObject temp, temp1, #$0a, #$0 ;use those to create new object in place of player character
			;		^	^		^	^
;kn-I pasted in what these numbers mean from macros.asm below. 
	; I have #$0a in arg2 because the object sprites take up spaces 00-0f and the sprite I was trying to replace 
	; my player with was at the Effect 2 spot in my Game Objects menu in NesMaker. Counting down from the top 
	; (with my main player sprite being 00), in Hex makes Effect 2 #$0a.
	; If you want to replace player with an object in the Monsters table (say, #$11 for example) instead of a Game Object, the sprite
	; will change if you go in a room that has different monsters assigned to it.
	
;CreateObject arg0, arg1, arg2, arg3  ;; arg 3 = action step?
	;arg0 x value
    ;arg1 y value
    ;arg2 object type 
    ;arg3 action step - great for creating a 'spawning' effect that is non-zero
                        ;; or even for creating projectiles that may behave differently, where
                        ;; a single projectile could have 8 action types that are different, and 
                        ;; could load that particular action step, which could show a unique animation
                        ;; with specialized behaviors?  Just a thought.
    
    ;; need to do this redundantly, otherwise, the death object will be in same slot as player
    ;stx player1_object
    ; lda temp2 
     ; sta Object_type,x
    ; CreateObject temp, temp1, #$00, #$0
    ;;;;;;;;;;;;;;;;;;;
    
    
    ;LDA #$0a
    ;STA player1_object
    
    LDX tempx
    LDY tempy
Another tip I can give you, that I discovered in messing with all this code, is that in Nesmaker/Game Engine Data there is a file called demo.txt. this file is created every time you export your game and is basically all the code for your game in one place. if you don't know what a variable is doing, or how it is used throughout the whole game, you can open that text file and hit ctrl+F and search for that variable. if you find a script that looks like it is doing something you want to change, just go to the top of that particular script and the address for it is in the "include" line. then you can easily find that script, open that script in Notepad++ or whatever editor you use, and you can cut and paste from it or edit it.

Good Luck. Sorry I haven't got more to show you yet. Hopefully what I said made a little sense.
User avatar
hairycarrot
Posts: 24
Joined: Sat Sep 01, 2018 4:38 pm

Re: Multiple Character Game Object switching

Post by hairycarrot » Thu Oct 18, 2018 11:55 pm

That's a great tip. Thank you.
Post Reply