[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

game scripts




 Hi, I have adapted LUA script language 
( http://www.tecgraf.puc-rio.br/lua/ ) for a rpg project
I'm writing. I was thinking about an easy (yet poweful)
script engine, so I came up with this model:

a 'location' is a group of 'maps' a player can visit, like
a city and its houses and rooms, shops etc.

A 'map' is a table of characters describing the environment,
like a room in a house or a dungeon. A 'map' has defined
positions, so that it is easier to undestand the script.
For instance: City.House_X.door

A map can connect to another by structures I called 'links'.
That's useful when the player walks through a door, so he is
'transported' to the new map.

Then I thought that maybe instead of these links, I should
use events, then I can interrupt user input anywhere I want
and put a cut-scene, for instance. The gate between two
maps would be just a very common type of event.

Notice that the script engine runs in a different thread,
so the script can call actions to be executed concurrently
and wait for events when it needs to sync. Then when it
calls a function to move a character, it should wait until
a "stop" event is sent.

Here is an example where the player enters a city, and wander
until he triggers an expected event:

-- Lua Interpreted script for GAME v0.0
-- Lines begining with '--' are comments

-- This function is called when the player enters city_X.
function city_X()

    -- NewLocation("ID Name", "filename")
    -- This loads a new location, maps and some events
    City = NewLocation("X City", "city_X.location");

    -- Non-playable part of game:
    -- method show() -> put map on screen
    City.Street.show();

    -- Character walks 5 positions from begining of the map
    -- Notice: Knight is global
    Knight.position = City.Street.origin;
    Knight.relative_move(0, 5);
    WaitEvent(Knight, "stop");

    -- Set an aditional event:
    LeavingFunction = function()
        Knight.say("I can't leave yet...");
        WaitEvent(Input, "keypress");
        Knight.relative_move(0, 5);
        WaitEvent(Knight, "stop");
    end
    -- NewEvent(event_type, args...)
    LeavingEvent = NewEvent("sprite_over", Knight, City.Street.origin,
        LeavingFunction);

    -- Playable part:
    -- Allow the player to move the character until the expected event happens
    while (GAME_EVENT != City.TriggerEvent)
        Knight.move(Input);

    -- Continue
    ...

end


I know it still needs improvement.  But what do you think?
Any thoughts about it? Anyone wants to bash? :)

---------------------------------------------------------------------
To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.dk
For additional commands, e-mail: linuxgames-help@sunsite.dk