
yes is true, the player remains alive at 1 HP. Well is easy to fix.
The die of entities with coroutines is a difficult task. I was thinking about have two or more task per entity. One task to execute the behaviour and another task to control the messages. One example of behaviour task can be:
-------------------------------------------------------------------------------
function MoveTo( scheduler, entity, x, y )
local incx, incy
if ( x - entity.x ) > 0 then
incx = 1
else
incx = -1
end
if ( y - entity.y ) > 0 then
incy = 1
else
incy = -1
end
while entity.x ~= x or entity.y ~= y do
if entity.x ~= x then
entity.x = entity.x + incx
end
if entity.y ~= y then
entity.y = entity.y + incy
end
scheduler.Transfer()
end
end
-------------------------------------------------------------------------------
function Boss()
local fun = function( scheduler )
local entity = {}
entity.x = 0
entity.y = 0
while true do
MoveTo( scheduler, entity, 0, 10 )
MoveTo( scheduler, entity, 10, 10 )
--Shot()
MoveTo( scheduler, entity, 10, 0 )
MoveTo( scheduler, entity, 0, 0 )
scheduler:Sleep( 20 )
end
end
return fun
end
The MoveTo function is a generic one, all entities can use it. We can have generic functions like PlayAnimation, MoveTo, gfx effects..etc. The main function of the 'boss' only use the generic functions.
Zhen.