func (jm *JotaModule) MoveTowards(vs ...runtime.Val) runtime.Val { jm.dieOnTerminated() pos, ok := vs[0].Native().(*agoraVec) if !ok { base.Warn().Printf("Script called MoveTowards with the wrong type: %T", vs[0].Native()) return runtime.Nil } jm.engine.Pause() defer jm.engine.Unpause() g := jm.engine.GetState().(*game.Game) me := g.Ents[jm.myGid] if me == nil { base.Warn().Printf("Darn, I don't exist") return runtime.Nil } angle := pos.Regular().Sub(me.Pos()).Angle() jm.engine.ApplyEvent(game.Move{jm.myGid, angle, 1.0}) return runtime.Nil }
func (b *BaseEnt) BindAi(name string, engine *cgf.Engine) { if b.ai != nil { base.Warn().Printf("Can't bind an Ai when there is already one bound.") return } if b.Gid == "" { base.Error().Printf("Can't bind an Ai on an ent before setting its Gid.") return } b.ai = ai_maker(name, engine, b.Gid) b.ai.Start() }
func (editor *editorData) saveAction(room *Room) { data, err := json.MarshalIndent(room, "", " ") if err != nil { base.Error().Printf("Unable to encode room to json: %v", err) return } name := fmt.Sprintf("save-%v.json", time.Now()) fullPath := filepath.Join(base.GetDataDir(), name) err = ioutil.WriteFile(fullPath, data, 0664) if err != nil { base.Warn().Printf("Unable to write output json file: %v", err) return } }