lua-users home
lua-l archive

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


On Monday 08 December 2003 9:44 pm, Tim wrote:
> If I had the time, this is all predicated on time, which I have nill.  We
> have like a short
> time to do a game

1. have a file for each game object as you've described, but like this
HenchMan=
{
 pos={0,0,0},
 health=100,
}

Henchman.init()
Henchman.main()
Henchman.destroy()

2. have resources in a seperate file, the resource tells the code what actual resources are used eg:
resource{ID="BaddieClass1", gfxFile="myGeometry.blah", audio={"shout.wav", "taunt.wav"}}

3. have a main lua function for your game that's a coroutine. create objects at the start of your main function:

function exampleGame.main()
baddies={}
for loop-1,10 do
  baddies[loop] = createObject.(HenchMan, {pos={10,0,10}, anotherInitVar="hello"}}
end
...

the createObject function stores this obejct in a global object table, it also checks if the physical resources are
loaded if not, it loads them. it then inserts a C pointer to each of the resources created on the C++ side intot he lua object.
whenever a lua object needs to do something like play a sound or move itself, it passes the C++ pointer back to the host
function. eg utils.setPos(self, {5,5,5})

function utils.setPos(_object, _pos)
  HostSetObjectPos(_object.ObjectPointer, _pos[1], _pos[2], _pos[3])
end

each game tick, you call a lua 'main' function for your game
(if you have many games, just replace the tick function when you run your init script)

...
while (bGameActive) do
 utils.tickGameObjects()
 coroutine.yield()
end

utils.destroyGameObjects()

end

It's a really simple method and it works. we wrote 13 games in 3 months with two programmers. one of the coders had
never used C++ or any OO and certainly not Lua. we got it done with time to spare.

If you dont think this method will work, please tell me why, tell me what kind of thing you're trying to do
(ie what kind of game).

Rob