Exemple #1
0
 public static bool operator ==(FRectangle a, FRectangle b)
 {
     return
         (FloatMath.EpsilonEquals(a.X, b.X) &&
          FloatMath.EpsilonEquals(a.Y, b.Y) &&
          FloatMath.EpsilonEquals(a.Width, b.Width) &&
          FloatMath.EpsilonEquals(a.Height, b.Height));
 }
Exemple #2
0
        private TimeSpan CalcTickPeriod()
        {
            // ranges from -1 to 1, with 0 being 'default'
            var ratio = FloatMath.Clamp(_timing.TickTimingAdjustment, -0.99f, 0.99f);
            var diff  = TimeSpan.FromTicks((long)(_timing.TickPeriod.Ticks * ratio));

            return(_timing.TickPeriod - diff);
        }
        protected override void OnProgress(MultiplayerJoinLobbyScreen element, float progress, InputState istate)
        {
            var off = Vector2.UnitX * (FloatMath.Sin(progress * FloatMath.TAU * 6) * 32) * (1 - FloatMath.FunctionEaseInCubic(progress));

            element.RelativePosition = realPos + off;

            element.HUD.Validate();
        }
        protected override FPoint SetParticleSpawnPosition(out bool doSpawn)
        {
            var len = FloatMath.GetRangedRandom(0, vectorPath.Length);
            var pos = vectorPath.Get(len);

            doSpawn = true;
            return(Position + (pos - vectorPathCenter));
        }
        protected override void OnProgress(UnlockPanel element, float progress, SAMTime gameTime, InputState istate)
        {
            var off = Vector2.UnitX * (FloatMath.Sin(progress * FloatMath.TAU * 6) * 32) * (1 - FloatMath.FunctionEaseInCubic(progress));

            element.RelativePosition = realPos + off;

            element.HUD.Validate();
        }
Exemple #6
0
        public static FPoint GetPointOnEllipse(float cx, float cy, float rx, float ry, float angle)
        {
            var t = GetEllipseTheta(angle, rx, ry);

            var x = FloatMath.Cos(t) * rx;
            var y = FloatMath.Sin(t) * ry;

            return(new FPoint(x + cx, y + cy));
        }
Exemple #7
0
        public static Vector2 RotateWithLength(this Vector2 v, float radians, float len)
        {
            var vlen = v.Length();

            var cos = FloatMath.Cos(radians);
            var sin = FloatMath.Sin(radians);

            return(new Vector2(((v.X * cos - v.Y * sin) * len) / vlen, ((v.X * sin + v.Y * cos) * len) / vlen));
        }
Exemple #8
0
        public FCircle AsTranslated(float offsetX, float offsetY)
        {
            if (FloatMath.IsZero(offsetX) && FloatMath.IsZero(offsetY))
            {
                return(this);
            }

            return(new FCircle(X + offsetX, Y + offsetY, Radius));
        }
        protected override void OnUpdate(SAMTime gameTime, InputState istate)
        {
            base.OnUpdate(gameTime, istate);

            if ((_runtime += gameTime.RealtimeElapsedSeconds) > PREVIEW_TIME && FloatMath.PercSin(gameTime.TotalElapsedSeconds * 2) > 0.85f)
            {
                _parent.SetNextScreen((_blueprintIndex + 1) % _blueprints.Length);
            }
        }
Exemple #10
0
 public static bool operator ==(FRotatedRectangle a, FRotatedRectangle b)
 {
     return
         (FloatMath.EpsilonEquals(a.CenterX, b.CenterX) &&
          FloatMath.EpsilonEquals(a.CenterY, b.CenterY) &&
          FloatMath.EpsilonEquals(a.Width, b.Width) &&
          FloatMath.EpsilonEquals(a.Height, b.Height) &&
          FloatMath.EpsilonEquals(a.Rotation, b.Rotation));
 }
Exemple #11
0
        public FRectangle AsTranslated(float offsetX, float offsetY)
        {
            if (FloatMath.IsZero(offsetX) && FloatMath.IsZero(offsetY))
            {
                return(this);
            }

            return(new FRectangle(X + offsetX, Y + offsetY, Width, Height));
        }
Exemple #12
0
        public static FRectangle Lerp(FRectangle ra, FRectangle rb, float percentage)
        {
            var minx = FloatMath.Lerp(ra.Left, rb.Left, percentage);
            var miny = FloatMath.Lerp(ra.Top, rb.Top, percentage);
            var maxx = FloatMath.Lerp(ra.Right, rb.Right, percentage);
            var maxy = FloatMath.Lerp(ra.Bottom, rb.Bottom, percentage);

            return(new FRectangle(minx, miny, maxx - minx, maxy - miny));
        }
Exemple #13
0
        public FRotatedRectangle AsTranslated(float offsetX, float offsetY)
        {
            if (FloatMath.IsZero(offsetX) && FloatMath.IsZero(offsetY))
            {
                return(this);
            }

            return(new FRotatedRectangle(CenterX + offsetX, CenterY + offsetY, Width, Height, Rotation));
        }
        protected override void OnProgress(SettingsButton button, float progress, InputState istate)
        {
            var pp = FloatMath.FunctionEaseOutQuad(progress);

            var xx = startX + (endX - startX) * pp;
            var yy = buttony + FloatMath.Sin(pp * FloatMath.PI) * SubSettingButton.DIAMETER * (1 + _posindex * 0.1f);

            _button.RelativePosition = new FPoint(xx, yy);
        }
Exemple #15
0
        private void GetState(float time, out FRectangle rect, out Color col, out float rot)
        {
            rect = _rect0;
            foreach (var tf in transformationsBounding)
            {
                if (time < tf.TimeStart)
                {
                    // nothing
                }
                else if (time > tf.TimeEnd)
                {
                    rect = tf.BoundingsFinal;
                }
                else
                {
                    var p = tf.TimeTransform((time - tf.TimeStart) / (tf.TimeEnd - tf.TimeStart));
                    rect = FRectangle.Lerp(tf.BoundingsStart, tf.BoundingsFinal, p);
                }
            }

            col = _col0;
            foreach (var tf in transformationsColor)
            {
                if (time < tf.TimeStart)
                {
                    // nothing
                }
                else if (time > tf.TimeEnd)
                {
                    col = tf.ColorFinal;
                }
                else
                {
                    var p = tf.TimeTransform((time - tf.TimeStart) / (tf.TimeEnd - tf.TimeStart));
                    col = ColorMath.Blend(tf.ColorStart, tf.ColorFinal, p);
                }
            }

            rot = _rot0;
            foreach (var tf in transformationsRotation)
            {
                if (time < tf.TimeStart)
                {
                    // nothing
                }
                else if (time > tf.TimeEnd)
                {
                    rot = tf.RotationFinal;
                }
                else
                {
                    var p = tf.TimeTransform((time - tf.TimeStart) / (tf.TimeEnd - tf.TimeStart));
                    rot = FloatMath.Lerp(tf.RotationStart, tf.RotationFinal, p);
                }
            }
        }
Exemple #16
0
        private void UpdateBarrel(SAMTime gameTime)
        {
            if (CannonHealth.TargetValue >= 1)
            {
                if (_remainingBullets > 0)
                {
                    _nextBulletTime -= gameTime.ElapsedSeconds;

                    if (_nextBulletTime <= 0)
                    {
                        if (controller.DoBarrelRecharge())
                        {
                            Shoot();
                        }
                        else if (controller.SimulateBarrelRecharge())
                        {
                            barrelRecoil = 0f;
                        }

                        _remainingBullets--;
                        _nextBulletTime += MINIGUN_BULLET_DELAY;
                    }

                    if (_remainingBullets <= 0)
                    {
                        _nextBulletTime = 0;
                    }
                }
                else
                {
                    float chargeDelta = BARREL_CHARGE_SPEED_MINIGUN * Fraction.BulletMultiplicator * RealBoost * gameTime.ElapsedSeconds;
                    if (Scale > 2.5f)
                    {
                        chargeDelta /= Scale;
                    }

                    BarrelCharge += chargeDelta;

                    if (BarrelCharge >= 1f)
                    {
                        BarrelCharge -= 1f;

                        _remainingBullets = MINIGUN_BULLET_COUNT;
                    }
                }
            }
            else
            {
                _remainingBullets = 0;
            }

            if (barrelRecoil < 1)
            {
                barrelRecoil = FloatMath.LimitedInc(barrelRecoil, BARREL_RECOIL_SPEED * Fraction.BulletMultiplicator * RealBoost * gameTime.ElapsedSeconds, 1f);
            }
        }
Exemple #17
0
        public override bool Start(IReadOnlyList <IPlayerSession> readyPlayers, bool force = false)
        {
            if (!force && readyPlayers.Count < MinPlayers)
            {
                _chatManager.DispatchServerAnnouncement($"Not enough players readied up for the game! There were {readyPlayers.Count} players readied up out of {MinPlayers} needed.");
                return(false);
            }

            var list     = new List <IPlayerSession>(readyPlayers);
            var prefList = new List <IPlayerSession>();

            foreach (var player in list)
            {
                if (!readyProfiles.ContainsKey(player.Name))
                {
                    continue;
                }
                var profile = readyProfiles[player.Name];
                if (profile.AntagPreferences.Contains(_prototypeManager.Index <AntagPrototype>(TraitorID).Name))
                {
                    prefList.Add(player);
                }
            }

            var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor,
                                              MinTraitors, readyPlayers.Count);

            for (var i = 0; i < numTraitors; i++)
            {
                IPlayerSession traitor;
                if (prefList.Count() == 0)
                {
                    traitor = _random.PickAndTake(list);
                    Logger.InfoS("preset", "Insufficient preferred traitors, picking at random.");
                }
                else
                {
                    traitor = _random.PickAndTake(prefList);
                    list.Remove(traitor);
                    Logger.InfoS("preset", "Selected a preferred traitor.");
                }
                var mind           = traitor.Data.ContentData().Mind;
                var antagPrototype = _prototypeManager.Index <AntagPrototype>(TraitorID);
                mind.AddRole(new SuspicionTraitorRole(mind, antagPrototype));
            }

            foreach (var player in list)
            {
                var mind           = player.Data.ContentData().Mind;
                var antagPrototype = _prototypeManager.Index <AntagPrototype>(InnocentID);
                mind.AddRole(new SuspicionInnocentRole(mind, antagPrototype));
            }

            _gameTicker.AddGameRule <RuleSuspicion>();
            return(true);
        }
		protected override void OnProgress(BaseWorldNode node, float progress, SAMTime gameTime, InputState istate)
		{
			var off = (Vector2.UnitX * (FloatMath.Sin(progress * FloatMath.TAU * 6) * SHAKE_OFFSET) * (1 - FloatMath.FunctionEaseInCubic(progress))).Rotate(rot);
			var p = FloatMath.FunctionEaseInOutQuad(progress);

			node.Owner.MapViewportCenterX = centeringStartOffset.X + off.X;
			node.Owner.MapViewportCenterY = centeringStartOffset.Y + off.Y;

			if (_screen.IsDragging) Abort();
		}
        protected override void OnProgress(GDWorldMapScreen screen, float perc, SAMTime gameTime, InputState istate)
        {
            var bounds = FRectangle.Lerp(rectStart, rectFinal, FloatMath.FunctionEaseInOutCubic(perc));

            vp.ChangeVirtualSize(bounds.Width, bounds.Height);
            screen.MapViewportCenterX = bounds.CenterX;
            screen.MapViewportCenterY = bounds.CenterY;

            screen.GDBackground.GridLineAlpha = 1 - perc;
        }
        protected override void OnProgress(GDOverworldScreen screen, float perc, SAMTime gameTime, InputState istate)
        {
            var bounds = FRectangle.Lerp(rectStart, rectFinal, FloatMath.FunctionEaseInSine(perc));

            vp.ChangeVirtualSize(bounds.Width, bounds.Height);
            screen.MapViewportCenterX = bounds.CenterX;
            screen.MapViewportCenterY = bounds.CenterY;

            _gdNode.AlphaOverride = FloatMath.FunctionEaseInExpo(perc, 10);
        }
Exemple #21
0
        private void CalcOuterCoords()
        {
            var p1 = new Vector2(+Width / 2f, -Height / 2f).Rotate(Rotation);
            var p2 = new Vector2(-Width / 2f, -Height / 2f).Rotate(Rotation);

            _cacheMostLeft   = FloatMath.Min(CenterX - p1.X, CenterX + p1.X, CenterX - p2.X, CenterX + p2.X);
            _cacheMostRight  = FloatMath.Max(CenterX - p1.X, CenterX + p1.X, CenterX - p2.X, CenterX + p2.X);
            _cacheMostTop    = FloatMath.Min(CenterY - p1.Y, CenterY + p1.Y, CenterY - p2.Y, CenterY + p2.Y);
            _cacheMostBottom = FloatMath.Max(CenterY - p1.Y, CenterY + p1.Y, CenterY - p2.Y, CenterY + p2.Y);
        }
 /// <summary>
 /// Return the current distance between the two pointers forming the
 /// gesture in progress.
 /// </summary>
 /// <remarks>
 /// Return the current distance between the two pointers forming the
 /// gesture in progress.
 /// </remarks>
 /// <returns>Distance between pointers in pixels.</returns>
 public virtual float GetCurrentSpan()
 {
     if (mCurrLen == -1)
     {
         float cvx = mCurrFingerDiffX;
         float cvy = mCurrFingerDiffY;
         mCurrLen = FloatMath.Sqrt(cvx * cvx + cvy * cvy);
     }
     return(mCurrLen);
 }
Exemple #23
0
        private void ShuffleIndizies()         // Fisher-Yates shuffle
        {
            int n = 5;

            while (n > 1)
            {
                n--;
                FloatMath.Swap(ref _shuffle[FloatMath.GetRangedIntRandom(n + 1)], ref _shuffle[n]);
            }
        }
Exemple #24
0
        protected override void Run(float perc)
        {
            var bounds = FRectangle.Lerp(rectStart, rectFinal, FloatMath.FunctionEaseInOutCubic(perc));

            vp.ChangeVirtualSize(bounds.Width, bounds.Height);
            Screen.MapViewportCenterX = bounds.CenterX;
            Screen.MapViewportCenterY = bounds.CenterY;

            _gdScreen.GDBackground.GridLineAlpha = 1 - perc;
        }
        protected override void Run(float perc)
        {
            var bounds = FRectangle.Lerp(rectStart, rectFinal, FloatMath.FunctionEaseOutSine(perc));

            vp.ChangeVirtualSize(bounds.Width, bounds.Height);
            Screen.MapViewportCenterX = bounds.CenterX;
            Screen.MapViewportCenterY = bounds.CenterY;

            _gdScreen.ColorOverdraw = FloatMath.FunctionEaseOutExpo(1 - perc, 10);
        }
Exemple #26
0
        protected override void OnProgress(GDWorldMapScreen screen, float perc, SAMTime gameTime, InputState istate)
        {
            var bounds = FRectangle.Lerp(rectStart, rectFinal, FloatMath.FunctionEaseOutSine(perc));

            vp.ChangeVirtualSize(bounds.Width, bounds.Height);
            screen.MapViewportCenterX = bounds.CenterX;
            screen.MapViewportCenterY = bounds.CenterY;

            _node.ColorOverdraw = perc;
        }
Exemple #27
0
        public void PositionTo2Byte(FPoint pos, out ushort x, out ushort y)
        {
            var xmin = MapFullBounds.Left - MapFullBounds.Width / 2f;
            var xmax = MapFullBounds.Right + MapFullBounds.Width / 2f;
            var ymin = MapFullBounds.Top - MapFullBounds.Height / 2f;
            var ymax = MapFullBounds.Bottom + MapFullBounds.Height / 2f;

            x = (ushort)FloatMath.IClamp(FloatMath.Round(((pos.X - xmin) / (xmax - xmin)) * 65535), 0, 65535);
            y = (ushort)FloatMath.IClamp(FloatMath.Round(((pos.Y - ymin) / (ymax - ymin)) * 65535), 0, 65535);
        }
Exemple #28
0
        private float GetAdjustedScore(Blackboard context)
        {
            var score = GetScore(context);
            var considerationsCount = context.GetState <ConsiderationState>().GetValue();
            var modificationFactor  = 1.0f - 1.0f / considerationsCount;
            var makeUpValue         = (1.0f - score) * modificationFactor;
            var adjustedScore       = score + makeUpValue * score;

            return(FloatMath.Clamp(adjustedScore, 0.0f, 1.0f));
        }
        public GDCellularBackground(GDGameScreen scrn, LevelBlueprint lvl) : base(scrn)
        {
            tileCountX = FloatMath.Ceiling(lvl.LevelWidth / 64f) + 2 * MAX_EXTENSION_X;
            tileCountY = FloatMath.Ceiling(lvl.LevelHeight / 64f) + 2 * MAX_EXTENSION_Y;
            wrapMode   = scrn.WrapMode;

            _grid = new GridCellMembership[tileCountX, tileCountY];

            Initialize();
        }
 /// <summary>
 /// Return the previous distance between the two pointers forming the
 /// gesture in progress.
 /// </summary>
 /// <remarks>
 /// Return the previous distance between the two pointers forming the
 /// gesture in progress.
 /// </remarks>
 /// <returns>Previous distance between pointers in pixels.</returns>
 public virtual float GetPreviousSpan()
 {
     if (mPrevLen == -1)
     {
         float pvx = mPrevFingerDiffX;
         float pvy = mPrevFingerDiffY;
         mPrevLen = FloatMath.Sqrt(pvx * pvx + pvy * pvy);
     }
     return(mPrevLen);
 }