snake5 icon

psh animation state machine code

snake5 | PRO | 03/05/17 02:29:46 PM UTC | 0 ⭐ | 856 👁️ | Never ⏰ | []
JavaScript |

510 B

|

None

|

0 👍

/

0 👎

class PSHPlayerStateMachine
{
    global _char = "images/player_char";
    
    function _stand2run(c){ return abs( c.velocityX ) > 4; }
    
    function init(c)
    {
        return "stand";
    }
    function stand(c)
    {
        c.PlayAnim( "stand", true );
        
        if( this._stand2run(c) ) return "run";
    }
    function run(c)
    {
        c.PlayAnim( "run", true, 0, abs( c.velocityX ) / 200 );
        
        if( !this._stand2run(c) ) return "stand";
    }
}
 
class PSHPlayerCharacter : PSHCharacter
{
    global CharInfoAndStates = PSHPlayerStateMachine;
}

Comments