Just a bit of a text update.
I've spent most of the week implementing this crazy big entity system that will handle everything in the game.
I've also ran across quite a few of neat Lua tricks that are going to come in handy. (Thanks MOAI IRC guys!
ps. TIGSOURCE IRC GUYS STINK. )
most notably lua proxies!
Magical lua proxies.
-- create metatable
local mt = {
__newindex = function (t,k,v)
if t.writing then
t.writing(k,v)
end
t.obj[k] = v -- update original table
end
}
function track (t,writefunction,readingfunction)
local proxy = {}
proxy.obj = t
proxy.writing = writefunction
proxy.reading = readingfunction
setmetatable(proxy, mt)
return proxy
end
This wonderful little bit of code essentially makes a listener that looks at a data table and runs a function when i change something in that data table. Super useful.
That means i can just set something like player.health = 0, and then the listener takes over and deletes the entity, makes the effects and updates the UI elements all at once.
Neat!
-------------------------
For the entity system I'm trying to set it up on a modular way.
A basic entity will consist of the box2D physics, the sprites and a controller.
The controller will take basic input commands which will either be keyboard input or AI input, so theoretically I could control any enemy in the game with one line of code.
This is all generic as i want to use this stuff for multiple games in the future, and should serve me well as a robust prototyping system.
I'm not going to be directly parenting objects to the box 2d collision. Instead I will just parent the transform and instead drive the rotation through a rounding function so that i can constrain sprite rotations to what ever number of angles i want. It makes things feel snappier and works better for the aesthetic I'm going for.
Anyhow, that's all for tonight. I'll try and get the basic gameplay implemented over the next few days, as it's all going to start coming together really fast once i finish laying this groundwork.