Ducking with animation frames only (platformer)

Mugi

Member
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"

idle_state.png


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

here's the code:

duck.asm
Code:
    ;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:
    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 :)

https://youtu.be/Vf_qFwUbDt4

feel free to improve the code, im not the best of assembly programmers :p
 

Mugi

Member
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

Member
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
 

Mugi

Member
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.
 

Lother

Member
I tried to use your code for Crouching in my game, but I crouch a second time I get that strange glitch shown in the video below.

[media]https://www.youtube.com/watch?v=_DWWCX7OW4g[/media]

I also want to duplicate and use that code but for my character looking up while pressing UP. What are the few modification I have to do for this to work ?

(Oh, and you can also see a new boss enemy I'm working on too.)
 

dale_coop

Moderator
Staff member
You might have this kind of glitch when you don't have the same frame count for your animations (check that all the animations assigned to a animation type have the same frame count).
Or it might happen because your animations are using too much memory (size or your player too big or too much frames)... Make a backup of your project (or your objects) and try redoing the animation frames.
 

Lother

Member
dale_coop said:
You might have this kind of glitch when you don't have the same frame count for your animations (check that all the animations assigned to a animation type have the same frame count).
Or it might happen because your animations are using too much memory (size or your player too big or too much frames)... Make a backup of your project (or your objects) and try redoing the animation frames.

That was indeed the count of frames that was different between the Ducking animation and the Idle one.
 

Lother

Member
Ok, so I've been trying to fiddle the scripts around in order for my character to play a special animation whenpressing Up with these codes:

lookup.asm
Code:
    ;FACE_UP_RIGHT    = #%00000011    ; we use this to crouch, facing right.
    ;FACE_RIGH          = #%00000010
    
    ;FACE_LEFT          = #%00000110
    ;FACE_UP_LEFT     = #%00000101    ; we use this to crouch, facing left.
    LDX player1_object
    
    LDA gamepad
    AND #%11010000
    BNE skipCrouchToo

    LDA Object_movement,x
    CMP #%00000110
    BEQ faceLeftToo
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_RIGHT
    RTS
    
faceLeftToo:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_LEFT
skipCrouchToo:
    RTS

And releaseLookup.asm:

Code:
    LDX player1_object
    LDA Object_movement,x
    CMP #%00000101
    BEQ faceLeft_noUp
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeft_noUp:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS

But the animation doesn't play when pressing Up. Any idea how to make that work? (The animations are set up to "Up Right" and "Up Left" in the idle animation type.)
 

dale_coop

Moderator
Staff member
Assign it to "PRESS" up...?

I would try something like this...
for lookup.asm:

Code:
    ;; checking if another direction button is pressed, at the same time
    ;;(not sure you really need those 3 lines):
    LDA gamepad
    AND #%11100000
    BNE skipLookUp

    LDA Object_movement,x
    AND %00000111
    CMP #%00000110
    BEQ faceLeftLookUp
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_RIGHT
    RTS
    
faceLeftLookUp:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_LEFT
skipLookUp:
    RTS

Note: I think you even don't need the 3 lines about "gamepad"


And releaseLookup.asm:

Code:
    LDX player1_object
    LDA Object_movement,x
    AND #%00000111
    CMP #%00000101
    BEQ faceLeftNoLookUp
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeftNoLookUp:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS

Sorry, didn't test...
 

Lother

Member
It works, but when my character is facing Left it sometimes plays the "Up Right" animation instead of the correct one (the "Up Left") and my animations are correctly set. It's a pretty minor detail but it looks a bit... odd.
 

dale_coop

Moderator
Staff member
OK...
Try those ones:

press:
Code:
    ;; checking if another direction button is pressed, at the same time
    ;;(not sure you really need those 3 lines):
    LDA gamepad
    AND #%11100000
    BNE skipLookUp

    LDA Object_movement,x
    AND %00000111
    CMP #%00000110
    BEQ faceLeftLookUp
    CMP #%00000101
    BEQ faceLeftLookUp
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_RIGHT
    RTS
    
faceLeftLookUp:
    StopMoving player1_object, STOP_RIGHT
    StopMoving player1_object, STOP_LEFT
    FaceDirection player1_object, FACE_UP_LEFT
skipLookUp:
    RTS


And release:
Code:
    LDX player1_object
    LDA Object_movement,x
    AND #%00000111
    CMP #%00000110
    BEQ faceLeftNoLookUp
    CMP #%00000101
    BEQ faceLeftNoLookUp
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_RIGHT
    RTS
faceLeftNoLookUp:
    ChangeObjectState #$00, #$03
    FaceDirection player1_object, FACE_LEFT
    RTS
 

Lother

Member
Indeed, but I've remarked something. It looks like the animation works when I press Up after pressing Left and Up. Maybe it will help.
 

dale_coop

Moderator
Staff member
Check your "Project Settings > User Constants" the STARTING_DIRECTION (for a platformer, the value should be 1 or 2). Might help...?
 

Lother

Member
dale_coop said:
Check your "Project Settings > User Constants" the STARTING_DIRECTION (for a platformer, the value should be 1 or 2). Might help...?

I did check, it is indeed at 2. I didn't touch it once though.
 
Top Bottom