Skip to content

Instantly share code, notes, and snippets.

@rubenwardy

rubenwardy/init.lua Secret

Created Apr 25, 2013
Embed
What would you like to do?
YAMM - Mock up api structure
--[[
Example entity structure
{
animation = {
current = "walking",
frame = 0
},
flag = "grazing",
move = {
path = {} -- path it is currently following
}
}
]]--
-- Movement definition
YAMM.c("YAMM:move",{
on_spawn=function(entity)
if not entity.flags then
entity.flags = {}
end
table.insert(entity.flags,"watch") -- the animal is currently watching and searching for food
entity.move = {}
entity.move.path = nil
entity.animation.count = 0
end,
on_step = function(entity,dtime)
-- do pathgen movement stuff
end
})
-- Grazing definition
YAMM.c("YAMM:grazing",{
depends = {"YAMM:move"},
on_step=function(entity)
if entity.flag == "grazing" then
-- do grazing code here
if not entity.move.path then
entity.move.path = find_path(entity.position,{x:entity.position.x+5,y:entity.position.y, z:entity.position.z},5,2,2)
end
end
end
})
YAMM.e("YAMM:sheep",{
c = {"YAMM:move","YAMM:grazing","YAMM:prey"},
food = {"default:dirt_with_grass"}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment