Class engine.Game
Represents a game
A module should subclass it and initialize anything it needs to play inside
Local Functions
engine.Game.list ()
Get the available display modes for the monitor from the core
Methods
engine.Game:init (keyhandler)
Sets up the default keyhandler Also requests the display size and stores it in "w" and "h" properties
engine.Game:log ()
Log a message
engine.Game:logSeen ()
Log something that was seen
engine.Game:defaultMouseCursor ()
Default mouse cursor
engine.Game:setMouseCursor (mouse[, mouse_down], offsetx, offsety)
Sets the mouse cursor
engine.Game:updateMouseCursor ()
Called whenever the cursor needs updating
engine.Game:loaded ()
Called when the game is loaded
engine.Game:defaultSavedFields (t)
Defines the default fields to be saved by the savefile code
engine.Game:setPlayerName (name)
Sets the player name
engine.Game:prerun ()
Do not touch!!
engine.Game:run ()
Starts the game Modules should reimplement it to do whatever their game needs
engine.Game:isTainted ()
Checks if the current character is "tainted" by cheating
engine.Game:setLevel (level)
Sets the current level
engine.Game:setCurrent ()
Tells the game engine to play this game
engine.Game:display (nb_keyframes)
Displays the screen Called by the engine core to redraw the screen every frame
engine.Game:registerTimer (seconds, cb)
Register a timer
engine.Game:idling (focus)
Called when the game is focused/unfocused
engine.Game:handleEvents ()
Handle pending events
engine.Game:handleProfileEvent (evt)
Receives a profile event Usually this just transfers it to the PlayerProfile class but you can overload it to handle special stuff
engine.Game:getPlayer (main)
Returns the player Reimplement it in your module, this can just return nil if you dont want/need the engine adjusting stuff to the player or if you have many players or whatever
engine.Game:getCampaign ()
Returns current "campaign" name
engine.Game:isLoadable ()
Says if this savefile is usable or not Reimplement it in your module, returning false when the player is dead
engine.Game:saveVersion ([token])
Gets/increment the savefile version
engine.Game:tick ()
This is the "main game loop", do something here
engine.Game:onTickEndExecute ()
Run all registered tick end functions Usually just let the engine call it
engine.Game:onTickEnd (f, name)
Register things to do on tick end
engine.Game:onTickEndGet (name)
Returns a registered function to do on tick end by name
engine.Game:leaveLevel (level, lev, old_lev)
Called when a zone leaves a level
engine.Game:onQuit ()
Called by the engine when the user tries to close the module
engine.Game:onExit ()
Called by the engine when the user tries to close the window
engine.Game:setFlyingText (fl)
Sets up a FlyingText for general use
engine.Game:registerDialog (d)
Registers a dialog to display
engine.Game:registerDialogAt (d, pos)
Registers a dialog to display somewhere in the stack
engine.Game:replaceDialog (src, dest)
Replaces a dialog to display with another
engine.Game:unregisterDialog (d)
Undisplay a dialog, removing its own keyhandler if needed
engine.Game:hasDialog (d)
Do we have a specific dialog
engine.Game:hasDialogUp ([nb=0])
Do we have a dialog(s) running
engine.Game:commandLineArgs (args)
The C core gives us command line arguments
engine.Game:getSaveDescription ()
Called by savefile code to describe the current game
engine.Game:saveSettings (file, data)
Save a settings file
engine.Game:setResolution (res, force)
Change screen resolution
engine.Game:onResolutionChange ()
Called when screen resolution changes
engine.Game:checkResolutionChange (w, h, ow, oh)
Checks if we must reload to change resolution
engine.Game:onWindowMoved (x, y)
Called when the game window is moved around
engine.Game:updateVideoDialogs ()
Update any registered video options dialogs with the latest changes.
engine.Game:setGamma (gamma)
Sets the gamma of the window By default it uses SDL gamma settings, but it can also use a fullscreen shader if available
engine.Game:saveGame ()
Requests the game to save
engine.Game:registerHighscore ()
Saves the highscore of the current char
engine.Game:registerCoroutine (id, co)
Add a coroutine to the pool Coroutines registered will be run each game tick
engine.Game:getCoroutine (id)
Get the coroutine corresponding to the id
engine.Game:cancelCoroutine (id)
Ask a registered coroutine to cancel The coroutine must accept a "cancel" action
engine.Game:takeScreenshot (for_savefile)
Take a screenshot of the game
engine.Game:saveScreenshot ()
Take a screenshot of the game and saves it to the screenshots folder
engine.Game:registerPersistentHook (hook, fct)
Register a hook that will be saved in the savefile Obviously only run it once per hook per save
engine.Game:isAddonActive (name)
Checks the presence of a specific addon
Local Functions
MethodsMethods
- engine.Game:init (keyhandler)
-
Sets up the default keyhandler
Also requests the display size and stores it in "w" and "h" properties
Parameters:
- keyhandler Key the default keyhandler for this game
- engine.Game:log ()
- Log a message
- engine.Game:logSeen ()
- Log something that was seen
- engine.Game:defaultMouseCursor ()
- Default mouse cursor
- engine.Game:setMouseCursor (mouse[, mouse_down], offsetx, offsety)
-
Sets the mouse cursor
Parameters:
- engine.Game:updateMouseCursor ()
- Called whenever the cursor needs updating
- engine.Game:loaded ()
- Called when the game is loaded
- engine.Game:defaultSavedFields (t)
-
Defines the default fields to be saved by the savefile code
Parameters:
- t table additional definitions to save
Returns:
-
table of definitions
- engine.Game:setPlayerName (name)
-
Sets the player name
Parameters:
- name string
- engine.Game:prerun ()
- Do not touch!!
- engine.Game:run ()
- Starts the game Modules should reimplement it to do whatever their game needs
- engine.Game:isTainted ()
-
Checks if the current character is "tainted" by cheating
Returns:
-
false by default
- engine.Game:setLevel (level)
-
Sets the current level
Parameters:
- level a Level (or subclass) object
- engine.Game:setCurrent ()
- Tells the game engine to play this game
- engine.Game:display (nb_keyframes)
-
Displays the screen
Called by the engine core to redraw the screen every frame
Parameters:
- nb_keyframes The number of elapsed keyframes since last draw (this can be 0). This is set by the engine
- engine.Game:registerTimer (seconds, cb)
-
Register a timer
Parameters:
- seconds int will be called in the given number of seconds
- cb func the callback function
- engine.Game:idling (focus)
-
Called when the game is focused/unfocused
Parameters:
- focus boolean are we focused?
- engine.Game:handleEvents ()
- Handle pending events
- engine.Game:handleProfileEvent (evt)
-
Receives a profile event
Usually this just transfers it to the PlayerProfile class but you can overload it to handle special stuff
Parameters:
- evt the event
- engine.Game:getPlayer (main)
-
Returns the player
Reimplement it in your module, this can just return nil if you dont want/need
the engine adjusting stuff to the player or if you have many players or whatever
Parameters:
- main if true the game should try to return the "main" player, if any
Returns:
-
nil by default
- engine.Game:getCampaign ()
-
Returns current "campaign" name
Returns:
-
"default" by default
- engine.Game:isLoadable ()
-
Says if this savefile is usable or not
Reimplement it in your module, returning false when the player is dead
Returns:
-
true by default
- engine.Game:saveVersion ([token])
-
Gets/increment the savefile version
Parameters:
- token if "new" this will create a new allowed save token and return it. Otherwise this checks the token against the allowed ones and returns true if it is allowed (optional)
Returns:
- uuid
- true
- engine.Game:tick ()
- This is the "main game loop", do something here
- engine.Game:onTickEndExecute ()
- Run all registered tick end functions Usually just let the engine call it
- engine.Game:onTickEnd (f, name)
-
Register things to do on tick end
Parameters:
- f func function to do on tick end
- name string callback to reference the function
- engine.Game:onTickEndGet (name)
-
Returns a registered function to do on tick end by name
Parameters:
- name string callback to reference the function
- engine.Game:leaveLevel (level, lev, old_lev)
-
Called when a zone leaves a level
Parameters:
- level the level we're leaving
- lev the new level
- old_lev the old level (probably same value as level)
- engine.Game:onQuit ()
- Called by the engine when the user tries to close the module
- engine.Game:onExit ()
- Called by the engine when the user tries to close the window
- engine.Game:setFlyingText (fl)
-
Sets up a FlyingText for general use
Parameters:
- fl FlyingText
- engine.Game:registerDialog (d)
-
Registers a dialog to display
Parameters:
- d Dialog
- engine.Game:registerDialogAt (d, pos)
-
Registers a dialog to display somewhere in the stack
Parameters:
- d Dialog
- pos int the stack position (1=top, 2=second, ...)
- engine.Game:replaceDialog (src, dest)
-
Replaces a dialog to display with another
Parameters:
- engine.Game:unregisterDialog (d)
-
Undisplay a dialog, removing its own keyhandler if needed
Parameters:
- d Dialog
- engine.Game:hasDialog (d)
-
Do we have a specific dialog
Parameters:
- d Dialog
- engine.Game:hasDialogUp ([nb=0])
-
Do we have a dialog(s) running
Parameters:
- nb int how many dialogs minimum (default 0)
- engine.Game:commandLineArgs (args)
-
The C core gives us command line arguments
Parameters:
- args table filled in by the C core
- engine.Game:getSaveDescription ()
-
Called by savefile code to describe the current game
Returns:
-
table
- engine.Game:saveSettings (file, data)
-
Save a settings file
Parameters:
- file string
- data
- engine.Game:setResolution (res, force)
-
Change screen resolution
Parameters:
- res string should be in format like "800x600 Windowed"
- force boolean try to force the resolution if it can't find it
- engine.Game:onResolutionChange ()
- Called when screen resolution changes
- engine.Game:checkResolutionChange (w, h, ow, oh)
-
Checks if we must reload to change resolution
Parameters:
- w int width
- h int height
- ow int original width
- oh int original height
- engine.Game:onWindowMoved (x, y)
-
Called when the game window is moved around
Parameters:
- x int x coordinate
- y int y coordinate
- engine.Game:updateVideoDialogs ()
-
Update any registered video options dialogs with the latest changes.
Note: If the title of the video options dialog changes, this functionality will break.
- engine.Game:setGamma (gamma)
-
Sets the gamma of the window
By default it uses SDL gamma settings, but it can also use a fullscreen shader if available
Parameters:
- gamma
- engine.Game:saveGame ()
- Requests the game to save
- engine.Game:registerHighscore ()
- Saves the highscore of the current char
- engine.Game:registerCoroutine (id, co)
-
Add a coroutine to the pool
Coroutines registered will be run each game tick
Parameters:
- id the id
- co thread the coroutine
- engine.Game:getCoroutine (id)
-
Get the coroutine corresponding to the id
Parameters:
- id the id
- engine.Game:cancelCoroutine (id)
-
Ask a registered coroutine to cancel
The coroutine must accept a "cancel" action
Parameters:
- id the id
- engine.Game:takeScreenshot (for_savefile)
-
Take a screenshot of the game
Parameters:
- for_savefile boolean The screenshot will be used for savefile display
Returns:
-
screenshot
- engine.Game:saveScreenshot ()
- Take a screenshot of the game and saves it to the screenshots folder
- engine.Game:registerPersistentHook (hook, fct)
-
Register a hook that will be saved in the savefile
Obviously only run it once per hook per save
Parameters:
- hook string the hook to run on
- fct func the function to run
- engine.Game:isAddonActive (name)
-
Checks the presence of a specific addon
Parameters:
- name