Module LevelPlayerClass

Level Playable Character class, functions, and callback events

Class PlayerControllerBase

PlayerControllerBase:__init (player_obj) Controller constructor, once called on first initialization of Playable Character Controller.
Required to be defined in an Playable Character controller class!
PlayerControllerBase:onLoop (frameDelay) Event callback calling per every frame
PlayerControllerBase:onHarm (harmEvent) Event callback calling on attempt to hurt Playable Character
PlayerControllerBase:onTransform (characterID, stateID) Event callback calling on transform of playable character into another or on state change
PlayerControllerBase:onTakeNpc (npc) Event callback calling on attempt of player to take an NPC
PlayerControllerBase:onKillNpc (npc) Event callback calling on attempt of player to kill an NPC
PlayerControllerBase:onKeyPressed (keyType) Event callback calling on key pressing on playable character's controller device
PlayerControllerBase:onKeyReleased (keyType) Event callback calling on key releasing on playable character's controller device

Class BasePlayer

BasePlayer.characterID Current playable character ID (Read Only)
BasePlayer.stateID Current playable character's state ID (Read Only)
BasePlayer.direction Current playable character's face direction (Read Only)
BasePlayer.onGround Is playable character stays on solid ground (Read Only)
BasePlayer.isDucking Is playable character ducking (Read Only)
BasePlayer.globalState Global state information of a player
BasePlayer.health Playable character's health level
BasePlayer:getKeyState (keyType) Get pressed state of a specific key
BasePlayer:setAnimation (animationID, frameDelay) Change currently animation sequence
BasePlayer:playAnimationOnce (animationID, frameDelay, fixedSpeed, locked, skipLastFrames) Play specified animation sequence once and switch previous animation back
BasePlayer:bump () Bump playable character vertically to down
BasePlayer:bump (upDirection) Bump playable character vertically
BasePlayer:bump (upDirection, bounceSpeed) Bump playable character vertically with custom bounce speed
BasePlayer:bump (upDirection, bounceSpeed, timeToJump) Bump playable character vertically with custom bounce speed
BasePlayer:setState (stateID) Change playable character's state/skin
BasePlayer:setCharacter (characterID) Change playable character
BasePlayer:setInvincible (state, delay) Set temporary invincability to playable character
BasePlayer:setInvincible (state, delay, enableSpriteBlinking) Set temporary invincability to playable character with blinking

Class PlayerHarmEvent

PlayerHarmEvent.do_harm Grand this event, it will be executed if this field is true, set it to false to reject this event
PlayerHarmEvent.damage Damage level caused by this event


Class PlayerControllerBase

Playble Character Controller base class, must be implemented for every Playable Character which needs more complex logic than engine provides
PlayerControllerBase:__init (player_obj)
Controller constructor, once called on first initialization of Playable Character Controller.
Required to be defined in an Playable Character controller class!

Parameters:

  • player_obj BasePlayer Reference to actual NPC object

Usage:

    class 'MyPlayer'
    
    function MyPlayer:initPros()
        self.timer = 0
        self.state = 0
        -- ...
    end
    
    function MyPlayer:__init(player_obj)
        self.player_obj = player_obj
        self:initProps()
    end
    
    -- ...
    
    return MyPlayer
PlayerControllerBase:onLoop (frameDelay)
Event callback calling per every frame

Parameters:

  • frameDelay double Frame delay in milliseconds. Use it for various timing processors.

Usage:

    class 'MyPlayer'
    
    -- A timer value
    local timer = 0
    
    -- Play sound every one second
    function ticker(frameDelay)
        -- Iterate a timer
        timer = timer + frameDelay
        -- Check if timer reaches one whole second
        if(timer >= 1000)then
            -- Play a tick sound
            Audio.playSoundByRole(SoundRoles.MenuScroll)
            -- Reset timer to zero without lost of timing accuracy
            timer = timer - 1000
        end
    end
    
    function MyPlayer:onLoop(frameDelay)
        ticker(frameDelay)
    end
    
    return MyPlayer
PlayerControllerBase:onHarm (harmEvent)
Event callback calling on attempt to hurt Playable Character

Parameters:

  • harmEvent PlayerHarmEvent Harm event context. Can be used to identify reasons and gives ability to reject this event.

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onHarm(harmEvent)
        -- Say "Ouch" when Playable Character was kicked to ass, but don't harm it
        if(harmEvent.do_harm == true)then
            Audio.playSound(5);
            harmEvent.do_harm = false
        end
    end
    
    return MyPlayer
PlayerControllerBase:onTransform (characterID, stateID)
Event callback calling on transform of playable character into another or on state change

Parameters:

  • characterID ulong ID of destinition playable character
  • stateID ulong ID of destinition playable character's state

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onTransform(characterID, stateID)
        -- Do something here...
    end
    
    return MyPlayer
PlayerControllerBase:onTakeNpc (npc)
Event callback calling on attempt of player to take an NPC

Parameters:

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onTakeNpc(npc)
        -- Do something here...
    end
    
    return MyPlayer
PlayerControllerBase:onKillNpc (npc)
Event callback calling on attempt of player to kill an NPC

Parameters:

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onKillNpc(npc)
        -- Do something here...
    end
    
    return MyPlayer
PlayerControllerBase:onKeyPressed (keyType)
Event callback calling on key pressing on playable character's controller device

Parameters:

  • keyType GlobalConstants.PLAYER_KEY_CODES Key type pressed on controller device which is attached to this playable character

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onKeyPressed(keyType)
        -- Do something here...
    end
    
    return MyPlayer
PlayerControllerBase:onKeyReleased (keyType)
Event callback calling on key releasing on playable character's controller device

Parameters:

  • keyType GlobalConstants.PLAYER_KEY_CODES Key type of released on controller device which is attached to this playable character

Usage:

    class 'MyPlayer'
    
    function MyPlayer:onKeyReleased(keyType)
        -- Do something here...
    end
    
    return MyPlayer

Class BasePlayer

Playable Character Object base class, inherited from PhysBaseClass.PhysBase
BasePlayer.characterID
Current playable character ID (Read Only)
  • characterID ulong
BasePlayer.stateID
Current playable character's state ID (Read Only)
  • stateID ulong
BasePlayer.direction
Current playable character's face direction (Read Only)
  • direction int -1 - Player is faced to left, +1 - Player is faced to right
BasePlayer.onGround
Is playable character stays on solid ground (Read Only)
  • onGround bool
BasePlayer.isDucking
Is playable character ducking (Read Only)
  • isDucking bool
BasePlayer.globalState
Global state information of a player
BasePlayer.health
Playable character's health level
  • health int
BasePlayer:getKeyState (keyType)
Get pressed state of a specific key

Parameters:

  • keyType GlobalConstants.PLAYER_KEY_CODES Code of key code

Returns:

    bool true if key is pressed, false is released
BasePlayer:setAnimation (animationID, frameDelay)
Change currently animation sequence

Parameters:

  • animationID int Index of animation sequence in the calibration file
  • frameDelay int Delay of one animation frame in milliseconds
BasePlayer:playAnimationOnce (animationID, frameDelay, fixedSpeed, locked, skipLastFrames)
Play specified animation sequence once and switch previous animation back

Parameters:

  • animationID int Index of animation sequence in the calibration file
  • frameDelay int Delay of one animation frame in milliseconds
  • fixedSpeed bool Forbid framedelay change while animation is playing
  • locked bool Forbid animation switch while sequence is playing
  • skipLastFrames int Count of last frames to skip until end animation
BasePlayer:bump ()
Bump playable character vertically to down
BasePlayer:bump (upDirection)
Bump playable character vertically

Parameters:

  • upDirection bool Bump playable character up, if false - to down
BasePlayer:bump (upDirection, bounceSpeed)
Bump playable character vertically with custom bounce speed

Parameters:

  • upDirection bool Bump playable character up, if false - to down
  • bounceSpeed double Initial flying speed
BasePlayer:bump (upDirection, bounceSpeed, timeToJump)
Bump playable character vertically with custom bounce speed

Parameters:

  • upDirection bool Bump playable character up, if false - to down
  • bounceSpeed double Initial flying speed
  • timeToJump int Allow playable character jump higher in specified time delay, doesnt affects down directed bounce
BasePlayer:setState (stateID)
Change playable character's state/skin

Parameters:

  • stateID ulong ID of state to toggle
BasePlayer:setCharacter (characterID)
Change playable character

Parameters:

  • characterID ulong ID of playable character to toggle
BasePlayer:setInvincible (state, delay)
Set temporary invincability to playable character

Parameters:

  • state bool true to turn invincibility on, false - turn it off
  • delay double Delay of invincibility effect in milliseconds
BasePlayer:setInvincible (state, delay, enableSpriteBlinking)
Set temporary invincability to playable character with blinking

Parameters:

  • state bool true to turn invincibility on, false - turn it off
  • delay double Delay of invincibility effect in milliseconds
  • enableSpriteBlinking bool Blink sprite of playable character while invincibility is active

Class PlayerHarmEvent

Playable Character Harm Event context
PlayerHarmEvent.do_harm
Grand this event, it will be executed if this field is true, set it to false to reject this event
  • do_harm bool
PlayerHarmEvent.damage
Damage level caused by this event
  • damage int
generated by LDoc 1.4.6 Last updated 2017-08-21 02:20:32