func (p *Player) Update(other *Player, total_elapsed float64, elapsed float64) { p.Interpreter.SetFloat64("self.speed", p.Entity.Speed) p.Interpreter.SetFloat64("self.heading.x", p.Entity.VecTarget.X) p.Interpreter.SetFloat64("self.heading.y", p.Entity.VecTarget.Y) p.Interpreter.SetFloat64("self.position.x", p.Entity.Position.X) p.Interpreter.SetFloat64("self.position.y", p.Entity.Position.Y) p.Interpreter.SetFloat64("other.position.x", other.Entity.Position.X) p.Interpreter.SetFloat64("other.position.y", other.Entity.Position.Y) p.Interpreter.SetFloat64("total_elapsed", total_elapsed) p.Interpreter.SetFloat64("elapsed", elapsed) weapon := interpret.NewObject() weapon.Attributes["ammo"] = &interpret.Number{Value: 10} weapon.Attributes["recharge_time"] = &interpret.Number{Value: 5} weapon.Attributes["total_recharge_time"] = &interpret.Number{Value: 5} weapon.Attributes["weapon_id"] = &interpret.Number{Value: 1} p.Interpreter.SetArray("self.projectiles", []interpret.Object{}) p.Interpreter.SetArray("self.weapons", []interpret.Object{weapon}) newSpeed, _ := p.Interpreter.GetFloat64("self.speed") newHeadingX, _ := p.Interpreter.GetFloat64("self.heading.x") newHeadingY, _ := p.Interpreter.GetFloat64("self.heading.y") p.Entity.Speed = newSpeed p.Entity.VecTarget.X = newHeadingX p.Entity.VecTarget.Y = newHeadingY p.Entity.Update(other.Entity, elapsed) }
array.Values = append(array.Values, item) return nil, nil }, "random": func(args []interpret.Object) (interpret.Object, error) { return &interpret.Number{Value: rand.Float64()}, nil }, "vector": func(args []interpret.Object) (interpret.Object, error) { x1 := args[0].(*interpret.Number).Value y1 := args[1].(*interpret.Number).Value x2 := args[2].(*interpret.Number).Value y2 := args[3].(*interpret.Number).Value vector := physics.GenerateVector(&physics.Position{x1, y1}, &physics.Position{x2, y2}) physics.Normalize(vector) ret := interpret.NewObject() ret.Attributes["x"] = &interpret.Number{Value: vector.X} ret.Attributes["y"] = &interpret.Number{Value: vector.Y} return ret, nil }, "fire": func(args []interpret.Object) (interpret.Object, error) { ws_wrapper := args[0].(*interpret.ConcreteObject) ws := &types.WeaponSystem{} interpret.Unwrap(ws_wrapper, ws) if ws.Ammo > 0 && ws.RechargeTime >= ws.RechargeTimeTotal { ws.Ammo -= 1 ws.RechargeTime = 0 }