Ducking with animation frames only (platformer)

Post Reply
User avatar
Mugi
Posts: 416
Joined: Thu Dec 27, 2018 8:30 pm

Ducking with animation frames only (platformer)

Post by Mugi » Tue Jan 08, 2019 12:33 pm

I'm not sure how useful this is to other people, but in my game, im REALLY needing the action states for other things, and
ducking i wanted to have, but ducking is more or less just a visual and doesnt really serve any purpose that would warrant it to get an action state of it's own.
(in my game, a down press of dpad is just hardcoded to do things.)

so i put together a set of inputs that make the player enter a ducking animation derived from idle state, instead of going into ducking action state.

here's how it's done;

1) make sprite for "ducking left" and "ducking right"
2) assign the sprites in your idle state (action state 00) in positions "down right" and "down left"

Image

3) make 2 new Input script, duck.asm and releaseDuck.asm

here's the code:

duck.asm

Code: Select all

    ;FACE_DOWN_RIGHT    = #%00000001    ; we use this to crouch, facing right.
    ;FACE_RIGH          = #%00000010
    
    ;FACE_LEFT          = #%00000110
    ;FACE_DOWN_LEFT     = #%00000111    ; we use this to crouch, facing left.
    LDX player1_object
    
    LDA gamepad
    AND #%11010000
    BNE skipCrouch

    LDA Object_movement,x
    CMP #%00000110
    BEQ faceLeft
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_DOWN_RIGHT
    RTS
    
faceLeft:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_DOWN_LEFT
skipCrouch:
    RTS
releaseDuck.asm:

Code: Select all

    LDX player1_object
    LDA Object_movement,x
    CMP #%00000111
    BEQ faceLeft_noCrouch
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeft_noCrouch:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS
assign duck.asm in input editor to "Press Down" and releaseDuck.asm to "Release Down"
enjoy ducking without wasting an action state :)



feel free to improve the code, im not the best of assembly programmers :P
User avatar
dale_coop
Posts: 3058
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Ducking with animation frames only (platformer)

Post by dale_coop » Tue Jan 08, 2019 12:35 pm

Smart! Love it. Thanks Mugi, for sharing that <3
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
GX79
Posts: 2
Joined: Wed Feb 20, 2019 12:19 pm

Re: Ducking with animation frames only (platformer)

Post by GX79 » Fri Mar 15, 2019 5:01 pm

Is it possible to temporarily ignore the top collision points so you can avoid enemies when ducking?
User avatar
Mugi
Posts: 416
Joined: Thu Dec 27, 2018 8:30 pm

Re: Ducking with animation frames only (platformer)

Post by Mugi » Fri Mar 15, 2019 5:07 pm

yes, it's a flag of object_vulnerability (i dont remember which one)
all you have to do is make your input script to write that flag as 1 when you're ducking and remove it when you're not.
digit2600
Posts: 171
Joined: Mon Apr 16, 2018 9:50 pm

Re: Ducking with animation frames only (platformer)

Post by digit2600 » Sat Mar 16, 2019 4:40 am

In object actions theres an ignore top collision flag. I only just discovered it last week lol... meanwhile I was trying to do it in code and having no luck
User avatar
Mugi
Posts: 416
Joined: Thu Dec 27, 2018 8:30 pm

Re: Ducking with animation frames only (platformer)

Post by Mugi » Sat Mar 16, 2019 4:53 am

the thing is that if you do your ducking like this (using a face direction of idle state) you cant set the object flag to the idle state as it would cut the hitbox during idle.
that flag can be set in code though, which is nice because this method spares you from using an action state for your ducking.
Post Reply