Melee Troubles

ppaquette

New member
Hello trusty helpers,
I've actually got the melee to work as I've exchanged blows with my enemy, however the representation of the melee weapon does not look the same in game as in engine:
2018-08-24.png

2018-08-24.png


Also, it only shows up on the first attack if I remain completely still. If I start moving and try to attack it registers as being there because of the enemy hit react, but it's not visible. Any ideas? Thanks in advance!!
 

MistSonata

Moderator
This sounds like one of the problems is with which way your character's facing in the engine. Even if you're doing a side-view platformer and only have left and right facing sprites and animations, the underlying engine still recognizes 8 directional facing. You'll need to compensate for this in the tool. I'd recommend setting up and down to either left or right and making sure that this is reflected in the object details>animation types and the melee offsets.

The second problem is probably that if you're facing left or right, the "create melee object" code is trying to spawn the object in the "projectile source" slot instead. If you watch the adventure tutorial on creating a melee weapon you'll see why. Try using the following script instead of the one included in the adventure module:

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
 ChangeObjectState #$02, #$01
 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, #$02, #$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

This is just the "create melee" script with the code that creates the "projectile source" object if the player is facing a certain direction commented out. I haven't tested it, but if it doesn't work let me know.
 

RadJunk

Administrator
Staff member
The offset is a little bit of a trick...sort of a holdover that's *technically* not implemented here precisely, but we thought we'd show it in this tutorial anyway.

When the thing is created, it essentially creates it at the player's x, minus the width of the object being created (which I think we did manually), plus the offset from the table that gets exported here.

You might have to look into your script that creates the melee and see exactly where it's creating it. What you're getting in that dialog is the offset. So...you'd have to subtract the appropriate width. You'll see it...it's the part that says SBC #$xx.

This is in hex value, so it's #$00 - #$0f (0-15), and then #$10-#$1f (16-31), etc etc etc.

Let me know if you find where I mean. :)
 

MistSonata

Moderator
Here's a tweaked version of the code you can try...

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
 ChangeObjectState #$02, #$01
 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 #$10 ;; width of weapon
    CLC
    ADC weaponOffsetTableX,y
    STA temp
    LDA temp1
    SEC
    SBC #$08
    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, #$02, #$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
 

Mihoshi20

Member
ppaquette said:
Hello trusty helpers,
I've actually got the melee to work as I've exchanged blows with my enemy, however the representation of the melee weapon does not look the same in game as in engine:
2018-08-24.png

Though I don't have much constructive to add, I have to say, that pic of the skeleton with the sword jammed into his eye-socket really made me laugh, and that expression on his face just sells it. I just imagined him saying in a droopy like voice... "Oh no, I've done it again."
 

acaudel

Member
Adding to the topic of "Melee Troubles":

I had my own trouble with the Melee weapon, but this was in the Adventure Module.
I figured out what was wrong, but I wanted to share just in case anyone else had the same problem that I did.
I thought I had everything set up correctly, and the melee weapon worked fine in 3 directions: left, up, and right.
But for some reason, the melee weapon would not appear when attacking down.
The character animation played correctly, but no weapon appeared.
I wracked my brain trying to figure it out, until finally I noticed something.
In the vertical melee weapon's object details, in the Details tab, I had accidentally checked both the "player weapon" and "pickup / powerup" boxes.
When the character attacked up, the melee weapon appeared above the player bounding box, so there was no problem.
But, when the player attacked down, the player's bounding box hit the weapon and thought that it was a pickup / powerup, so the weapon disappeared.
Silly mistake, I know. But, maybe this post will help someone else in the future!
 

digit2600

Member
how have I missed this thread?? I just spent days trying to get my melee function to work in a half assed state lol....
 
Top Bottom