Player (class)

From Moondust Wiki
Jump to navigation Jump to search

This class provides fields/functions for managing Players in the current level.

Player class
Type Function/Field Return values/Value type Description
Constructor myPlayer = Player() Player Construct a new Player-Object. This objects references to the first player. You might want to use the constants player and player2 (for the 2nd player) instead.
Constructor myPlayer = Player(int internalIndex) Player Construct a new Player-Object. This object reference to the player given in internalIndex. 1 = first player, 2 = second player
function Player:mem(int offset, int fieldtype, object value) nil Sets a value of the Player struct at a specific address-offset.
function Player:mem(int offset, int fieldtype) object Returns a value of the Player struct at a specific address-offset.
function Player:kill() nil Kills the player.
function Player:harm() nil Harms the player.
Field Player.x double The x coordinate of the player.
Field Player.y double The y coordinate of the player.
Field Player.speedX double The x-speed of the player.
Field Player.speedY double The y-speed of the player.
Field (ro) Player.screen RECT Returns the distances from the player's coordinates to the screen boundaries of player camera. Note that this means width is 'right' + 'left', and not 'right' - 'left', etc.
Field (ro) Player.section int Returns the current section number of the player.
Field (ro) Player.sectionObj Section Returns the current section object of the player.
Field powerup int The current powerup state the player is in.
Field reservePowerup int The npc-id in the powerup box of the player.
Field width int The player width.
Field height int The player height.
Field (ro) holdingNPC NPC or nil The npc which the player is holding. If the player holds nothing then nil is returned.
Field upKeyPressing boolean True, if the player is pressing the up key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field downKeyPressing boolean True, if the player is pressing the down key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field leftKeyPressing boolean True, if the player is pressing the left key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field rightKeyPressing boolean True, if the player is pressing the right key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field jumpKeyPressing boolean True, if the player is pressing the jump key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field altJumpKeyPressing boolean True, if the player is pressing the alt jump key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field runKeyPressing boolean True, if the player is pressing the run key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field altRunKeyPressing boolean True, if the player is pressing the alt run key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field dropItemKeyPressing boolean True, if the player is pressing the drop item key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field pauseKeyPressing boolean True, if the player is pressing the pause key. Can be overwritten with the Event onInputUpdate, to lock or reverse controls (LunaLua ≥v0.7)
Field (ro) isValid boolean Checks if the player is acutally valid. With this method you can check if a second player is in the level.

There are also raw fields. These fields are not maintained and not camel-case affected!