2 Players Adventure Game tutorial (2 Players Single Screen module - NESmaker 4.1.5)

dale_coop

Moderator
Staff member
The "b_create_weapon_sprite.asm" script just will set your player to the Attacking step (action step 2), used for the sword.
But nothing related to the textbook with that script.
You could try assigning the "b_activate_text_box.asm" script to your "B" button, for NPC interactions and activation text boxes.
 

RicePixel

New member
Thanks, that was what I was missing. It works now, just need to get the weapon to go into the hud. So I'm assuming the predraw.asm file is involved. In the tutorial at https://www.youtube.com/watch?v=wH6G296onhs&t=4826s
Joe has a different script and talks about the one he uses to get the hud to draw a sword.

Code:
LDA weaponsUnlocked
    AND #%00000001
	BNE +
	JMP skipDrawSpriteWeapon
	+

Should I be placing the code he has in this area? I'm not familiar with asm so my guess was this.

Code:
LDA weaponsUnlocked
    AND #%00000001
	BNE +
	JMP skipDrawSpriteWeapon
	+ 
	DrawSprite #$74, #$14, #$2c, #%00000001, spriteOffset

Also if its two players do both players need to obtain the sword and item or is it just player one? When I tried with player 2 the game freezes up.

Code:
;; sprite pre-draw
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
checkStartScreenSelector:
	LDA update_screen_details
	BNE endCheckingStartScreenSelector 
	;; is special screen:
	LDA newScreen
	CMP #$01
	BEQ endCheckingStartScreenSelector
	;; is START SCREEN:
	
	;; positions selection: 
	LDA #SELECTION_POS_X
	STA temp2  				;; coord X position of all selections
	LDA #SELECTION_POS_Y  	;; coord Y position when selection mode is 0
	STA temp1
	LDA player2Mode
	CLC
	BEQ +
	;; if not equal to 0, means at least equal to 1
	LDA temp1  				;; coord Y position when selection mode is 1
	ADC #$08
	STA temp1
	+
	DrawSprite temp2, temp1, #STARTSCREEN_CURSOR_TILE, #%00000000, #$00	
	UpdateSpritePointer
	
	JMP endCheckingStartScreenSelector
		
endCheckingStartScreenSelector:





;;=================== Platform engine
;; In our platform engine, the player can shoot from a 'projectile source'.
;; Since this projectile source does not interact with the background in any way,
;; it is really just a sprite extention of the player, and would be truly foolish to waste
;; an object and processing time on it.  You can, but it would be wasteful.
;; So what we can do instead is use pre-drawn sprites.  If the player is in his attack state,
;; we will check the direction, and then draw the weapon sprite based on which direction he is
;; facing.


	;; if a Sprite weapon is set:
	LDA #SPRITE_WEAPON_H
	BNE +
	JMP skipDrawSpriteWeapon
	+
	LDA #SPRITE_WEAPON_V
	BNE +
	JMP skipDrawSpriteWeapon
	+
	;; if weapon unlocked:
    LDA weaponsUnlocked
    AND #%00000001
	BNE +
	JMP skipDrawSpriteWeapon
	+

	;LDX player1_object ;; we are going to check some player 1 things.
	;;; but getting current action type will set x to this automatically
doDrawSpriteWeapon:
	TXA
	STA tempxxx
	LDX player1_object
	CPX #$FF
	BEQ +
	TXA
	STA playerX_object
	JSR doPreDrawPlayerX
	+
	LDX player2_object
	CPX #$FF
	BEQ +
	TXA
	STA playerX_object
	JSR doPreDrawPlayerX
	+
	LDX tempxxx
	JMP skipDrawSpriteWeapon
	

doPreDrawPlayerX:	
	GetCurrentActionType playerX_object ;; what object is the current player
										;; because if it's attack (2), we should draw weapon.
	CMP #$02
	BEQ +
	JMP	notAttackingSoDontDrawWeapon
+
	;;attacking, so draw weapon.
	LDA Object_movement,x
	AND #%00000111
	TAY ;; now y contains direction, so we can figure out position offset
	;CMP #RIGHT
	;BNE directionIsNotRightForDrawingWeapon
	;;; direction is right.
	 LDA Object_x_hi,x
     ;;; offset x for creation
     CLC
     ADC weaponOffsetTableX,y
	 SEC
     SBC #$08 ;; width of gun 
     STA temp
     LDA Object_y_hi,x
     CLC
     ADC weaponOffsetTableY,y
     sec
     sbc #$08 ;; height of gun
     STA temp1
	 
	 CPY #RIGHT
	 BNE directionIsNotRightForDrawingWeapon
	 ;; it is right, which means draw without flip
	 LDA #%00000001
	 STA temp2
	 LDA #SPRITE_WEAPON_H
	 STA temp3
	 JMP doDrawWeapon
directionIsNotRightForDrawingWeapon:
	CPY #LEFT
	BNE directionIsNotLeftForDrawingWeapon
	LDA #%01000001
	STA temp2
	LDA #SPRITE_WEAPON_H
	STA temp3
	JMP doDrawWeapon
directionIsNotLeftForDrawingWeapon:
	CPY #UP
	BNE directionIsNotUPForDrawingWeapon
	LDA #%00000001
	STA temp2
	LDA #SPRITE_WEAPON_V
	STA temp3
	JMP doDrawWeapon
directionIsNotUPForDrawingWeapon:
	;; direction must be down.
	;; need to add cases for diagonals if you want to use diagonals.
	LDA #%10000001
	STA temp2
	LDA #SPRITE_WEAPON_V
	STA temp3
doDrawWeapon:
	DrawSprite temp, temp1, temp3, temp2, spriteOffset
	JMP doneDrawingWeaponSprite
doneDrawingWeaponSprite:
	UpdateSpritePointer
notAttackingSoDontDrawWeapon:
skipDrawSpriteWeapon:

update: after following your tutorial i'm still having trouble actually getting the sword to show up properly. I'm using the object version over the sprite but after pressing b on the NPC I get the sword but it bugs out my character and I can't move him. Very confusing but if I can't figure it out I might go back to the original adventure module with 1 player.
 

dale_coop

Moderator
Staff member
The weapons are unlocked for both players.
To draw the weapon in the hud, the script should look like:

Code:
	LDA update_screen_details
	BEQ skipDrawSpriteWeaponHud

	LDA weaponsUnlocked
	AND #%00000001
	BNE +
	JMP skipDrawSpriteWeaponHud
	+ 
	DrawSprite #$74, #$14, #$2c, #%00000001, spriteOffset
	UpdateSpritePointer
	skipDrawSpriteWeaponHud:

You can put that code at the begining of the PreDraw script (or at the total end of the script).


What Sword Weapon do you want to use? The sprite based one (the sword drawn from the tileset) ? or the Melee object ?
 

RicePixel

New member
The melee object version; I want to add animations and varied colors later on down the line. Currently when I get the sword I have it to the point where it animates when I press b but its very buggy. The first part is this weird flashing on the top of both players' heads in the top left corner when facing down.

gg.gif

Once I get the sword all of the animations have this two second delay which prevents me from moving. The last problem I have is using the game objects to set up the offset. The same frame of animation is used for Melee and projectile (now Melee_H) when trying to align it, so I can't really gauge where to place it. Even when I set up left and right melee nothing shows up in game.

3.PNG
2.PNG
1.PNG
 

dale_coop

Moderator
Staff member
You are not settings correctly the objects...
The Melee object is only 1 unique object: the one you named "Melee_V". You have to set different animations for that specific object.
Your "Melee_h" object is your projectile object!
Those are defined in your "Project Settings > User constants":
2019-11-06-20-23-33-Param-tres-du-projet.png


Then to set the Melee offset (the origin when the object is created), you need to click on the button here.... until it displays "Melee" to set the Melee offsets:
2.png


Last, if you don't use the sprite based weapon, you need to set your "SPRITE_WEAPON_V" and "SPRITE_WEAPON_H" to "0" :
2019-11-06-20-25-58-Param-tres-du-projet.png



And make sure you are not using the "b_create_weapon_sprite.asm" script... in the input scripts. Use the "b_create_melee_object.asm" instead.
 

RicePixel

New member
So I got the sword working but there's this weird action that takes place when I move left with player 2. When I move player 2 to the left after receiving a sword it triggers player 1 to attack. This happens when player one is facing any direction. I thought I might have done something wrong so I re-did your tutorial using the adventure tutorial assets and started over on a new project. It still happens so I guess there is something in StartMovingPlayerLeft.asm that might be causing it? :|

test.gif

Here is all the inputs that I am using for my players.
5.PNG

update: So apparently the inputs are correct but for some reason mesen can't seem to differentiate between the two controllers. It works in FCEUX. Now the problem is getting rid of the messed up pixels at the top of the players head when getting the sword. Its only there when facing down, so I just have to find out whats causing it. Also when I have the weapon unlocked from the start that problem is not there, its only when I get it from the NPC does it act weird.

6.PNG
 

dale_coop

Moderator
Staff member
file.php


About this small glitch on the player head... I think I have an idea why...
Let me do some tests on my demo projects trying to reproduce it and I'll tell you how to fix it.
 

dale_coop

Moderator
Staff member
About the placement of the Melee object (sword) when the player is attacking.... could you check the "Melee" offset, for all 4 directions (like in my post from yesterday)?
Could you share a screenshot of the Melee Offset settings ?
 

RicePixel

New member
They are very crude but its just to make sure they appear on screen; I'll fix up the animation frames later on and make a more detailed sword.
 

Attachments

  • meleed.PNG
    meleed.PNG
    45.1 KB · Views: 2,449
  • meleer.PNG
    meleer.PNG
    50.2 KB · Views: 2,449
  • meleeu.PNG
    meleeu.PNG
    44.9 KB · Views: 2,449
  • ml.PNG
    ml.PNG
    41.3 KB · Views: 2,449

dale_coop

Moderator
Staff member
Those settings look correct.
And you set your "SPRITE_WEAPON_V" and "SPRITE_WEAPON_H" user constants to "0" (in project Settings > User Constants)?
Then it should work correctly... it is not?
 

RicePixel

New member
The sword is working now I just have to make new animations and minor adjustments to it. Also is it normal for the melee weapon to always be behind the player object when pressing b?


Now I'm stuck on the projectile, it freezes my character once the projectile button is pressed

projectile.gif

proj.PNG

Update: I got the projectile working, had to change the action step 3 to attack.
 

RicePixel

New member
https://www.youtube.com/watch?v=Z7fSvORaz-Y&feature=youtu.be

So I got it to the point where I'm happy with the results; everything seems to work I can grab the sword and projectile from the npc characters and have them pop up in my hud. The only problem I have is that the NPC characters spawn in on top of my player characters when I switch screens. For some reason they don't want to stay put in their designated spot.

Also thanks for all the help Dale, I can't wait to get deeper into what I can do with two players. Maybe doors that need two people to open? Or very hard bosses that need the strength of two players lol.
 

dale_coop

Moderator
Staff member
Interesting...
Might an issue somewhere in the objects spawning/loading code.
Could you share a copy of your nesmaker with me (zipped, via wetransfer or dropbox or...)? I could check that and find a fix..
 

dale_coop

Moderator
Staff member
After having checked your project, the issue is you made a small mistake in your monster details... you set the "persistent" flag.
This flag is ONLY for player objects.

Just uncheck "PERSISTENT" on all your monster objects and it should work ;)
 

dale_coop

Moderator
Staff member
RicePixel said:
Now the problem is getting rid of the messed up pixels at the top of the players head when getting the sword. Its only there when facing down, so I just have to find out whats causing it. Also when I have the weapon unlocked from the start that problem is not there, its only when I get it from the NPC does it act weird.

file.php


About that issue, you could try:
Modify the "LoadTileUpdate.asm" script (in your "Routines\Basic_NoScroll_TwoPlayers\DataLoadScripts" folder) and comment out the lines 60 and 61, like this:
Code:
	; LDA #$01
	; STA UpdateAtt
Ir might fix your issue.
 

RicePixel

New member
dale_coop said:
RicePixel said:
Now the problem is getting rid of the messed up pixels at the top of the players head when getting the sword. Its only there when facing down, so I just have to find out whats causing it. Also when I have the weapon unlocked from the start that problem is not there, its only when I get it from the NPC does it act weird.

file.php


About that issue, you could try:
Modify the "LoadTileUpdate.asm" script (in your "Routines\Basic_NoScroll_TwoPlayers\DataLoadScripts" folder) and comment out the lines 60 and 61, like this:
Code:
	; LDA #$01
	; STA UpdateAtt
Ir might fix your issue.


What does commenting out those two lines do, exactly?
 

dale_coop

Moderator
Staff member
This workaround was proposed by Elarath to eliminate a unwanted sprite drawing on some triggered scripts:
http://nesmakers.com/viewtopic.php?p=18823#p18823
 

RicePixel

New member
Ok thanks, I read up on what he posted and it doesn't seem to affect anything else. So its a harmless change which is good.
 
Top Bottom