Melee Attack stops working properly after player starts moving

CutterCross

Active member
So, I'm probably doing something dumb here, but I've been having quite a few issues with the Melee attack in the Platformer Module that I'm not sure how to fix. (I'm using a slightly modified version of the Adventure Tutorial's Melee Attack.)

https://www.youtube.com/watch?v=PuZbITC_9f8&feature=youtu.be

1. Everything works right when the player first spawns. The Melee Attack spawns in the right spot and the player plays his correct animation. As soon as he moves, however, the Melee attack always spawns near his top-left corner (which is NONE of the offsets I made in the GameObjects offset tab), and the player no longer plays his attacking animation.

2. For some reason, the Melee Attack won't spawn if the player reaches the peak of his jump, but WILL spawn if he hasn't reached his full jump height.

3. There's no limit on how many Melee Attacks the player can spawn by rapidly mashing the Attack button (B).
 

CutterCross

Active member
MistSonata said:
Could you post your melee script? That might help
Sure, it's just slightly modified from the basic Adventure Game Melee Script
Code:
 LDA gameHandler
 AND #%00100000
 BEQ notNPCstate_attack
 JMP doneAttacking
notNPCstate_attack
 LDA weaponsUnlocked
 AND #%00000001
 BNE canAttack
 JMP doneAttacking
canAttack:
LDX player1_object
 GetCurrentActionType player1_object

 CMP #$02
 BNE notAlreadyAttacking 
 JMP doneAttacking
notAlreadyAttacking
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 
 LDA Object_movement,x          ;
 CMP #$00                       ;If player is moving, skip changing the animation
 BNE +                          ;
 LDX player1_object             ;
 ChangeObjectState #$04, #$02   ;
 +                              ;
 
 LDA Object_movement,x
 AND #%00001111
 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
 
 LDA Object_x_hi,x
 STA temp
 LDA Object_y_hi,x
 STA temp1
 
 LDA Object_movement,x
 AND #%00000111
 STA temp2
 AND #%00000010 ;; this will be 0 on up and down, but 1 on left right
    BNE createLRmelee
    LDA temp2
    TAY
    LDA temp
    SEC
    SBC #$08 ;; width of weapon
    CLC
    ADC weaponOffsetTableX,y
    STA temp
    LDA temp1
    SEC
    SBC #$10
    CLC
    ADC weaponOffsetTableY,y
    STA temp1
 
 CreateObject temp, temp1, #$01, #$00
JMP meleeCreated
createLRmelee:
    LDA temp2
    TAY
    LDA temp
    SEC
    SBC #$10 ;; width of weapon
    CLC
    ADC projOffsetTableX,y
    STA temp
    LDA temp1
    SEC
    SBC #$08
    CLC
    ADC projOffsetTableY,y
    STA temp1
    CreateObject temp, temp1, #$01, #$00
meleeCreated:
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    PlaySound #sfx_slash
doneAttacking:
    RTS


;;000 down
;010 right
;100 up
;110 left
I also only want the player to play his attacking animation while he's idle. It works fine on startup, but not when he moves.
 

MistSonata

Moderator
Try this instead:

Code:
 LDA gameHandler
 AND #%00100000
 BEQ notNPCstate_attack
 JMP doneAttacking
notNPCstate_attack
 LDA weaponsUnlocked
 AND #%00000001
 BNE canAttack
 JMP doneAttacking
canAttack:
LDX player1_object
 GetCurrentActionType player1_object

 CMP #$02
 BNE notAlreadyAttacking 
 JMP doneAttacking
notAlreadyAttacking
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 
 LDA Object_movement,x          ;
 CMP #$00                       ;If player is moving, skip changing the animation
 BNE +                          ;
 LDX player1_object             ;
 ChangeObjectState #$04, #$02   ;
 +                              ;
 
 LDA Object_movement,x
 AND #%00001111
 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
 
 LDA Object_x_hi,x
 STA temp
 LDA Object_y_hi,x
 STA temp1
 
 LDA Object_movement,x
 AND #%00000111
 STA temp2
 
    LDA temp2
    TAY
    LDA temp
    SEC
    SBC #$08 ;; width of weapon
    CLC
    ADC weaponOffsetTableX,y
    STA temp
    LDA temp1
    SEC
    SBC #$10
    CLC
    ADC weaponOffsetTableY,y
    STA temp1
 
 CreateObject temp, temp1, #$01, #$00
 
meleeCreated:
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    PlaySound #sfx_slash
doneAttacking:
    RTS


;;000 down
;010 right
;100 up
;110 left

The code was set up to load the projectile offset for the player facing left and right. The reason it looked fine before you started moving is because the default direction for when your player spawns is down, and if your character only faces left and right, the code that holds your direction is still there, just not shown.
 

CutterCross

Active member
MistSonata said:
Try this instead:

The code was set up to load the projectile offset for the player facing left and right. The reason it looked fine before you started moving is because the default direction for when your player spawns is down, and if your character only faces left and right, the code that holds your direction is still there, just not shown.
Thanks, that fixed the Melee Spawn issue. (Partially that is, I still had to mess around with the "width of weapon" value to get everything lined up, but it's all working now.) I've still got to fix the animation issue, but the spawning issue was the main thing I needed help with. Thanks a bunch!

I really need to buckle down and get my ASM skills up. It's definitely not my strong suit.
 
Top Bottom