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

Lother

Member
I have a problem with the melee attack. I've binded the attack to a button and all, but when I press it when testing the attack doesn't activate.

My attack is 2 sprites large by 2 sprites high.

Here's the code :
Code:
; load the playerX_object (current inputs):
JSR PlayerXobjectInputs

createWeaponMelee:
    ;; if on a cutscene:
    LDA screenFlags
    AND #%00000010
    BEQ +
    RTS
    +
    ;TXA
    ;STA playerX_object
    LDA gameHandler
    AND #%00100000  
    BEQ notNPCstate_weapon
    JMP doneCreatingWeaponMelee
notNPCstate_weapon:
    LDA weaponsUnlocked
    AND #%00000001
    BNE canCreateWeaponMelee
    JMP doneCreatingWeaponMelee
canCreateWeaponMelee:
    ;LDA limitWeapon
    ;BNE continueCreatingWeaponMelee
    ;RTS
continueCreatingWeaponMelee:

    LDA Object_physics_byte,x
    AND #%00000001 ;; is it on the ground?
    BNE notCurrentyJumping
    JMP doneCreatingWeaponMelee
notCurrentyJumping:

    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN ATTACKING, comment out the following 3 lines: 
    ;;; check if already attacking (assuming the attack action step is 03)
    GetCurrentActionType playerX_object
    CMP #$03
    BNE notAlreadyCreatingWeaponMelee
    JMP doneCreatingWeaponMelee
notAlreadyCreatingWeaponMelee:
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN ATTACKING, comment out the following 1 line: 
    ;;; if not already attacking, change it's action step (assuming the attack action step is 03)
    ChangeObjectState #$03, #$02
    
    ;;; if you want your player stops when he's attacking, comment out the following lines:
    ;LDA Object_movement,x
    ;AND #%00001111
    ;ORA #%00000010
    ;STA Object_movement,x
    ;LDA #$00
    ;STA Object_h_speed_hi,x
    ;STA Object_h_speed_lo,x
    ;STA Object_v_speed_hi,x
    ;STA Object_v_speed_lo,x
    
;; if was already attacking
wasAlreadyCreatingWeaponMelee:

    LDA Object_movement,x
    AND #%00000111
    STA temp2
    TAY

    LDA Object_x_hi,x
    SEC 
    SBC #$10 ;; <<-- HERE, width of weapon 
    STA temp

    LDA temp
    ;;; offset x for creation
    CLC
    ADC weaponOffsetTableX,y
    STA temp
    LDA temp3
    ADC #$00
    STA temp3

    LDA Object_y_hi,x
    CLC
    ADC weaponOffsetTableY,y
    sec
    sbc #$10 ;; <<-- HERE, height of weapon
    STA temp1   
    
    
    CreateObject temp, temp1, #OBJECT_PLAYER_MELEE, #$00, currentNametable
    
    ;DEC limitWeapon
  
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x
    
    PlaySound #SND_SLASH
doneCreatingWeaponMelee:
    RTS

In the options of the player object used for the attack, "Player Weapon" and "Monster" are the only boxes checked.
 

dale_coop

Moderator
Staff member
Have you assigned that script correctly to "MainGame" "Player1" "Press" B (or another one) button?
Is your "OBJECT_PLAYER_MELEE" user constant (in "Project Settings > User Constants") corrspond to the object you used for the melee weapon?

Don't hesitate to share screenshots of your settings.
 

Lother

Member
Here's some screenshots of my settings.

screen17.png


screen18.png


screen19.png


Hope it does help.
 

dale_coop

Moderator
Staff member
Hummm.... your Player weapon should only be set as "weapon" :
- "player weapon" in the case you make a co-op game.
- "monster weapon" if you want to make 1 vs 1 game.

Also the animation speed "1" is very quick (1 frame!)... so you might not have the time to see the weapon. You would use "end of timer" and timer value of "1"... Or "end of animation" with a value of "4" or "6" (depends of the nb of frames of your animation and the speed you want to give to that animation)
 

Lother

Member
It's not the animation speed the problem, I did such speedy animations on purpose. The problem is when I press the attack button, the attack just won't appear, not even the attack animation would play.
 

dale_coop

Moderator
Staff member
Ok... have you set the b_create_melee_object.asm script to the button input?
Have you set the "weapon 1 unlocked" ("Arme 1 déverrouillée"), in your project Infos.
 

Lother

Member
dale_coop said:
Ok... have you set the b_create_melee_object.asm script to the button input?
Have you set the "weapon 1 unlocked" ("Arme 1 déverrouillée"), in your project Infos.

I forgot the weapon 1 unlocked. That was it.
 

Lother

Member
But now, I still have some problems to solve :

What do I need to change in the code in order to make sure that the players do not go to the adjacent screens upon touching the edges of the current one ? (Apart from closing everything between solid tiles, which will make me lose some useful space.)
 

dale_coop

Moderator
Staff member
You could modify your "Handle Left Bounds" and "Handle Right Bounds" scripts (in the "Project Settings > Scripts Settings")...
Adding the code:
Code:
	LDA #$00
	STA Object_x_lo,x
	STA Object_h_speed_lo,x
	STA Object_h_speed_hi,x
	LDA xPrev
	STA xHold_lo
	STA Object_x_hi,x
	STA xHold_hi
	RTS

At line 8 (just after "doPlayerUpdateRightScreen:" / "doPlayerUpdateRightScreen :" line)

And for the top of your screen... I'd suggest to make the "Playable Area" crossing the "HUD Area", by 1 row (or even the full screen as "Playable Area"...) and place solid tiles under the last row of your HUD.
 

Lother

Member
dale_coop said:
And for the top of your screen... I'd suggest to make the "Playable Area" crossing the "HUD Area", by 1 row (or even the full screen as "Playable Area"...) and place solid tiles under the last row of your HUD.

Problem is, my HUD is at the bottom of the screen, not at the top.
 

dale_coop

Moderator
Staff member
hummm...OK I see.
A 8 pixels row might already be cropped by the overscan (crt / emulators). So, I'd suggest to put 1 row of solid tiles at the top of your screen...
 
I’m having an issue with this. For some reason when I shoot a projectile, it freezes one of the players and prevents them from moving. Any way to fix this?
 

dale_coop

Moderator
Staff member
Using all the native scripts? or you made any modification in some scripts (in handle object collision or create projectile ones)?
 

dale_coop

Moderator
Staff member
Ok... hmmm... (NESmaker can have freeze with a lot of incorrect settings / scripts used)
Could you share more details? : Which shooting script are you using? how is set your players ? which object do you use as projectile? Its settings?
 
dale_coop said:
Ok... hmmm... (NESmaker can have freeze with a lot of incorrect settings / scripts used)
Could you share more details? : Which shooting script are you using? how is set your players ? which object do you use as projectile? Its settings?
So it seems to happen no matter what number the player2Mode variable is set to. I'm using the projectile script used in the tutorial and my projectile constant is set to 02. Here is a bunch of screenshots of my settings for my players and my projectile.
2019-10-22.png
2019-10-22 (1).png
2019-10-22 (4).png
2019-10-22 (5).png
2019-10-22 (6).png
2019-10-22 (7).png
2019-10-22 (8).png
2019-10-22 (9).png
2019-10-22 (10).png
2019-10-22 (11).png
 

dale_coop

Moderator
Staff member
Your projectile is not set as "player weapon" (or "monster weapon" depending if you want a coop game or a versus game)... but I don't think it's the error here.
How is the crete projectile script you use? Could you share it? Maybe an error in that one?
 
dale_coop said:
Your projectile is not set as "player weapon" (or "monster weapon" depending if you want a coop game or a versus game)... but I don't think it's the error here.
How is the crete projectile script you use? Could you share it? Maybe an error in that one?
Here is my projectile script.
Code:
; load the playerX_object (current inputs):
JSR PlayerXobjectInputs

createWeaponProjectile:
    ;; if on a cutscene:
    LDA screenFlags
    AND #%00000010
    BEQ +
    RTS
    +
    LDA isPaused
    BEQ +
    RTS
    +

    ;TXA
    ;STA playerX_object
    LDA gameHandler
    AND #%00100000  
    BEQ notNPCstate_proj
    JMP doneShooting
notNPCstate_proj:
    LDA weaponsUnlocked
    AND #%00000010
    BNE canShoot
    JMP doneShooting
canShoot:
    ;LDA limitProjectile
    ;BNE continueCreateProjectile
    ;RTS
continueCreateProjectile:
    ;LDX player1_object
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 3 lines: 
    ;;; check if already shooting (assuming the shoot action step is 03)
    GetCurrentActionType playerX_object
    CMP #$03
    BNE notAlreadyShooting
    JMP doneShooting
notAlreadyShooting:
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 1 line: 
    ;;; if not already shooting, change it's action step (assuming the shoot action step is 03)
    ChangeObjectState #$03, #$02
    
    ;;; if you want your player stops when he's shooting, comment out the following lines:
    LDA Object_movement,x
    AND #%00001111
    ORA #%00000010
    STA Object_movement,x
    LDA #$00
    STA Object_h_speed_hi,x
    STA Object_h_speed_lo,x
    STA Object_v_speed_hi,x
    STA Object_v_speed_lo,x
    
;; if was already shooting
wasAlreadyShooting:

    LDA Object_movement,x
    AND #%00000111
    STA temp2
    TAY

    LDA Object_x_hi,x
    SEC 
    SBC #$08 ;; width of projectile 
    STA temp

    LDA temp
    ;;; offset x for creation
    CLC
    ADC projOffsetTableX,y
    STA temp
    LDA temp3
    ADC #$00
    STA temp3

    LDA Object_y_hi,x
    CLC
    ADC projOffsetTableY,y
    sec
    sbc #$08 ;; height of projectile
    STA temp1   
    
    
    CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, currentNametable
    
    ;DEC limitProjectile
  
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x
    
    PlaySound #SND_SHOOT
doneShooting:
    RTS
 
Top Bottom