-
-
Save rubenwardy/b5cd1a01049e0c935ecf to your computer and use it in GitHub Desktop.
YAMM - Mock up api structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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