Ejemplo n.º 1
0
        public void Thrust(int thrustStrength)
        {
            Vector deltaV = Dir.Multiply(thrustForce / mass);

            deltaV = deltaV.Multiply(thrustStrength);
            Vel    = (Vel.AddVector(deltaV)).LimitToMagnitude(MaxVel);
        }
Ejemplo n.º 2
0
 public Driving()
 {
     this.InitializeComponent();
     this.NavigationCacheMode =
         Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
     Vel.Focus(FocusState.Keyboard);
 }
Ejemplo n.º 3
0
        void updateBrain()
        {
            //input
            for (int i = 0; i < Eyes.Count; i++)
            {
                Inputs[i * 3]     = Eyes[i].Col.R / 255.0f;
                Inputs[i * 3 + 1] = Eyes[i].Col.G / 255.0f;
                Inputs[i * 3 + 2] = Eyes[i].Col.B / 255.0f;
            }
            Inputs[ListenId] = 0;

            /*foreach (var item in NearbyObjects)
             * {
             *  if(item is Creature)
             *  {
             *      Creature C = item as Creature;
             *      float Ratio = (C.Pos - Pos).MagSq() / (EyeRadius * EyeRadius);
             *      if (Ratio<=1)
             *      {
             *          Inputs[ListenId] += (1 - Ratio) * C.TalkValue;
             *      }
             *  }
             * }*/
            Inputs[ListenId] = Clamp01(Inputs[ListenId]);
            Inputs[EnergyId] = Clamp01(Energy / (StartEnergy + EggEnergy));
            Inputs[SpeedId]  = Clamp01(Vel.Mag() / MaxSpeed);
            Inputs[PollenId] = Pollen != null?1:0;
            Brain.SetInputs(Inputs);
            Brain.Update();
            //output
            Outputs   = Brain.GetOutputs();
            TalkValue = Clamp01(Outputs[3]);
        }
Ejemplo n.º 4
0
 public static MotionBehaviour <V> AccelByRatio <V, T>(this MotionBehaviour <V> self, V iv, T accel)
 {
     Syntax.Resolve <V>(self,
                        (e) => e.Add(Vel.AccelByRatio((float  )(object)iv, Syntax.AsEnumerator <float, T>(accel))),
                        (e) => e.Add(Vel.AccelByRatio((Vector2)(object)iv, Syntax.AsEnumerator <float, T>(accel))),
                        (e) => e.Add(Vel.AccelByRatio((Vector3)(object)iv, Syntax.AsEnumerator <float, T>(accel))),
                        (e) => e.Add(Vel.AccelByRatio((Vector4)(object)iv, Syntax.AsEnumerator <float, T>(accel)))
                        );
     return(self);
 }
Ejemplo n.º 5
0
 public static MotionBehaviour <V> Accel <V, T>(this MotionBehaviour <V> self, T accel)
 {
     Syntax.Resolve <V>(self,
                        (e) => e.Add(Vel.Accel(Syntax.AsEnumerator <float, T>(accel))),
                        (e) => e.Add(Vel.Accel(Syntax.AsEnumerator <Vector2, T>(accel))),
                        (e) => e.Add(Vel.Accel(Syntax.AsEnumerator <Vector3, T>(accel))),
                        (e) => e.Add(Vel.Accel(Syntax.AsEnumerator <Vector4, T>(accel)))
                        );
     return(self);
 }
Ejemplo n.º 6
0
        protected override void ApplyRotation(float delta, Physics2DDirectBodyState state)
        {
            if (Vel.Length() > 0f || RotateBy != 0)
            {
                Transform2D xform = state.Transform.Rotated(MathU.LerpAngle(state.Transform.Rotation, RotateBy == 0 ? LinearVelocity.Angle() + Mathf.Deg2Rad(90) : RotateBy,
                                                                            Type.RotationSpeed * delta * (Speed / Type.MaxSpeed) + Mathf.Abs(RotateBy / Mathf.Tau)) - state.Transform.Rotation);

                state.Transform = xform;
            }
        }
Ejemplo n.º 7
0
        public IsotropicGasParticle(double d, double hmax) : base(hmax)
        {
            this.D = d;

            dV      = new Position2D();
            dV.Name = "dV";
            AddChild(dV);
            Vel.AddDiffVect(dV, false);


            // AddDiffPropToParam(pRo,pdRo);
            AddDiffPropToParam(pE, pdE);
        }
Ejemplo n.º 8
0
        public override void Update()
        {
            Vel       = Vel.Multiply(friction);
            turnRate *= friction;
            theta     = turnRate;

            if (!cdHandler.IsOnCooldown())
            {
                Kill(Team.None);
            }

            base.Update();
        }
Ejemplo n.º 9
0
        public bool TryReactToCollision(int dmg, Vector collidingVel, int collidingMass, Team collidingTeam, bool forceReaction = false)
        {
            health -= dmg;

            float velTransferMod = ((float)collidingMass / (float)Mass);

            Vel = Vel.AddVector(collidingVel.Multiply(velTransferMod));
            Vel = Vel.LimitToMagnitude(MaxVel);

            if (health <= 0)
            {
                Kill(collidingTeam);
            }

            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initialise the particle
        /// </summary>
        /// <param name="pos">spawning position</param>
        /// <param name="dir">spawning direction</param>
        public void Init(Point2D pos, Vector dir)
        {
            thrustForce = Util.RandomInRange(velRange);
            turnRate    = Util.RandomInRange(turnRateRange);
            lifetime    = Util.RandomInRange(lifetimeRange);
            cdHandler   = new CooldownHandler(lifetime * 1000);
            cdHandler.StartCooldown();

            TeleportTo(pos);
            double theta = Dir.AngleTo(dir) * Math.PI / 180;

            this.theta = theta;

            Vector deltaV = dir.Multiply(-thrustForce);

            Vel = (Vel.AddVector(deltaV)).LimitToMagnitude(thrustForce);
        }
Ejemplo n.º 11
0
        public override void Update()
        {
            if (cdHandler != null)
            {
                if (cdHandler.IsOnCooldown())
                {
                    Vel       = Vel.Multiply(friction);
                    turnRate *= friction;
                    theta     = turnRate;

                    colorIndex = SwinGame.Rnd(colors.Count);
                }
                else
                {
                    Kill(Team.None);
                }
            }

            base.Update();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Object's reaction to being collided with
        /// </summary>
        /// <param name="dmg">incoming damage</param>
        /// <param name="collidingVel">velocity of other object</param>
        /// <param name="collidingMass">mass of other object</param>
        /// <param name="collider">
        /// team of other object</param>
        /// <param name="forceReaction">opt to bypass hurting timeout</param>
        public virtual bool TryReactToCollision(int dmg, Vector collidingVel, int collidingMass, Team collidingTeam, bool forceReaction = false)
        {
            if (!isHurting || forceReaction)
            {
                isHurting = true;
                hurtTimer.Start();

                health -= dmg;
                float velTransferMod = ((float)collidingMass / (float)Mass);
                Vel = Vel.AddVector(collidingVel.Multiply(velTransferMod));
                Vel = Vel.LimitToMagnitude(MaxVel);

                if (health <= 0)
                {
                    Kill(collidingTeam);
                }

                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
 public static MotionBehaviour <Vector3> Angle <T>(this MotionBehaviour <Vector3> self, T angle)
 {
     self.Wrap((v) => Vel.Angle(v, Syntax.AsEnumerator <Vector3, T>(angle)));
     return(self);
 }
Ejemplo n.º 14
0
        private void HandlerControl(float seconds)
        {
            if (!isDead && openControl)
            {
                float maxSpeed = SpaceWarConfig.SpeedMax;
                float accel    = SpaceWarConfig.SpeedAccel;
                if (stillTimer < 0)
                {
                    // 硬直状态
                    // maxSpeed *= cStillSpeedScale;
                    accel *= SpaceWarConfig.StillSpeedScale;
                }

                #region  获取键盘输入

                bool Up    = InputHandler.IsKeyDown(Keys.W);
                bool Left  = InputHandler.IsKeyDown(Keys.A);
                bool Down  = InputHandler.IsKeyDown(Keys.S);
                bool Right = InputHandler.IsKeyDown(Keys.D);

                Vector2 deltaSpeed = new Vector2();
                bool    noInput    = false;

                // 左上
                if (Up && Left && !Right && !Down)
                {
                    deltaSpeed.X = -cRootTwoDivideTwo;
                    deltaSpeed.Y = -cRootTwoDivideTwo;
                }
                // 右上
                else if (Up && Right && !Left && !Down)
                {
                    deltaSpeed.X = cRootTwoDivideTwo;
                    deltaSpeed.Y = -cRootTwoDivideTwo;
                }
                // 右下
                else if (Down && Right && !Up && !Left)
                {
                    deltaSpeed.X = cRootTwoDivideTwo;
                    deltaSpeed.Y = cRootTwoDivideTwo;
                }
                // 左下
                else if (Down && Left && !Up && !Right)
                {
                    deltaSpeed.X = -cRootTwoDivideTwo;
                    deltaSpeed.Y = cRootTwoDivideTwo;
                }
                // 上
                else if (Up && !Down)
                {
                    deltaSpeed.X = 0;
                    deltaSpeed.Y = -1.0f;
                }
                // 下
                else if (Down && !Up)
                {
                    deltaSpeed.X = 0;
                    deltaSpeed.Y = 1.0f;
                }
                // 左
                else if (Left && !Right)
                {
                    deltaSpeed.X = -1.0f;
                    deltaSpeed.Y = 0;
                }
                // 右
                else if (Right && !Left)
                {
                    deltaSpeed.X = 1.0f;
                    deltaSpeed.Y = 0;
                }
                else
                {
                    noInput = true;
                }

                #endregion

                #region 获得鼠标状态

                if (InputHandler.LastMouseLeftDown)
                {
                    Vector2 mousePos = InputHandler.GetCurMousePosInLogic(BaseGame.RenderEngine);
                    float   shootAzi = MathTools.AziFromRefPos(mousePos - this.Pos);

                    this.Shoot(shootAzi);
                }

                #endregion


                if (!noInput)
                {
                    phisicalUpdater.Azi = MathTools.AziFromRefPos(Vel);
                    deltaSpeed         *= seconds * accel;
                    Vel += deltaSpeed;
                    float SpeedAbs = Vel.Length();
                    if (SpeedAbs > maxSpeed)
                    {
                        Vel *= maxSpeed / SpeedAbs;
                    }
                }
                else // 衰减
                {
                    // 假设时间间隔是均匀的,并且间隔很小。
                    if (SpaceWarConfig.SpeedDecay * seconds < 1)
                    {
                        Vel *= (1 - SpaceWarConfig.SpeedDecay * seconds);
                    }
                }
                phisicalUpdater.Vel = Vel;
            }
        }