Hi again. Today's task is basic AI. Throughout the game world there will exists small entities, like chickens and rabbits and stuff.
Here is the code I''ll be using to spawn these guys.
Code: Select all
entities = {}
function spawnEntities(type, x, y, w, h, hp, speed, state, dir, anim)
table.insert(entities, {type = type, x=x, y=y, w=w, h=h, hp=hp, speed=speed, state=state, dir=dir, anim=anim})
end
function updateEntities(dt)
-- code to move them
end
function drawEntities()
for i=1, #entities do
entities[i].anim:draw(entities[i].x, entities[i].y)
end
end
Code: Select all
spawnEntities(chicken, 100, 100, 16, 16, 100, speed, alive, left, anim)
These chickens have animations for 4 directions. Left/Down/Up/Right, so the animation would need to change based on the direction it's walking in.
This one seems like a difficult task, but I appreciate any help.