self.color = {80, 160, 255}
local s = self.nearest("stranger")
local f = self.nearest("food")
local k = self.nearest("family")
if s.distance < 100 then
self.move(-s.direction.x * 3, -s.direction.y * 3)
elseif f.distance < 120 then
self.move(f.direction.x * 2, f.direction.y * 2)
self.eat(f)
elseif k.distance < 150 then
self.move(k.direction.x, k.direction.y)
else
local t = self.age * 0.02
self.move(math.sin(t), math.cos(t))
end
if self.energy > 160 then
self.reproduce()
end
entity.distance
Distance (0 for self).
entity.direction.x / .y
Normalized direction vector.
entity.count
Count nearby.
entity.density
Crowdedness.
entity.health
Current health.
entity.energy
Current energy.
entity.x, entity.y
Position.
entity.family
Group id.
entity.age
Frames alive.
entity.color = {r, g, b}
Set color (0-255).
entity.move(dx, dy)
Add movement force.
entity.eat(food)
Consume a specific food entity. Returns energy gained.
entity.attack(stranger)
Strike a specific non-group entity. Returns damage dealt.
entity.reproduce()
Split if energy is high enough.
entity.nearest("stranger")
Get nearest non-group entity.
entity.nearest("family")
Get nearest same-group entity.
entity.nearest("food")
Get nearest resource.
entity.distance(to entity)
Distance from self to another entity or coordinates.