1
0
Fork 0
microworlds/actors/ant.go

36 lines
653 B
Go
Raw Normal View History

2019-08-03 02:00:33 +00:00
package actors
import (
"git.openprivacy.ca/sarah/microworlds/core"
)
type Ant struct {
SniffDistance int
2019-08-03 05:14:56 +00:00
Carrying bool
DropSize float32
2019-08-03 02:00:33 +00:00
}
2019-08-03 05:14:56 +00:00
func (a *Ant) Setup(env *core.Environment, t *core.Turtle) {
2019-08-03 02:00:33 +00:00
//t.SetXY(150,150)
}
2019-08-03 05:14:56 +00:00
func (a *Ant) Run(env *core.Environment, t *core.Turtle) {
2019-08-03 02:00:33 +00:00
if a.Carrying == false {
if env.HasValue(t.Pos()) {
env.TakeValue(t.Pos())
a.Carrying = true
a.DropSize = 100
t.TurnAround()
} else {
t.Wiggle()
t.FollowGradient(env, a.SniffDistance, 5, "food")
2019-08-03 02:00:33 +00:00
}
t.Step(env)
2019-08-03 05:14:56 +00:00
} else if a.Carrying == true {
2019-08-03 02:00:33 +00:00
a.DropSize -= 0.6
t.Drop(env, a.DropSize, "food")
2019-08-03 02:00:33 +00:00
t.Wiggle()
t.Step(env)
}
}