Adventure Game Template

Adventure Game Template allows you to easily create point-and-click adventure games with Awakening. It consists of several script files: game.lua, inventory.lua, item.lua, game_config.lua;
all script files can be found at the "scripts\Adventure Game" folder.
Hotspot:
A hotspot is an object which can occur something
when click on it. A mobile or overlay can be hotspot, just need name it with
'hotspot_' prefix. If a hotspot be clicked,
the game system will try to execute the Script
which has same name with the hotspot.
For example, you name a mobile with 'hotspot_tv',
so it will be a hotspot. Then you can define a Script Resource
also with name 'hotspot_tv', so the
Script will be called when someone click the hotspot. When the cursor on a
hotspot, it will use the image defined in g_config.cursor_hand_open
.
A hotspot with 'hotspot_portal_'
prefixed name is a portal hotspot. This sort of hotspots are no essential
difference to normal hotspots, just the cursor on it will use the image defined
in g_config.cursor_portal.
For example, you can name a door with 'hotspot_portal_door',
then use LoadScene() to transport
player to another scene.
Inventory:
The Inventory module let player can pick item, check item and use item, etc. A instance of inventory class means a inventory dialog, there is a default instance g_inv. You can new more instance for multiple inventory dialogs if you like.
Item:
Items are things like candle, key, notepaper, etc. When player pick a thing, you can add a item to inventory dialog like below:
local it=item.new('paper')
it.setDesc('a notepaper') -- set the description of item
it.setImage('\\inv\\paper.png')
it.setRect(rect.new(0,0,48,64))
it.OnSelect = function(bEnter)
if bEnter then -- select
g_inv.setCoverImage(
texturelist.addTexture('\\inv\\paper.png') )
else
-- deselect
end
end
g_inv.addItem(it)
The OnSelect
function can be absent. It will be called when user
select / deselect item.
If user select a item, then click on a hotspot, the game system will try to execute Script which has name: HotspotName_ItemID. For example, if select a item with ID 'candle', then click on a hotspot with name 'hotspot_desk', the game system will try to execute Script 'hotspot_desk_candle'.
Use the Template:
To use this Adventure Game Template, you need first copy all script files of Template to your scene folder (same folder with User Script File ). Then set configuration information in file game_config.lua. In User Script File, you need call events responding functions ( game_OnMouseMove, etc, see Reference below ) at appropriate locations.
Reference of Template:
Classes:
| Class Name | Explain |
| item | item |
| inventory | inventory |
| Variable Name | Explain |
| g_world | a native LUA table, you can use it to store information ( e.g. a variable indicates whether a door is opened ) which all through game. |
| g_config | a native LUA table that stores configuration information of the game engine. |
| g_msg | a native LUA table that stores tips message of hotspots. |
| g_inv | a instance of inventory class. |
| Function Name | Parameter | Return | Explain |
| game_OnMouseMove(x,y) | number x, y | None | should be called in the OnMouseMove() function of User Script File. |
| game_OnLButtonDown(x,y) | number x, y | boolean | should be called in the OnLButtonDown() function
of User Script File. If function processes this message, return true; otherwise return false. |
| game_OnLButtonUp(x,y) | number x, y | boolean | should be called in the OnLButtonUp()
function of User Script File. If function processes this message, return true; otherwise return false. |
| game_OnSize(type,cx,cy) | number type, cx, cy | None | should be called in the OnSize() function of User Script File. |
| game_FrameMove() | None | None | should be called in the FrameMove() function of User Script File. |
| game_Render2D() | None | None | should be called in the Render2D() function of User Script File. |
| getObjectOnCursor | number x, y | obj, vec vInter | Retrieves the object on specified cursor position. The function emit a ray started from assigned screen point, along camera direction, then return the first hited object , and the intersection point. If no hited object, the returned obj is nil, and vInter is a faraway point. The function checks mobiles, static meshs, surfaces, and terrains. |