Ejemplo n.º 1
0
        public static void Update(TankState state, TankAppliance appliance, PlayerData data, float elapsed)
        {
            state.Position += Vector.FromAngle(state.Rotation) * state.Speed * elapsed;

            if (data.keys.Contains("W"))
            {
                state.Speed += (float)(appliance.Acceleration *
                                       Math.Cos(Math.PI * (state.Speed / appliance.MaxSpeed) / 2f) * elapsed);
            }

            if (data.keys.Contains("S"))
            {
                state.Speed = (float)PolyTanks.Helpers.MathF.Max(0, state.Speed - appliance.Acceleration * elapsed);
            }

            if (data.keys.Contains("A"))
            {
                var movement = appliance.RotationSpeed * elapsed;
                state.Rotation    += movement;
                state.GunRotation += movement;
            }

            if (data.keys.Contains("D"))
            {
                var movement = appliance.RotationSpeed * elapsed;
                state.Rotation    -= movement;
                state.GunRotation -= movement;
            }

            state.Loading += 0.5f * elapsed;

            //gun rotation
            var target = 0f;

            if (Math.Abs(data.mouseDir - state.GunRotation) > 180)
            {
                if (state.GunRotation > 0)
                {
                    target = 180;
                }
                else if (state.GunRotation < 0)
                {
                    target = -180;
                }
            }
            else
            {
                target = data.mouseDir;
            }

            if (state.GunRotation == 180 || state.GunRotation == -180)
            {
                state.GunRotation = 179 * Math.Sign(data.mouseDir);
            }
            else
            {
                state.GunRotation = MathF.Reach(state.GunRotation, target, appliance.TurretSpeed * elapsed);
            }
        }