2 Player Game Tutorial For Version (4.5.9)

Ok, I was playing around with Nesmaker to see if it were possible to make a 2 player platform game? Because they are becoming very popular with the homebrew scene at the moment e.g Micro Mages. I managed to get it to partially work in this current version of Nesmaker. Here is how I did it:

2022-03-26 (2).png
Step 1) I made a second player object exactly the same as the first player object and saved it as (Player_2).

2022-03-26 (1).png
Step 2) In Input Scripts, above Script To Run, I changed the settings to Target (Player_2) and set Controller to 2.

2022-03-26.png
Step 3) With those settings set, I went ahead and added all the scripts that was needed for player 1 object and set it to the second player object.

2022-03-26 (4).png
Step 4) Once all my scripts were added, I added my Player_2 object to my first game screen of my Overworld map.

2022-03-26 (5).png
Step 5) I ran the game, as you can see both objects are being displayed on screen.

2022-03-26 (6).png
Step 6) The new Player_2 object can be moved using the second controller buttons/keys. As it were a 2 player game, but it's a strange Monster/Player hybrid and can't collect gems, die or climb ladders. At this stage this object can just be moved around the screen, run and jump.

So that's as far as I have got with it for the moment. It seems to fully implement this idea. I think someone would have to change the program by customizing a few things and change the scripts to recognize a second player object. But the rough framework is there and is possible to certain degree.
 
Last edited:

cupofT

New member
Hi, I have been trying to get my player 2 to shoot projectiles. Have you had any luck with this?
 

JamesNES

Well-known member
If you add two player as monster 1 on every screen you warp into, you can always reference them by assuming they're object ID 1, so

Code:
LDX #$01
LDA Object_x_hi,x
CLC
ADC #$10
STA Object_x_hi,x

moves player 2 one tile to the right for instance.

If you post your shoot projectile script I can show you what to change to make it come from player 2 instead of player 1.

NES Maker is actually set up really well from base to use two players.
 

cupofT

New member
Thank you so much! I got the player 2 sorted out. Do you know how I might create separate health systems for both players?
 

Poche

New member
Hello

I'm a noob for coding.
I try to make 2 players (or more) with this tutorial.
That work, but I have a problem. It seems that the Inpuscrip stop moving d'ont work all the time for the player 2.
If two players move together, the player 2 d'ont stop when a relaese left or right.
Maybe I have de problème mention by JamesNes about the ID of the player.

But I d'ont no where I must put this part of code ?
I must check only the list of input script? or others are concerd?
What is #$01 ? (the position in my game object for the player 2 ?)
What is ADC #$10 ?

My visual probleme (I have the same problem if I use my D pad from the pad 2) :



Player_dont_stop_moving.gif
 

SciNEStist

Well-known member
in a lot of the input scripts, it assumes you are making a 1 player game, so adjustments need to be made.

for example, if you see "LDA gamepad" in the script, it is checking the player1 controller to see what buttons are being pressed. you would need to replace it with something like this:

Code:
LDA controllerNumber_hold  ;which controller is being pressed?
BNE +controller2 ; 0 = controller1, 1=controller2
;; we are checking controller 1.
LDA gamepad
+controller2:
;;we are checking controller 2
LDA gamepad2

or you will see some instances of "LDX player1_object" and you will need to do something similar to make it look at "player2_object" instead.
 

Poche

New member
Tanks for your answer!

I find this part of code very similar at yours on the changeActionToStop_unlessJumping script.


LDA controllerNumber_hold
BNE +weAreCheckingCOntroller2
;; we are checking controller 1.
LDA gamepad
AND #%11110000
BEQ changeToStop_NoDpadPressed
RTS
weAreCheckingCOntroller2:
LDA gamepad2
AND #%11110000
BEQ changeToStop_NoDpadPressed
RTS
changeToStop_NoDpadPressed:
ChangeActionStep temp, #$00 ;; assumes that "walk" is in action 1
;arg0 = what object?
;arg1 = what behavior?
RTS


I try it on my Input Script "stopMoving" and "moveLeft/moveRight"
But anthing are changing

The probleme is when I'm holding the D pad1 to Left or Right. The input script StopMoving for the player2 don't work..
Maybe LDX player1_object can help me.
But how can I define all my players? Do I'must creat different variables or something like that?
 

dale_coop

Moderator
Staff member
Try this...
Edit the "oStopMoving.asm" script assigned to the Stop Moving in your Project Settings > Script Settings (under Behaviors)

2023-01-03 12_17_52-Project Settings.png

And comment out the lines 6 to 10 (by adding a ";" before each line):

2023-01-03 12_18_33-MEDIA - Database .NET Free (Non-Commercial Use) - (sa@SYLVAIN_SQLGESTIONCL...png

Now, I think your players should stop correctly as expected.
 

Poche

New member
Okay I enjoy a little bit to fast.

If my 2 player are on the same pad. No broblem.
But If I holding two directiction with 2 pad. No probleme for walk right or left. But players can't jump .

I'm looking for a script like oStopMoving.asm for jump. But I d'ont find it.
 

dale_coop

Moderator
Staff member
Can you share your JUMP input script ?
(Doit y avoir un bout de code à modifier dans ce script... je pense que c'est pas méchant)
 

Poche

New member
Here is my jump_Input Scrip


;; Only can jump if the place below feet is free.
SwitchBank #$1C
LDY Object_type,x
LDA ObjectBboxTop,y
CLC
ADC ObjectHeight,y
sta temp2

LDA Object_x_hi,x
CLC
ADC ObjectBboxLeft,y
STA temp
JSR getPointColTable

LDA Object_y_hi,x
CLC
ADC #$02
CLC
ADC temp2
STA temp1
CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BNE +checkMore
JMP +doJump
+checkMore

CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BNE +checkMore
JMP +doJump
+checkMore
CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
;;; if it is (equal), can jump.
;;; if not, skips jumping.

BNE +dontDoJump
JMP +doJump

+dontDoJump
;; check second point.
LDY Object_type,x
LDA ObjectWidth,y
CLC
ADC temp
STA temp
JSR getPointColTable
CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BEQ +doJump

CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BEQ +doJump
CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
;;; if it is (equal), can jump.
;;; if not, skips jumping.
BEQ +doJump

; Partie qui check si on peut faire un double saut. Le code en commentaire sert à checker si on à récupèrer l'objet nésséssaire
; Pour pouvoir faire un double Jump (On à du créer une variable "doubleJumpCounter" dans project setting Objet Variable pour que
; ca fonctionne
JMP +checkIfCanDoubleJump

+checkIfCanDoubleJump
; LDA weaponsUnlocked
; AND #%00000010
BNE +doubleJumpUnlocked
JMP +skipJumping

+doubleJumpUnlocked
LDA doubleJumpCounter
CMP #$02
BEQ +skipJumping
JMP +doJumpNoReset

+doJump:
LDA #$00
STA doubleJumpCounter

+doJumpNoReset
TXA
STA temp ;; assumes the object we want to move is in x.
;PlaySound #sfx_thump

LDY Object_type,x
LDA ObjectJumpSpeedLo,y
EOR #$FF
STA Object_v_speed_lo,x
LDA ObjectJumpSpeedHi,y
EOR #$FF
STA Object_v_speed_hi,x

TXA
STA temp ;; assumes the object we want to move is in x.
; change the object's action so that he is in jump mode.
INC doubleJumpCounter
ReturnBank
RTS

+skipJumping:
ReturnBank
RTS

I put a part of code to have a double Jump.
Y use a variable for that and I'have duplicate this script with a another variable for the player 2.
If I d'ont. players can't doing that in the same time.
I'don't no if there are a link with my problem?

And here is my varJump Input Script:

HTML clipboard LDX player1_object
LDA Object_v_speed_lo,x
CLC
ADC #$00
LDA Object_v_speed_hi,x
ADC #$00
BPL skipVarJump
LDA Object_v_speed_hi,x
CMP #$01
BCC skipVarJump
LDA #$00
SEC
SBC #$01
STA Object_v_speed_hi,x
skipVarJump:
RTS


(Je croise les doights pour que ca vienne bien de là )
 

dale_coop

Moderator
Staff member
The jump script, you have an error in the doublejump part, in this code:
Code:
+checkIfCanDoubleJump
; LDA weaponsUnlocked
; AND #%00000010
BNE +doubleJumpUnlocked
JMP +skipJumping
if you don't want it to be unlockable, comment out all the lines, like this:
Code:
+checkIfCanDoubleJump
; LDA weaponsUnlocked
; AND #%00000010
; BNE +doubleJumpUnlocked
; JMP +skipJumping
if you want it to be unlockable (by an NPC or maybe a pickup or at some time in the game), uncomment all the lines:
Code:
+checkIfCanDoubleJump
 LDA weaponsUnlocked
 AND #%00000010
 BNE +doubleJumpUnlocked
 JMP +skipJumping

And in your varJump input script, comment out (or remove) the LDX player1_object line.
Basic rule, for two players fame... you should not have any "LDX player1_object" line in your input scripts.

Make sure your jumps input scripts are correctly set to your player 2 object and for the "controller 2" in the Input Editor.
And it sould be all good.
 

Poche

New member
The code look better now. But the problem is still there.

If I look what button I use in the Nes Emulator. I realize that any other direction is possible when I Hold the same direction whit Pad 1 and 2.
I use UP for Jump. Because I would like to have 2 players with one pad. (For making a 4 players games with only 2 Pad)
But if y a put Jump on the "A" Button they are any problems for Juming with any players in the same Time.

Is there a probleme when we using several directions at the same time when using the 2 gamePad?
 

Poche

New member
I tried an official nintendo rom and I noticed the same thing!

Are you thinking that is a probleme with the emlulator or with the nintendo hardware ?
 

TakuikaNinja

Active member
Are you using the keyboard to simulate the controllers? Some key combinations will not register due to some stupid limitations.
 

Poche

New member
Yes, i'm using my Keyboard.
I will try USB gamepad. But I'm not sure that de probleme are here. Because I Only use 3 Key for my probleme :s
 
Top Bottom