lua-users home
lua-l archive

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


I am working on a pretty simple bomberman-esque game, and I was really wanting to embed Lua for the first time in it, I have a few questions so please bear with me. Basically what I'm thinking of doing is having a BomberEnemy class, then having an init##.lua that would be called for the various levels to create some enemies and perhaps set some settings, this I could fairly easily work out. Then I was thinking of having enemyType.lua files for each enemy type, and then each enemy would call Update each frame which would call it's lua script to do the AI.

BomberMap,BomberPlayer,BomberEtc.. then
BomberEnemy -> LuaBomberEnemy (in style of recently posted Account c++ example) then the enemy.lua files could access all the functions of a BomberEnemy.. helping it find empty positions, the player position and other useful methods. My problem is if I use this technique the Lua objects would be created via Lua (of course I could have the constructor stick them in a static container) and would then need to be accessed from C++, for stuff like collision detection with other players and drawing, yet basically one method (BomberEnemy::Act) would need to call Lua. How would I be able to write an enemies AI, something like:

if(curtime() - enemy.LastBomb() > 1000)
     enemy.PlaceBomb();
if(enemy.MapEmpty(FORWARD))
     enemy.MoveForward();

I was thinking that since classes accessed from Lua basically have a static method access an internal pointer I could somehow pass an enemy pointer in, but I'm not familiar with all that boxpointer stuff. I was thinking from C++
void BomberEnemy::Act()
{
      //pass self into Lua somehow as a LuaBomberEnemy named enemy
      //run a single file 'dumb_enemy.lua'
}

If anybody can give me any insight into the best way to work this system I'd appreciate it greatly.
     -James

(PS. Thanks to Peter Shook for his Account example which answered some of my other questions.)