Skip to content

Instantly share code, notes, and snippets.

@rubenwardy
Created April 25, 2013 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenwardy/b5cd1a01049e0c935ecf to your computer and use it in GitHub Desktop.
Save rubenwardy/b5cd1a01049e0c935ecf to your computer and use it in GitHub Desktop.
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