Get some Modified platformer code with melee attack here

digit2600

Member
This is not perfect... There's still one part i'm trying to tighten up (moving while jumping and attacking), but other than that, with this, you can perform a jumping attack, and you will stand in place while attacking if walking. There's also one more issue, where the melee doesn't conform to the players physics while in a jump attack...But yeah.. If anyone wants to try it out, here ya go. Oh, there's a crouching script too that's a little buggy at the moment....
#$03 is attacking
#$04 is crouching




Code:
;;;Move left code;;;;
    LDX player1_object
    GetCurrentActionType player1_object
     
     CMP #$01;;walk
    BEQ+
    CMP #$03;;attack
    BEQ ++
    CMP #$02;; jump
    BEQ +
    
    
     
    ChangeObjectState #$01, #$03
    
 +
    StartMoving player1_object, MOVE_LEFT
 ++
     FaceDirection player1_object, FACE_LEFT
      
      
     
      
    RTS
    
    ;;;;;;;Move Right code;;;;;;;;;;;
        LDX player1_object
    GetCurrentActionType player1_object
    CMP #$01;;walk
    BEQ+
   
    CMP #$03    ;; attack
    BEQ ++  
    
    CMP #$02;; jump
    
    BEQ +
     
    ChangeObjectState #$01, #$03 
    +
    StartMoving player1_object, MOVE_RIGHT
 ++
    FaceDirection player1_object, FACE_RIGHT
    
    
    
     
    RTS
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Melee 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 #$01; if walking
 BNE notAlreadyAttacking 
 CMP #$02; if jumping
 BNE notAlreadyAttacking 
 CMP #$04; if ducking 
 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 #$03, #$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, #$02, #$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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;crouching code;;;;;;;;;;;;;;;;;;;;;;;;;;
   
    LDX player1_object
    LDA Object_status,x
    AND #%00000100
    BEQ +
    ChangeObjectState #$04, #$03
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    +
  
    RTS
    ;;;;;;;;;;;;;;;;;;;;;
 

dale_coop

Moderator
Staff member
Some possible cleanup: you could remove all the part for up/down facing... and keep just the left/right.
 

digit2600

Member
good call... i didn't wanna mess with it too much, as I didn't bother saving it as a new version, so this should still be functional in adventure mode just fine
 

Mugi

Member
i im plemented the crouching code from this into my game, and it works pretty well, though i noticed it has one slight issue going on with it.

if you press left or right while holding down, and then release it, you will stay in the crouch animation and just start sliding instead of getting back to the run/idle.
i played around with this trying to configure the inputs (holds/presses) to deal with it, but no combination i found was capable of fully fixing the sliding and/or other animation problems that came with multiple button presses, so here's my solution for that.


Code:
LDX player1_object
    
    LDA gamepad
    AND #%11010000
    BNE skipCrouch
    ;LDA onGround
   
    LDA Object_status,x
    AND #%00000100 ;; not on ground
    BEQ skipCrouch
    
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    ChangeObjectState #$04, #$03
    ++

    skipCrouch:
    RTS

i mostly copied the routine out of "ChangeToIdleAnimation" and not really sure how "proper" way this is, but it works.
what this does is checks for other inputs on the D-pad and will disallow you to crouch if you are moving.

so now you will have to stop before you crouch, but it will (as far as i've tested it) not allow you to glitch the animations by buffering inputs anymore.

here's quick test i made showing inputs.

https://youtu.be/c-h0rt8wjKI


that said, i must be slightly retarded, but i cant figure out for the life of me how to use your melee code.
i gave my player a state $04 attack state, and made animations for that, and i created a melee object but i cant figure out how this is supposed to be used.
 
Top Bottom