Functions
addDisplay
- in string name
- in int x
- in int y
- in int type
- out Display
After adding a new Display object also remember to set it visible using the Display:setVisible method.
DISPLAY_TIME_LEFT displays the timeLeft counter DISPLAY_MESSAGE displays a text message DISPLAY_SCORE displays the user score DISPLAY_LIVES display available lives DISPLAY_HP display the hp counter DISPLAY_DEBUG displays the debug console
when a game is run there are already several displays defined. you may modify these displays using getDisplay() with the appropriate name string.
example
local displayId; displayId = findDisplay("timeLeft"); debug("timeLeft id: " .. displayId); displayId = findDisplay("score"); debug("score id: " .. displayId); local timeLeft = getDisplayByName("timeLeft"); timeLeft:setColor(0xff, 0xff, 0, 0x80); timeLeft:move(SCREENLEN - 100, 0); timeLeft:setFontSize(50); local score = getDisplayByName("score"); score:setColor(0xff, 0xff, 0xff, 0x80); score:setFontSize(24); local t = addDisplay("test", 64, 64, DISPLAY_MESSAGE); t:setText("this is a test\nSonia and the Pumpkins"); t:show();
addLayer
- in string name
- in int type
- in int hSpeed*
- in int vSpeed*
- out Layer
in parameter hSpeed : optional and can be omitted.
in parameter vSpeed : optional and can be omitted.
addSprite
- in int x
- in int y
- in int imageSet
- in int imageNo
- in int aim
- in int objectType
- in int imageSet*
- in int imageNo*
- out Sprite
in parameter imageSet : optional and can be omitted.
in parameter imageNo : optional and can be omitted.
addToHP
- in int hitPoints
- out int
addToHP will check for over bound value. if the player goes over maxHP, the value will be adjusted automatically
this function will also update the hp counter on screen
addToInventory
- in int objectType
- out void
addToScore
- in int points
- out int current score
also note that if the value is negative, it will get deducted from the total no test is performed to check for negative scores or overflow
alert
- in string text
- out void
alert("welcome home");
AND
- in int a
- in int b
- out int
callGameEvent
- in int eventId
- out void
EG_INIT_GAME EG_PREPARE_LEVEL EG_COMPLETE_LEVEL EG_DEATH EG_GOAL_COLLECTED EG_GOAL_KILLED
This is an example of usage.
local sprite = getSprite(self); if sprite:get("touched") ~= 1 then local image = sprite.imageNo + 1 if (image < sprite:frameCount()) then sprite:unMap(); sprite:setImage(image); sprite:map(); end if (image + 1) == sprite:frameCount() then sprite:unmarkAsGoal(); addToScore( 10 ) callGameEvent(EG_GOAL_KILLED); end sprite:set("touched",1); end
callLvEvent
- in int event
- out void
EL_CREATE EL_DRAW EL_RESTART EL_GOAL_COLLECTED EL_LEVEL_COMPLETED EL_TIMEOUT EL_KEY_PRESSED EL_KEY_UP EL_GOAL_KILLED EL_HANDLER
Alias: callLevelEvent
callTrigger
- in int key
- out void
clearDisplay
- in void
- out void
clearDisplay();
clearKeys
- in void
- out void
copySprite
- in Sprite src
- out Sprite newSprite
CAUTION: using this function inside an handler such as OnSpawn can cause an infinite loop which will crash the engine.
counter_add
- in string name
- in int variance
- out int new_value
counter_add("coins", 1);
Alias: counters_add
counter_dec
- in string name
- out int new_counter_value
Alias: counters_dec
counter_get
- in string name
- out int
Alias: counters_get
counter_inc
- in string name
- out int new_counter_value
Alias: counters_inc
counter_set
- in string name
- in int value
- out void
Alias: counters_set
countGoals
- in void
- out int
debug("++goals: " .. countGoals());
debug
- in string
- out void
debugClear
- in void
- out void
decTimeLeft
- in void
- out void
if mtime >= getNextSecond() then setNextSecond( mtime + 1000 ); if (not paused and getTimeLeft() > 0) then decTimeLeft(); if getTimeLeft() == 0 and closureEvent == EVENT_NO_EVENT then callLvEvent( EL_TIMEOUT ); setClosure( EVENT_TIMEOUT ); end end end
display_enableShadows
- in int displayId
- in bool shadow
- out void
example
local id = addDisplayC("goalCount", 258, 0, DISPLAY_MESSAGE); displaySetText(id, "XX"); displaySetVisible ( id, true ); displayEnableShadows( id, true );
Alias: displayEnableShadows
display_move
- in int displayId
- in int x
- in int y
- out void
example
local id = addDisplayC( "playerIcon", 60, 60, DISPLAY_IMAGE); displaySetXY(id, 0, 128); displaySetImage ( id, OBJECT_PLAYERS , 4 ); displaySetVisible ( id, true );
Alias: displaySetXY
display_new
- in string name
- in int x
- in int y
- in int type
- out int
you can use any of the DISPLAY_XXXX constants for ``type``.
DISPLAY_TIME_LEFT DISPLAY_MESSAGE DISPLAY_SCORE DISPLAY_LIVES DISPLAY_HP
after adding a new display also remember to set it visible using the displaySetVisible function.
-- create a display of an image -- using the frame set 'ANNIE.OBL' -- 0 is first image local id = addDisplayC( "petImage", 60, 60, DISPLAY_IMAGE); displaySetImage ( id, IMAGES_ANNIE_OBL , 0 ); displaySetVisible ( id, true );
see addDisplay for more sample usages.
Alias: addDisplayC
display_remove
- in int displayId
- out void
Alias: removeDisplayById
display_setAlpha
- in int displayId
- in int alpha
- out void
Alias: displaySetAlpha
display_setColor
- in int displayId
- in int red
- in int green
- in int blue
- in int alpha
- out void
Alias: displaySetColor
display_setExpireTime
- in int displayId
- in int time
- out void
Alias: displaySetExpireTime
display_setFlagXY
- in int displayID
- in int flagX
- in int flagY
- out void
FLAG_X_NONE = 0; FLAG_X_ALIGN_LEFT = 1; FLAG_X_ALIGN_RIGHT = 2; FLAG_X_ALIGN_CENTER = 3; FLAG_Y_NONE = 0; FLAG_Y_ALIGN_TOP = 1; FLAG_Y_ALIGN_BOTTOM = 2; FLAG_Y_ALIGN_CENTER = 3;
display_setFont
- in int displayID
- in int fontID
- out void
display_setFontSize
- in int displayId
- in int pxSize
- out void
local id = addDisplayC("goalCount", 258, 0, DISPLAY_MESSAGE); displaySetText(id, "XX"); displaySetVisible ( id, true ); displayEnableShadows( id, true ); displaySetShadowOffset(id, 2, 2); displaySetFontSize(id, 14);
Alias: displaySetFontSize
display_setImage
- in int displayId
- in int imageSet
- in int imageNo
- out void
imageSet is set from the gameDB. Use the IMAGES_XXXX constants. imageNo are zero based index (from the first image, #0).
Note that each display can only accomodate one thing. If you assign an image to display that originally contained text. That text will be gone.
Alias: displaySetImage
display_setShadowColor
- in int displayId
- in int red
- in int green
- in int blue
- in int alpha
- out void
local id = addDisplayC("lives", 188, 0, DISPLAY_LIVES); displaySetVisible ( id, true ); displayEnableShadows( id, true ); displaySetShadowOffset(id, 2,2); displaySetShadowColor(id, 200, 200, 240, 128);
Alias: displaySetShadowColor
display_setShadowOffset
- in int displayId
- in int tx
- in int ty
- out void
local id = addDisplayC("lives", 188, 0, DISPLAY_LIVES); displaySetVisible ( id, true ); displayEnableShadows( id, true ); displaySetShadowOffset(id, 2,2);
Alias: displaySetShadowOffset
display_setTemplate
- in int displayID
- in string template
- out void
Example of templates. These follow the sprintf format. See C++ documentation for details.
"%.3d" "%.8d" "%.2d"
display_setText
- in int displayId
- in string text
- out void
example
local id = findDisplay("goalCount"); -- local goals = sprintf( "%.2d", countGoals() ); local goals = sprintf("%.2d", getGoalLeft()); displaySetText( id, goals ) ;
Alias: displaySetText
display_setType
- in int displayId
- in int type
- out void
DISPLAY_TIME_LEFT DISPLAY_MESSAGE DISPLAY_SCORE DISPLAY_LIVES DISPLAY_HP DISPLAY_DEBUG DISPLAY_IMAGE
Alias: displaySetType
display_setVisible
- in int displayId
- in bool visible
- out void
Alias: displaySetVisible
display_sizeText
- in int displayId
- in string text*
- out int size
in parameter text : optional and can be omitted.
element_move
- in int layerId
- in int elementId
- in int aim
- out bool
UP DOWN LEFT RIGHT
return true if succesful
element_moveBy
- in int layerId
- in int elementId
- in int tx
- in int ty
- out bool
element_moveTo
- in int layerId
- in int elementId
- in int x
- in int y
- out bool
element_new
- in int layerId
- in int imageSet
- in int imageNo
- in int x
- in int y
- in bool show*
- out int elementId
in parameter show : optional and can be omitted.
Alias: addElement
element_setImage
- in int layerId
- in int elementId
- in int imageSet
- in int imageNo
- out bool
local id = findDisplay("goalIcon"); if id ~= -1 then displaySetImage ( id, IMAGES_DIAMOND_OBL , 0 ); displaySetVisible ( id, true ); end
element_setVisible
- in int layerId
- in int elementId
- in bool show
- out void
findDisplay
- in string name
- out int displayId
These can be system display or an a user defined one. (see example)
example:
-- find a previously created display -- and update it local id = findDisplay("goalCount"); local goals = sprintf( "%.2d", countGoals() ); displaySetText( id, goals ) ;
findLayer
- in String name
- out int layerId
Debug:printf("layer fw is :%d", getLayerC ( "fw"));
Alias: getLayerC
findSprite
- in int class
- in int origin*
- out int objId
Returns the objId if a match is found or otherwise -1.
local id = findSprte( CLASS_PLAYER_OBJECT );
in parameter origin : optional and can be omitted.
frameSet_getSize
- in int frameSet
- out int size
getBkColor
- in void
- out int red
- out int green
- out int blue
local bkColor = getBkColor(); Debug:printf("red: %u; green: %u; blue: %u", bkColor.red, bkColor.green, bkColor.blue);
Alias: getBkColorC
getBkColorC
- in void
- out int red
- out int green
- out int blue
local red; local green; local blue; red, green, blue = getBkColorC(); Debug:printf("red: %u; green: %u; blue: %u", red, green, blue);
getClosureEvent
- in void
- out int
getClosureTime
- in void
- out int
getDisplayById
- in int displayId
- out Display
getDisplayByName
- in string displayName
- out Display
getExtra
- in int objId
- out Extra
getGoalLeft
- in void
- out int goalLeft
example:
local id = findDisplay("goalCount"); -- countGoals requires more computation -- local goals = sprintf( "%.2d", countGoals() ); local goals = sprintf("%.2d", getGoalLeft()); displaySetText( id, goals ) ;
getHitTest
- in int objId
- in int aim
- out HitTest
see getHitTestC() for detais and HitTest class for details.
getHP
- in void
- out int player hp
example:
setHP(500); Debug:printf("hp: %d", getHP());
getImage
- in int objId
- out int imageSet
- out int ImageNo
local imageSet; local imageNo; imageSet, imageNo = getImage(selt);
getImageSize
- in int imageSet
- in int imageNo
- out int length
- out int height
local s = getSprite(self); local sx, sy = getImageSize(s.imageSet, s.imageNo); if s.y + sy >= BUFFERHEI then s:setState(STATE_DEAD); s:hide(); end
getLastKey
- in void
- out int keyCode
-- this would be called inside the keyPressed -- or keyUp handler local keyCode = getLastKey(); if keyCode == KEY_SPACE then setBkColor(rand(), rand(), rand()); else Debug:printf("last key: %d", keyCode); end
getLayer
- in string name
- out Layer
local layer = getLayer( "fw"); local element = layer:addElement(IMAGES_WHITEBALL_PNG, 0, 100, 100, true);
getLevelGoal
- in void
- out int levelGoal
GOAL_ONLY GOAL_UP GOAL_DOWN GOAL_LEFT GOAL_RIGHT GOAL_NO_COMPLETE
GOAL_ONLY: when all goal marked objects are collected (removed)
GOAL_UP: when all goal marked objects are collected and player reaches the top of level (LODERUNNER)
GOAL_DOWN: when all goal marked objects are collected and player reaches the bottom of level.
GOAL_LEFT: when all goal marked objects are collected and player reaches the most left position.
GOAL_DOWN: when all goal marked objects are collected and player reaches the most right position .
GOAL_NO_COMPLETE : this requires that the level be declared completed via EndLevel function as to automatic completion is checked.
Debug:printf("level goal: %d", getLevelGoal());
getLookUp
- in void
- out bool
getPlayer
- in void
- out Sprite
local player = getPlayer(); Debug:printf("player id= %d; name: %s", player.id, player.name);
getPlayerID
- in void
- out int objId
local id = getPlayerC(); Debug:printf("player_id: %x", id);
Alias: getPlayerC
getProto
- in int objType
- out Proto
getScore
- in void
- out int current score
debug( "score:" .. getScore());
getScreenSize
- in void
- out int len
- out int hei
local len local hei len, hei = getScreenSize()
getSkill
- in void
- out int skill
The value retuned is one of the following.
SKILL_NORMAL SKILL_NIGHTMARE SKILL_HELL SKILL_INSANE
example
if getSkill() == SKILL_NORMAL then debug("=>normal difficulty"); setTickScale(1000 / 80); addToHP(50); end
getSprite
- in int objId
- out Sprite
one thing to remember though is that modify individual fields of ``sprite`` will not alter the sprite. only your copy.
to make changes, you must call base methods such as s:setAim(). see example
local s = getSprite(self); debug("this is my detail:"); debug("x = " .. s.x); debug("y = " .. s.y); local aim = s.aim; s:unMap(); if s:canFall () then s:move( DOWN ) ; else if ticks % 5 == 0 then if s:isPlayerThere(aim) then s:attackPlayer(); end if aim < LEFT or aim > RIGHT then aim = LEFT end if s:canMove(aim) then s:move(aim); if s:canFall() then aim = XOR(aim, 1); s:move(aim); end else aim = XOR( aim, 1); end s:setAim ( aim ); end end s:map();
getTicks
- in void
- out int ticks
the number of ticks per seconds is directly related to the tick scale.
the best way to deal with ticks is time splicing
example
local ticks = getTicks(); if ticks % 5 == 0 then -- this will be executed 20% of the time -- or 1 in every 5 cycles end
getTickScale
- in void
- out int tickScale
getTime
- in void
- out int time elapsed
1000 = 1 second in real time
Debug:printf("%d", getTime() );
getVersion
- in void
- out int lgck_version
Debug:printf("version: %8.8x", getVersion());
getWrapFlag
- in void
- out int wrapFlag
Valid values are a combination of the following.
WRAP_UP WRAP_DOWN WRAP_LEFT WRAP_RIGHT
local wrapFlag = getWrapFlag(); Debug:printf("wrapFlag: %d", wrapFlag);
You can test for individual directions using the binary AND operator.
AND (wrapFlag, WRAP_UP)
hasGravity
- in void
- out bool gravity
if (hasGravity()) then debug("this level has gravity"); else debug("this level doesn't have gravity"); end
hasItem
- in int objType
- out bool result
killPlayer
- in void
- out void
killPlayer()
layer_clear
- in int layerId
- out bool result
local id = getLayerC("fw"); if layer_clear( id ) then Debug:printf("layer was cleared"); end
layer_delete
- in int layerOD
- out void
layer_getElement
- in int layerId
- in int elementId
- out int imageSet
- out int ImageNo
- out int x
- out int y
- out bool show
layer_getOffsetX
- in int layerID
- out int x
layer_getOffsetY
- in int layerID
- out int y
layer_getSize
- in int layerId
- out int size
local id = getLayerC ( "fw"); Debug:printf("layer size: %d", layer_getSize( id ));
layer_new
- in String name
- in int type
- in int hSpeed*
- in int vSpeed*
- out int layerId
LAYER_BK LAYER_FW
valid speeds
SPEED_NOSCROLL, SPEED_WHOLE, SPEED_1_2, SPEED_1_4, SPEED_1_8, SPEED_1_16, SPEED_1_32
in parameter hSpeed : optional and can be omitted.
in parameter vSpeed : optional and can be omitted.
Alias: addLayerC
layer_setOffsetX
- in int layerID
- in int x
- out void
layer_setOffsetY
- in int layerID
- in int y
- out void
layer_setSpeed
- in int layerID
- in int hSpeed
- in int vSpeed
- out void
loadGame
- in string filename
- out void
MAX
- in int value1
- in int value2
- out int
MIN
- in int value1
- in int value2
- out int
nextTick
- in void
- out void
openStream
- in string soundFile
- out bool
openStream("level01.ogg");
OR
- in int a
- in int b
- out int binary or (a , b)
pause
- in void
- out void
playSound
- in string sound...
- out void
This function can accept multiple inputs.
playSound("OUCH"); playSound("OUCH", "JUMP");
playStream
- in void
- out void
proto_get
- in int objType
- out array proto
Alias: getProtoC
rand
- in void
- out int
remap
- in void
- out void
removeDisplayByName
- in string name
- out void
removeFromInventory
- in int objType
- out void
resetInventory
- in void
- out void
saveGame
- in string filename
- out void
scene_getSize
- in void
- out int spriteCount
Alias: getSpriteCount
setBkColor
- in int red
- in int green
- in int blue
- out void
setBkColor(128, 40, 64);
Alias: setBkColorC
setBkColorC
- in int red
- in int green
- in int blue
- out void
-- set the background color at random setBkColorC(rand() % 256, rand() % 256, rand() % 256);
setBorderColor
- in int red
- in int green
- in int blue
- out void
setBorderColor(rand(),rand(),rand());
setEndLevel
- in void
- out void
setHP
- in int hitPoints
- out int the player's new hp count
example:
setHP(500); Debug:printf("hp: %d", getHP());
setKey
- in int keyCode
- in bool set
- out void
setLevelGoal
- in int goal
- out void
GOAL_ONLY GOAL_UP GOAL_DOWN GOAL_LEFT GOAL_RIGHT GOAL_NO_COMPLETE
GOAL_ONLY: when all goal marked objects are collected
GOAL_UP: when all goal marked objects are collected and player reaches the top of level (LODERUNNER)
GOAL_DOWN: when all goal marked objects are collected and player reaches the bottom of level.
GOAL_LEFT: when all goal marked objects are collected and player reaches the most left position.
GOAL_DOWN: when all goal marked objects are collected and player reaches the most right position .
GOAL_NO_COMPLETE : this requires that the level be declared completed via EndLevel function as to automatic completion is checked.
-- prevent this level from being completed automatically setLevelGoal(GOAL_NO_COMPLETE);
setLookup
- in bool lookup
- out void
setNextSecond
- in int mtime
- out void
-- test for timeout if mtime >= getNextSecond() then setNextSecond( mtime + 1000 ); if (not paused and getTimeLeft() > 0) then decTimeLeft(); if getTimeLeft() == 0 and closureEvent == EVENT_NO_EVENT then callLvEvent( EL_TIMEOUT ); setClosure( EVENT_TIMEOUT ); end end end
setSpeed
- in int speed
- out void
The speed is calculated as follow. 1000 / speed = number of cycles per second.
Each cycle is a tick. This is the base unit for everything in the game itself.
Also setTickScale()
setTickScale
- in int tickScale
- out void
Tick scale is calculate : 1000 / TickRate
TickRate is the number of times per second that the main loop is executed.
See example:
-- in this example the tick rate is 95 -- which is very fast !!! if SKILL == SKILL_INSANE then debug("=>insane difficulty"); setTickScale(1000 / 95); addToHP(-20); end
setWrapFlag
- in int wrapFlag
- out void
Wrap allows object to move from one edge of the map to the other.
A popular example of this is the classic PACMAN.
wrapFlag can be a combination of the following value.
WRAP_UP WRAP_DOWN WRAP_LEFT WRAP_RIGHT
-- allow wrapping only at the the top of the screen setWrapFlag( WRAP_UP ); -- check the flag to see that change was made local wrapFlag = getWrapFlag(); Debug:printf("A wrapFlag: %d", wrapFlag);
SHL
- in int value
- in int bits
- out int
showConsole
- in bool show
- out void
showConsole ( true ) showConsole ( false )
SHR
- in int value
- in int bits
- out int
snapshot_clear
- in void
- out void
snapshot_reload
- in void
- out bool
snapshot_take
- in void
- out void
sprintf
- in string format
- out string
local s = sprintf("My name is %s", "Frank"); -- print the result to the debug console Debug:printf(s); local s = sprintf("1 + 1 = %d", 2); -- print the result to the debug console Debug:printf(s);
sprite_activate
- in int objId
- out void
activateSprite(self)
Alias: activateSprite
sprite_addItem
- in int objId
- in int protoId
- in int count
- out void
sprite_attackPlayer
- in int objId
- out void
Alias: attackPlayer
sprite_callEvent
- in int objId
- in int event
- out void
local id = getPlayerC(); Debug:printf("player_id: %x", id); callObjEvent(id, EO_DEATH);
Event can be any of the following constants.
EO_SPAWN EO_ACTIVATE EO_DEATH EO_HURT EO_TOUCH EO_TRIGGER EO_HANDLER EO_SPLAT EO_HIT_TEST EO_ZKEY EO_AUTO EO_JUMP EO_FALL EO_LAND EO_LEAP EO_MOVE EO_FIRE
Alias: callObjEvent
sprite_canFall
- in int objId
- out bool
if (canFall ( self )) then debug ("I'm falling !!!"); end
Alias: canFall
sprite_canMove
- in int objId
- in int aim
- out bool
Alias: canMove
sprite_changeTo
- in int objId
- in int objType
- out void
Alias: changeTo
sprite_childCount
- in int spriteId
- out int childCount
sprite_clear
- in int objId
- out void
Alias: clearSprite
sprite_copy
- in int objId
- out int newObjId
CAUTION: using this function inside an handler such as OnSpawn can cause an infinite loop which will crash the engine.
Alias: copySpriteC
sprite_frameCount
- in int objid
- out int number_of_frames
sprite_freeze
- in int objId
- out void
It is your responsability to support this flag in custom handlers of your own making.
Alias: freezeSprite
sprite_get
- in int objId
- in mixed key
- out int value
The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.
EXTRA_ORGPROTO EXTRA_ORGX EXTRA_ORGY EXTRA_HP EXTRA_OLDAIM1 EXTRA_OLDAIM2 EXTRA_FALLHEIGHT EXTRA_LIVES EXTRA_ACTIVE EXTRA_BULLETCOUNT EXTRA_OWNER EXTRA_FLAGS EXTRA_PATHDIR EXTRA_PATHPTR EXTRA_ANIMSEQ EXTRA_ANIMPTR EXTRA_ANIMSPEED EXTRA_DEATHINDICATOR EXTRA_AGE EXTRA_TIMEOUT EXTRA_TAGFLAGS EXTRA_INVENTORY
sprite_getClass
- in int objId
- out int classId
Alias: getObjClass
sprite_getExtra
- in int objId
- out array
You can access this information via the following indexes.
EXTRA_ORGPROTO EXTRA_ORGX EXTRA_ORGY EXTRA_HP EXTRA_OLDAIM1 EXTRA_OLDAIM2 EXTRA_FALLHEIGHT EXTRA_LIVES EXTRA_ACTIVE EXTRA_BULLETCOUNT EXTRA_OWNER EXTRA_FLAGS EXTRA_PATHDIR EXTRA_PATHPTR EXTRA_ANIMSEQ EXTRA_ANIMPTR EXTRA_ANIMSPEED EXTRA_DEATHINDICATOR
Alias: getExtraC
sprite_getHeight
- in int sprite_id
- out int height
sprite_getHitTest
- in int objId
- in int aim
- out array bk
- out array fw
- out array ac
- out int flags
- out bool player
The objId is generally the "self" variable you would get from the object handler. Although, it could also be obtained with something else like findSprite().
Possible values for aim are UP, DOWN, LEFT, RIGHT and HERE, These values cannot be combined.
local bk, fw, ac, flags, player = getHitTestC( self, UP );
The results of this function can be a bit confusing. For starters, "flags" can be a combination of any of the following.
FLAG_NONE FLAG_METAL FLAG_NOSOUND FLAG_WATER FLAG_DEATH FLAG_HIT FLAG_TELEPORT
bk is an array of classes.
fw is an array of classes and objId. There value are in pair starting at index 1.
ac is an array of classes and objId. There value are in pair starting at index 1.
for i=1, #fw, 2 do local class = fw[i] ; local objId = fw[i + 1]; -- do something else .... end for i=1, #ac, 2 do local class = ac[i] ; local objId = ac[i + 1]; -- do something else .... end
player is boolean that indicate whether or not the player is there.
Alias: getHitTestC
sprite_getHP
- in int objId
- out int hp
sprite_getName
- in int objId
- out string name
Debug:printf("player picked up a %s", getObjName(self));
Alias: getObjName
sprite_getObjType
- in int objId
- out int objType
these values can be corrolated with the OBJECT_XXXX constants defined by LGCK for your game.
example:
debug("type: " .. getObjType( self )); debug("name:" .. getObjName( self ));
Alias: getObjType
sprite_getString
- in int objId
- out string
sprite_getTriggerKey
- in int objId
- out int triggerKey
Alias: getTriggerKey
sprite_getUID
- in int objId
- out int uid
Alias: getExtraUID
sprite_getVars
- in int objId
- out int x
- out int y
- out int aim
- out int objectType
- out int imageSetId
- out int imageNo
- out int triggerFlag
- out int stateFlag
- out int actionMask
- triggerFlag bit mask
to get the triggerKey out of triggerFlag use `AND (triggerFlag, TRIGGER_KEYS)`.
goal, frozen and hidden can be access using the TRIGGER_xxxx method above see common.lua for the definitions.
this is stuff for advanced users
- stateFlag
local x; local y; local aim; x , y, aim = getSpriteVars( self );
Alias: getSpriteVars
sprite_getWidth
- in int sprite_id
- out int width
sprite_hasItem
- in int objId
- in int protoId
- out bool hasItem
sprite_hide
- in int objId
- out void
Alias: hideSprite
sprite_isActive
- in int objId
- out bool active
sprite_isDead
- in int objId
- out bool
if isDead(self) then Debug:printf("This sprite is dead"); end
Alias: isDead
sprite_isFrozen
- in int objId
- out bool frozen
sprite_isGoal
- in int objId
- out bool goal
sprite_isHidden
- in int objId
- out bool
Alias: isHidden
sprite_isMonster
- in int objId
- out bool
Alias: isMonster
sprite_isPlayer
- in int objId
- out bool
sprite_isPlayerThere
- in int objId
- in int aim
- out bool
Alias: isPlayerThere
sprite_isVisible
- in int objId
- out bool
- Is the sprite on screen?
- Is the sprite hidden?
You can check if the sprite is hidden with sprite_isHidden.
Alias: isVisible
sprite_kill
- in int objId
- out void
Alias: killSprite
sprite_land
- in int objId
- out void
Alias: land
sprite_map
- in int objId
- out void
Alias: mapSprite
sprite_markAsGoal
- in int objId
- out void
Alias: markSpriteAsGoal
sprite_move
- in int objId
- in int aim
- in int objId
- in int tx
- in int ty
- out void
you generally check to see of the object can move in a given direction using canMove()
this second version also allows you to control the translation from current position. if you want defined where to position it then use moveSpriteTo().
Alias: moveSprite
sprite_moveBy
- in int objId
- in int tx
- in int tx
- out void
this allows you to control the translation from current position. if you want defined where to position it then use moveSpriteTo().
Alias: moveSpriteBy
sprite_moveTo
- in int objId
- in int x
- in int y
- out void
Please ensure that x and y coordonates are multiples of 8 and within the game world. You can do that with the bitwise operator AND (x, 0xfff8).
Alias: moveSpriteTo
sprite_new
- in int x
- in int y
- in int aim
- in int objectType
- in int imageSet*
- in int imageNo*
- out int objId
in parameter imageSet : optional and can be omitted.
in parameter imageNo : optional and can be omitted.
Alias: addSpriteC
sprite_removeItem
- in int objId
- in int protoId
- out void
sprite_resetInventory
- in int objId
- out void
sprite_set
- in int objId
- in mixed key
- in int value
- out void
The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.
EXTRA_ORGPROTO EXTRA_ORGX EXTRA_ORGY EXTRA_HP EXTRA_OLDAIM1 EXTRA_OLDAIM2 EXTRA_FALLHEIGHT EXTRA_LIVES EXTRA_ACTIVE EXTRA_BULLETCOUNT EXTRA_OWNER EXTRA_FLAGS EXTRA_PATHDIR EXTRA_PATHPTR EXTRA_ANIMSEQ EXTRA_ANIMPTR EXTRA_ANIMSPEED EXTRA_DEATHINDICATOR EXTRA_AGE EXTRA_TIMEOUT EXTRA_TAGFLAGS EXTRA_INVENTORY
sprite_setAim
- in int objId
- in int aim
- out void
Alias: setAim
sprite_setHP
- in int objID
- in int hp
- out void
sprite_setImage
- in int objId
- in int imageSet
- in int imageNo
- out void
The example below shows the best practice. Alternative methods include tryAnimation().
local imageSet; local imageNo; imageSet, imageNo = getImage(selt); setImage(self, imageSet, XOR(imageNo, 1));
Alias: setImage
sprite_setOwner
- in int objId
- in int ownerid
- out void
sprite_setState
- in int objId
- in int stateFlag
- in bool flip
- out int stateFlag
if flip is true the bits are set on otherwise they are cleared.
State flag is a combination of the following:
STATE_FALL STATE_DEAD STATE_HIT STATE_JUMP STATE_BEGINNING STATE_FIRING STATE_LOOKUP
returns the newly modified stateFlag.
Alias: setState
sprite_setTriggerKey
- in int objId
- in int key
- out void
Alias: setTriggerKey
sprite_show
- in int objId
- out void
Alias: showSprite
sprite_spawn
- in int objId
- out void
Alias: spawn
sprite_stopAnimation
- in int objId
- out void
stopAnimation(self);
Alias: stopAnimation
sprite_testFlags
- in int objId
- in int mask
- out bool true if bitwise matched
you must supply both args or the function will return false and spit out a warning on the debug console
local sound = ""; if not testFlags(self, FLAG_NOSOUND) then if testFlags(self , FLAG_METAL) then sound = "METAL"; else if ticks % 12 == 0 then sound = "WALK2"; else sound = "WALK"; end end playSound( sound ); end
The mask can be a combination of any of the following. Although, generally speaking you want to include only one.
FLAG_NONE FLAG_METAL FLAG_NOSOUND FLAG_WATER FLAG_DEATH FLAG_HIT FLAG_TELEPORT
Alias: testFlags
sprite_togglePathPlayback
- in int objId
- in bool enable
- out void
sprite_triggerHitState
- in int objId
- out void
ObjId is the sprite id.
No return value.
Alias: triggerHitState
sprite_tryAnimation
- in int objId
- in int animSeq
- out bool
The animation sequence is one of the following values. In order to use this animation, the target object must have corresponding images attached to it.
AS_DEFAULT AS_IDLE AS_CUSTOM1 AS_CUSTOM2 AS_STAND AS_STAND_UP AS_STAND_DOWN AS_STAND_LEFT AS_STAND_RIGHT AS_MOVE AS_MOVE_UP AS_MOVE_DOWN AS_MOVE_LEFT AS_MOVE_RIGHT AS_JUMP AS_JUMP_UP AS_JUMP_DOWN AS_JUMP_LEFT AS_JUMP_RIGHT AS_HURT AS_HURT_UP AS_HURT_DOWN AS_HURT_LEFT AS_HURT_RIGHT AS_ATTACK AS_ATTACK_UP AS_ATTACK_DOWN AS_ATTACK_LEFT AS_ATTACK_RIGHT AS_RUN AS_RUN_UP AS_RUN_DOWN AS_RUN_LEFT AS_RUN_RIGHT AS_DEAD AS_DEAD_UP AS_DEAD_DOWN AS_DEAD_LEFT AS_DEAD_RIGHT
This function returns true if succesful or false if the animSeq value is out of bound or the object has no animation sequence defined which match the animSeq value.
if tryAnimation(self, AS_DEAD_UP) then debug("animation worked!!! :D"); end
Alias: tryAnimation
sprite_tryPath
- in int objId
- in int pathDir
- in int aim*
- out bool
PS_DEFAULT PS_IDLE PS_CUSTOM1 PS_CUSTOM2 PS_ATTACK PS_ATTACK_UP PS_ATTACK_DOWN PS_ATTACK_LEFT PS_ATTACK_RIGHT PS_JUMP PS_JUMP_UP PS_JUMP_DOWN PS_JUMP_LEFT PS_JUMP_RIGHT PS_JUMP_UP_LEFT PS_JUMP_UP_RIGHT PS_JUMP_DN_LEFT PS_JUMP_DN_RIGHT PS_MOVE PS_MOVE_UP PS_MOVE_DOWN PS_MOVE_LEFT PS_MOVE_RIGHT PS_MOVE_UP_LEFT PS_MOVE_UP_RIGHT PS_MOVE_DN_LEFT PS_MOVE_DN_RIGHT
Aim can be either UP, DOWN, LEFT or RIGHT. If aim is not provided, INVALID is assumed.
Return true if the path defined. This function is similar to tryAnimation(). It only works with the player at the moment.
local id = getPlayerC(); Debug:printf("player_id: %x", id); tryPath(id, PS_JUMP_LEFT);
in parameter aim : optional and can be omitted.
Alias: tryPath
sprite_unFreeze
- in int objId
- out void
another way of doing this is through the Sprite interface.
activateSprite(self); -- is equivalent to local sprite; sprite = getSprite(self); sprite:activate();
Alias: unFreezeSprite
sprite_unMap
- in int objId...
- out void
Alias: unMapSprite
ss_animate
- in void
- out void
ss_autoCenter
- in void
- out void
ss_clear
- in int red
- in int green
- in int blue
- out void
ss_clearKeys
- in void
- out void
ss_doManage
- in void
- out void
ss_drawText
- in int x
- in int y
- in string text
- in int fontid
- in int fontSize
- in int rgba
- in int shadowOffset*
- in int shadowColor*
- out void
ss_drawText(100, 50, "This is a test", 0, 20, 0xa0ee20cc, 2, 0xffffffff);
in parameter shadowOffset : optional and can be omitted.
in parameter shadowColor : optional and can be omitted.
ss_getNextTick
- in void
- out int
ss_getPause
- in void
- out bool
ss_manageAuto
- in void
- out void
ss_manageKeyEvents
- in void
- out void
ss_managePlayer
- in void
- out void
ss_manageTasks
- in void
- out void
ss_notifyAll
- in int gameEventOD
- in int levelEventID
- in int spriteEventID
- in int spriteEventID
- out void
ss_notifyClosure
- in void
- out void
calls onNotifyClosure() EO_NOTIFYCLOSURE
local closureEvent, closureTime = getClosure(); local mtime = getTime(); --if (closureEvent ~= EVENT_NO_EVENT and mtime >= closureTime) then if closureEvent ~= EVENT_NO_EVENT then if mtime >= closureTime then return closureEvent; else ss_notifyClosure(); end end
ss_paint
- in int x1
- in int y1
- in int x2
- in int y2
- in unsigned int rgba
- in bool fill
- out void
ss_paint(0,0,40,40, 0xaa00aa90, TRUE);
ss_paintImage
- in int x
- in int y
- in int frameSet
- in int frameNo
- out void
ss_setNextTick
- in int time
- out void
stopStream
- in void
- out void
stopStream();
strv_del
- in string key
- out void
strv_get
- in string key
- out string val
strv_set
- in string key
- in string val
- out void
testJoyState
- in int mask
- out bool true if bitwise matched, otherwise false
states are outlined as const JOY_xxxxx
if (ticks % 5 == 0) and testJoyState( JOY_FIRE ) then local x; local y; local aim; x , y, aim = getSpriteVars( self ); if testJoyState( JOY_LEFT ) then aim = LEFT; x = x - 8; y = y + 8; elseif testJoyState( JOY_RIGHT ) then aim = RIGHT; x = x + 32; y = y + 8; elseif testJoyState( JOY_UP ) then aim = UP; x = x + 8; y = y - 8; elseif testJoyState( JOY_DOWN ) then aim = DOWN; x = x + 8; y = y + 32; end local bullet = addSprite ( x, y, aim, -- UP, DOWN, LEFT, RIGHT OBJECT_BULLET_LITTLE_STAR__PLY_ -- put the object type ); playSound("pow.ogg"); end
testKey
- in int keyCode
- out bool
KEY_A KEY_B KEY_C KEY_D KEY_E KEY_F KEY_G KEY_H KEY_I KEY_J KEY_K KEY_L KEY_M KEY_N KEY_O KEY_P KEY_Q KEY_R KEY_S KEY_T KEY_U KEY_V KEY_W KEY_X KEY_Y KEY_Z KEY_0 KEY_1 KEY_2 KEY_3 KEY_4 KEY_5 KEY_6 KEY_7 KEY_8 KEY_9 KEY_F1 KEY_F2 KEY_F3 KEY_F4 KEY_F5 KEY_F6 KEY_F7 KEY_F8 KEY_F9 KEY_ESCAPE KEY_CTRL KEY_SHIFT KEY_ALT KEY_MENU KEY_LBRACKET KEY_RBRACKET KEY_SEMICOLON KEY_COMA KEY_PERIOD KEY_QUOTE KEY_SLASH KEY_BACKSLASH KEY_TILDE KEY_EQUAL KEY_MINUS KEY_SPACE KEY_RETURN KEY_BACKSPACE KEY_TAB KEY_PAGEUP KEY_PAGEDOWN KEY_END KEY_HOME KEY_INSERT KEY_DELETE KEY_PLUS KEY_MINUS KEY_MULTIPLY KEY_DIVIDE KEY_LEFT KEY_RIGHT KEY_UP KEY_DOWN KEY_PAUSE
ticks
- in void
- out int ticks
triggerPlayerHitState
- in void
- out void
updateHP
- in void
- out void
updateJoyState
- in void
- out void
uuid
- in void
- out string
var_del
- in string
- out void
var_get
- in string key
- out void
local s = getSprite(self); local sx, sy = getImageSize(s.imageSet, s.imageNo); if s.y + sy >= var_get("BUFFERHEI") then s:setState(STATE_DEAD); s:hide(); else playSound("POUFLIGHT"); local extra = getExtra(self); Debug:printf("fallHeight: %d", extra.fallHeight); if extra.fallHeight >= 20 then triggerPlayerHitState(); addToHP( -25 ); end end
var_set
- in string key
- in int value
- out void
var_set("pink_bunny", 0)
warpTo
- in string uuid
- in int id
- out void
warpTo(2) warpTo("50d1-42c5-0112-e964")
XOR
- in int a
- in int b
- out int binary eXclusive OR (a , b)
XOR (1, 7) -- expected resut: 6 -- explanation 1 = 1000 7 = 1110 XOR 6 = 0110 XOR (2, 3) -- expected resut: 1 -- explanation 2 = 0100 3 = 1100 XOR 1 = 1000 etc.