Game

The game class keeps track of all current game objects, loaded maps, dialogue and quests. There should only be one game instance in use at a time and it should be registered with the main engine as being the current game. There can be many game instances over the lifetime of an engine however.
Return to Index
new ( )
__gc ( )
__eq ( am.game rhs ) -> ( boolean )
add_map ( am.map map ) -> ( boolean )
remove_map ( string map_name ) -> ( boolean )
remove_map ( am.map map ) -> ( boolean )
remove_all_maps ( ) -> ( am.game )
map ( string map_name ) -> ( am.map )
current_map ( string map_name ) -> ( boolean )
current_map ( ) -> ( am.map )
current_map ( string map_name ) -> ( am.game )
current_map ( am.map map ) -> ( am.game )
add_game_object_to_map ( am.game_object game_object ) -> ( boolean )
add_game_object_to_map ( string gameObjectId ) -> ( boolean )
remove_game_object_from_map ( am.game_object game_object ) -> ( boolean )
remove_game_object_from_map ( string gameObjectId ) -> ( boolean )
has_game_object_in_map ( am.game_object game_object ) -> ( boolean )
has_game_object_in_map ( string gameObjectId ) -> ( boolean )
move_object_to_map ( am.game_object game_object , am.map map ) -> ( am.game )
move_object_to_map ( am.game_object game_object , string map_name ) -> ( am.game )
move_object_to_map ( am.game_object game_object , am.map map , number position_x , number position_y , boolean set_as_current = true ) -> ( am.game )
move_object_to_map ( am.game_object game_object , string map_name , number position_x , number position_y , boolean set_as_current = true ) -> ( am.game )
move_object_to_map_grid ( am.game_object game_object , am.map map ) -> ( am.game )
move_object_to_map_grid ( am.game_object game_object , string map_name ) -> ( am.game )
move_object_to_map_grid ( am.game_object game_object , am.map map , integer grid_x , integer grid_y ) -> ( am.game )
move_object_to_map_grid ( am.game_object game_object , string map_name , integer grid_x , integer grid_y ) -> ( am.game )
main ( ) -> ( am.character )
main ( am.character main_char ) -> ( am.game )
game_object ( string gameObjectId ) -> ( am.game_object )
register_game_object ( am.game_object game_object ) -> ( am.game )
deregister_game_object ( am.game_object game_object ) -> ( am.game )
char_def ( string def_name ) -> ( am.character )
char_def ( string def_name , am.character def ) -> ( am.game )
item_def ( string def_name ) -> ( am.item )
item_def ( string def_name , am.item def ) -> ( am.game )
add_dialogue ( am.dialogue dialogue ) -> ( boolean )
remove_dialogue ( am.dialogue dialogue ) -> ( boolean )
remove_dialogue ( string dialogue_id ) -> ( boolean )
remove_all_dialogue ( ) -> ( am.game )
dialogue ( string dialogue_id ) -> ( am.dialogue )
available_dialogues ( ) -> ( )
add_quest ( am.quest quest ) -> ( boolean )
remove_quest ( am.quest quest ) -> ( boolean )
remove_quest ( string quest_id ) -> ( boolean )
quest ( string quest_id ) -> ( am.quest )
start_game ( ) -> ( am.game )
has_started ( ) -> ( boolean )
load_game ( string save_name ) -> ( integer )
scenario_name ( ) -> ( string )
generic_dead_graphic ( ) -> ( am.sprite )
generic_dead_graphic ( string asset_name ) -> ( am.game )
generic_dead_graphic ( am.sprite sprite ) -> ( am.game )
generic_dead_graphic ( nil grapic ) -> ( am.game )
attrs ( boolean create_table = false ) -> ( am.data_table )
attrs ( am.data_table attrTable ) -> ( am.game )
new ( )
Creates a new game instance.
__gc ( )
Release the reference counter on the game.
__eq ( am.game rhs ) -> ( boolean )
Compares this game against another game object.
Parameters:
am.game rhs : The other game object to compare.
Returns:
boolean : True if they are the same object.
add_map ( am.map map ) -> ( boolean )
Manually adds a new map to the map pool. Maps generally can be loaded from file automatically via the map()
Parameters:
am.map map : The map to add to the map pool.
Returns:
boolean : True if the map was successfully added, false indicates the map was nil or had no name.
remove_map ( string map_name ) -> ( boolean )
Removes a map from the map pool.
Parameters:
string map_name : The name of the map to remove.
Returns:
boolean : True if the map was successfully removed, false indicates that map was not in the map pool.
remove_map ( am.map map ) -> ( boolean )
Removes a map from the map pool.
Parameters:
am.map map : The map to remove.
Returns:
boolean : True if the map was successfully removed, false indicates that map was not in the map pool.
remove_all_maps ( ) -> ( am.game )
Removes all the maps from the map pool.
Returns:
am.game : This
map ( string map_name ) -> ( am.map )
Returns a map from the map pool. If the map is not present it will attempt to load the map from file under the data directory.

data/maps/{map_name}.lua

Parameters:
string map_name : The name of the map to load.
Returns:
am.map : The found/loaded map, nil if it could not be found nor loaded.
current_map ( string map_name ) -> ( boolean )
Returns true if a map with the given map name is found in the map pool.
Parameters:
string map_name : The map name to look up.
Returns:
boolean : True if the map was found.
current_map ( ) -> ( am.map )
Returns the current active map, this will usually be the one that the main character is on.
Returns:
am.map : The current active map.
current_map ( string map_name ) -> ( am.game )
Sets the current active map.
Parameters:
string map_name : The name of the map to set as the active map.
Returns:
am.game : This.
current_map ( am.map map ) -> ( am.game )
Sets the current active map.
Parameters:
am.map map : The map to set as the active map.
Returns:
am.game : This.
add_game_object_to_map ( am.game_object game_object ) -> ( boolean )
Adds a game object to the currently active map.
Parameters:
am.game_object game_object : The game object to add.
Returns:
boolean : True if the game object was successfully added. False indicates that either the current map is nil.
add_game_object_to_map ( string gameObjectId ) -> ( boolean )
Adds a game object to the currently active map.
Parameters:
string gameObjectId : The game object id of the game object to add.
Returns:
boolean : True if the game object was successfully added. False indicates that either the current map is nil.
remove_game_object_from_map ( am.game_object game_object ) -> ( boolean )
Removes a game object from the current map.
Parameters:
am.game_object game_object : The game object to remove from the current map.
Returns:
boolean : True if the game object was successfully removed. False indicates that either the current map or game_object are nil.
remove_game_object_from_map ( string gameObjectId ) -> ( boolean )
Removes a game object from the current map.
Parameters:
string gameObjectId : The game object id of the game object to remove from the current map.
Returns:
boolean : True if the game object was successfully removed. False indicates that either the current map or game_object are nil.
has_game_object_in_map ( am.game_object game_object ) -> ( boolean )
Returns true if the game object is on the current map.
Parameters:
am.game_object game_object : The game object to look for.
Returns:
boolean : True if the game object was found on the current map.
has_game_object_in_map ( string gameObjectId ) -> ( boolean )
Returns true if the game object is on the current map.
Parameters:
string gameObjectId : The game object id of the game object to look for.
Returns:
boolean : True if the game object was found on the current map.
move_object_to_map ( am.game_object game_object , am.map map ) -> ( am.game )
Moves a game object from their current map to a new map.
Parameters:
am.game_object game_object : The game object to move.
am.map map : The map to move to.
Returns:
am.game : This
move_object_to_map ( am.game_object game_object , string map_name ) -> ( am.game )
Moves a game object from their current map to a new map.
Parameters:
am.game_object game_object : The game object to move.
string map_name : The name of the map to move to.
Returns:
am.game : This
move_object_to_map ( am.game_object game_object , am.map map , number position_x , number position_y , boolean set_as_current = true ) -> ( am.game )
Moves a game object from their current map to a new map at a given position.
Parameters:
am.game_object game_object : The game object to move.
am.map map : The map to move to.
number position_x : The x position to move the game object to.
number position_y : The y position to move the game object to.
boolean set_as_current = true : When true, the new map will become the current map and the camera will focus on the given game object.
Returns:
am.game : This
move_object_to_map ( am.game_object game_object , string map_name , number position_x , number position_y , boolean set_as_current = true ) -> ( am.game )
Moves a game object from their current map to a new map at a given position.
Parameters:
am.game_object game_object : The game object to move.
string map_name : The name of the map to move to.
number position_x : The x position to move the game object to.
number position_y : The y position to move the game object to.
boolean set_as_current = true : When true, the new map will become the current map and the camera will focus on the given game object.
Returns:
am.game : This
move_object_to_map_grid ( am.game_object game_object , am.map map ) -> ( am.game )
Moves a game object from their current map to a new map.
Parameters:
am.game_object game_object : The game object to move.
am.map map : The map to move to.
Returns:
am.game : This
move_object_to_map_grid ( am.game_object game_object , string map_name ) -> ( am.game )
Moves a game object from their current map to a new map.
Parameters:
am.game_object game_object : The game object to move.
string map_name : The name of the map to move to.
Returns:
am.game : This
move_object_to_map_grid ( am.game_object game_object , am.map map , integer grid_x , integer grid_y ) -> ( am.game )
Moves a game object from their current map to a new map at a given grid position.
Parameters:
am.game_object game_object : The game object to move.
am.map map : The map to move to.
integer grid_x : The x grid position to move the game object to.
integer grid_y : The y grid position to move the game object to.
Returns:
am.game : This
move_object_to_map_grid ( am.game_object game_object , string map_name , integer grid_x , integer grid_y ) -> ( am.game )
Moves a game object from their current map to a new map at a given grid position.
Parameters:
am.game_object game_object : The game object to move.
string map_name : The name of the map to move to.
integer grid_x : The x grid position to move the game object to.
integer grid_y : The y grid position to move the game object to.
Returns:
am.game : This
main ( ) -> ( am.character )
Returns the main character for this game.
Returns:
am.character : The main character.
main ( am.character main_char ) -> ( am.game )
Sets the main character to the given character.
Parameters:
am.character main_char : The new main character.
Returns:
am.game : This
game_object ( string gameObjectId ) -> ( am.game_object )
Looks for a game object with the given game object id, returns nil if a game object could not be found.
Parameters:
string gameObjectId : The game object id to look up.
Returns:
am.game_object : The found game object, or nil.
register_game_object ( am.game_object game_object ) -> ( am.game )
Registers a game object with the game instance.
Parameters:
am.game_object game_object : The game object to register with this game.
Returns:
am.game : This
deregister_game_object ( am.game_object game_object ) -> ( am.game )
Deregisters a game object with the game instance.
Parameters:
am.game_object game_object : The game object to deregister.
Returns:
am.game : This
char_def ( string def_name ) -> ( am.character )
Returns the character definition with the given name. The definition name is made up of the file to load the definition from and the individual name. For example npcs:male1 If this definition is not found then the data/defs/npcs.lua file is loaded then the definition is looked for again.
Parameters:
string def_name : The definition name of the character to load.
Returns:
am.character : The found definition or nil.
char_def ( string def_name , am.character def ) -> ( am.game )
Registers a character with the given definition name. Definition names are always namespaced to the file they were loaded from. For example filename:defname This filename should be relative to the data/defs/ folder. If no filename is given then the current file being loaded will be used. The files under data/defs/ will be automatically loaded when a definition with their filename is used. Definitions can also be registered from outside of those files, however they will need to always provide a filename. Definitions can be overridden.
Parameters:
string def_name : The name to store the character definition under.
am.character def : The character definition to store.
Returns:
am.game : This
item_def ( string def_name ) -> ( am.item )
Returns the item definition with the given name. The definition name is made up of the file to load the definition from and the individual name. For example human:sword If this definition is not found then the data/defs/human.lua file is loaded then the definition is looked for again.
Parameters:
string def_name : The definition name of the item to load.
Returns:
am.item : The found definition or nil.
item_def ( string def_name , am.item def ) -> ( am.game )
Registers a character with the given definition name. Definition names are always namespaced to the file they were loaded from. For example filename:defname This filename should be relative to the data/defs/ folder. If no filename is given then the current file being loaded will be used. The files under data/defs/ will be automatically loaded when a definition with their filename is used. Definitions can also be registered from outside of those files, however they will need to always provide a filename. Definitions can be overridden.
Parameters:
string def_name : The name to store the item definition under.
am.item def : The item definition to store.
Returns:
am.game : This
add_dialogue ( am.dialogue dialogue ) -> ( boolean )
Adds the given dialogue to the dialogue pool.
Parameters:
am.dialogue dialogue : The dialogue to add to the pool.
Returns:
boolean : True if the dialogue was successfully added, false indicates that dialogue was nil or was already in the pool.
remove_dialogue ( am.dialogue dialogue ) -> ( boolean )
Removes a dialogue from the dialogue pool.
Parameters:
am.dialogue dialogue : The dialogue to remove.
Returns:
boolean : True if the dialogue was successfully removed, false indicates that the dialogue was nil or not found.
remove_dialogue ( string dialogue_id ) -> ( boolean )
Removes a dialogue from the dialogue pool.
Parameters:
string dialogue_id : The dialogue id of the dialogue to remove.
Returns:
boolean : True if the dialogue was successfully removed, false indicates that the dialogue was nil or not found.
remove_all_dialogue ( ) -> ( am.game )
Removes all dialogue from the dialogue pool.
Returns:
am.game : This
dialogue ( string dialogue_id ) -> ( am.dialogue )
Returns a dialogue with the given dialogue id, nil if no dialogue was found.
Parameters:
string dialogue_id : The id of the dialogue to look up.
Returns:
am.dialogue : The found dialogue or nil.
available_dialogues ( ) -> ( )
TODO
add_quest ( am.quest quest ) -> ( boolean )
Adds a quest to the quest pool.
Parameters:
am.quest quest : The quest to add.
Returns:
boolean : True if the quest was successfully added.
remove_quest ( am.quest quest ) -> ( boolean )
Removes a quest from the quest pool.
Parameters:
am.quest quest : The quest to remove from the quest pool.
Returns:
boolean : True if the quest was successfully removed.
remove_quest ( string quest_id ) -> ( boolean )
Removes a quest from the quest pool.
Parameters:
string quest_id : The id of the quest to remove from the quest pool.
Returns:
boolean : True if the quest was successfully removed.
quest ( string quest_id ) -> ( am.quest )
Returns a quest with the given quest id, nil if the quest could not be found.
Parameters:
string quest_id : The id of the quest to look up.
Returns:
am.quest : The found quest, or nil.
start_game ( ) -> ( am.game )
Tells the game that it can start. This should be called once it is ready to display the normal game HUD and have the appropriate game input listeners installed.
Returns:
am.game : This
has_started ( ) -> ( boolean )
Returns true if the game has started.
Returns:
boolean : True if the game has started.
load_game ( string save_name ) -> ( integer )
Attemps to load the game from a save file.
Parameters:
string save_name : The name of the save file to load.
Returns:
integer : A 1 for success, or 0 for error.
scenario_name ( ) -> ( string )
Returns the scenario name which this game is based off. The scenario name is set by the engine during a new game.
Returns:
string : The games scenario name.
generic_dead_graphic ( ) -> ( am.sprite )
Returns the generic dead graphic that is used when a specific dead graphic is not set onto a character.
Returns:
am.sprite : The generic dead graphic to use.
generic_dead_graphic ( string asset_name ) -> ( am.game )
Sets the generic dead graphic asset name to use when one has not been set onto the character itself.
Parameters:
string asset_name : The graphic asset name.
Returns:
am.game : This
generic_dead_graphic ( am.sprite sprite ) -> ( am.game )
Sets the generic dead graphic to use when one has not been set onto the character itself.
Parameters:
am.sprite sprite : The graphic to set.
Returns:
am.game : This
generic_dead_graphic ( nil grapic ) -> ( am.game )
Sets the generic dead graphic asset name to nil.
Parameters:
nil grapic : Sets to nil.
Returns:
am.game : This
attrs ( boolean create_table = false ) -> ( am.data_table )
Returns the game's attribute data table. By default if no attribute data table is present nil is returned unless true is passed as the first argument, then a data table is created if one is not present.
Parameters:
boolean create_table = false : Create a data table if one didn't exist.
Returns:
am.data_table : The data table on this game.
attrs ( am.data_table attrTable ) -> ( am.game )
Sets the data table on this game, can be set to nil.
Parameters:
am.data_table attrTable : The data table to set on the game.
Returns:
am.game : This