Example #1
0
        public IEnumerable <ActorBase> FindCollisionActorsRadius(float x, float y, float radius)
        {
            for (int i = 0; i < actors.Count; ++i)
            {
                if ((actors[i].CollisionFlags & CollisionFlags.CollideWithOtherActors) == 0)
                {
                    continue;
                }

                Hitbox hitbox = actors[i].Hitbox;

                // Find the closest point to the circle within the rectangle
                float closestX = MathF.Clamp(x, hitbox.Left, hitbox.Right);
                float closestY = MathF.Clamp(y, hitbox.Top, hitbox.Bottom);

                // Calculate the distance between the circle's center and this closest point
                float distanceX = x - closestX;
                float distanceY = y - closestY;

                // If the distance is less than the circle's radius, an intersection occurs
                float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
                if (distanceSquared < (radius * radius))
                {
                    yield return(actors[i]);
                }
            }
        }
Example #2
0
        private void SourceTilemap_EventTilemapChanged(object sender, TilemapChangedEventArgs e)
        {
            // If we resized our tilemap, we'll have to do a full update
            Point2 newTileCount = GetTileCount(this.sourceTilemaps);

            if (newTileCount != this.tileCount)
            {
                this.UpdateRigidBody(false);
            }
            // Otherwise, only update the sectors that are affected by the change
            else
            {
                Point2 minSector = new Point2(
                    MathF.Clamp(e.Pos.X / SectorSize, 0, this.sectorCount.X),
                    MathF.Clamp(e.Pos.Y / SectorSize, 0, this.sectorCount.Y));
                Point2 maxSector = new Point2(
                    MathF.Clamp(1 + (e.Pos.X + e.Size.X) / SectorSize, 0, this.sectorCount.X),
                    MathF.Clamp(1 + (e.Pos.Y + e.Size.Y) / SectorSize, 0, this.sectorCount.Y));
                RigidBody body = this.GameObj.GetComponent <RigidBody>();
                this.UpdateRigidBody(body,
                                     minSector.X,
                                     minSector.Y,
                                     maxSector.X - minSector.X,
                                     maxSector.Y - minSector.Y);
            }
        }
        private float GetRangedWeaponStrength(ItemObject item)
        {
            WeaponComponentData weaponData = item.PrimaryWeapon;
            double num1;

            switch (item.ItemType)
            {
            case ItemObject.ItemTypeEnum.Crossbow:
                num1 = 0.7;
                break;

            case ItemObject.ItemTypeEnum.Musket:
                num1 = 0.5;
                break;

            default:
                num1 = 1.0;
                break;
            }
            double num2  = (double)weaponData.ThrustDamage * 0.2 + (double)weaponData.ThrustSpeed * 0.02 + (double)weaponData.Accuracy * 0.02;
            float  tierf = (float)(num1 * num2 - 11.0);

            tierf = MathF.Clamp(tierf, 0, 10);

            return(tierf * 0.2f + 0.8f);
        }
Example #4
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     base.OnKeyDown(e);
     if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
     {
         this.SelectedEntry = null;
     }
     else if (e.KeyCode == Keys.Return)
     {
         this.entryMenu_CopyItem_Click(this, EventArgs.Empty);
     }
     else if (e.KeyCode == Keys.C && e.Control && this.SelectedEntry != null)
     {
         this.entryMenu_CopyItem_Click(this, EventArgs.Empty);
     }
     else if (e.KeyCode == Keys.Down && this.DisplayedEntries.Any())
     {
         ViewEntry[] visEntries = this.DisplayedEntries.ToArray();
         this.SelectedEntry = visEntries[MathF.Clamp(visEntries.IndexOfFirst(this.SelectedEntry) + 1, 0, visEntries.Length - 1)];
         this.EnsureVisible(this.SelectedEntry);
     }
     else if (e.KeyCode == Keys.Up && this.DisplayedEntries.Any())
     {
         ViewEntry[] visEntries = this.DisplayedEntries.ToArray();
         this.SelectedEntry = visEntries[MathF.Clamp(visEntries.IndexOfFirst(this.SelectedEntry) - 1, 0, visEntries.Length - 1)];
         this.EnsureVisible(this.SelectedEntry);
     }
 }
 public override float CalculateMoraleChangeToCharacter(
     Agent agent,
     float moraleChange,
     float distance)
 {
     return(moraleChange / MathF.Clamp(agent.Character.GetPower(), 0.7f, 10f));
 }
Example #6
0
        /// <summary>
        /// Given the specified coordinate in local / object space, this method returns the
        /// tile index that is located there.
        /// </summary>
        /// <param name="localPos"></param>
        /// <param name="pickMode">Specifies the desired behavior when attempting to get a tile outside the rendered area.</param>
        /// <returns></returns>
        public Point2 GetTileAtLocalPos(Vector2 localPos, TilePickMode pickMode)
        {
            // Early-out, if the specified local position is not within the tilemap rect
            Rect localRect = this.LocalTilemapRect;

            if (pickMode == TilePickMode.Reject && !localRect.Contains(localPos))
            {
                return(new Point2(-1, -1));
            }

            Tilemap tilemap   = this.ActiveTilemap;
            Tileset tileset   = tilemap != null ? tilemap.Tileset.Res : null;
            Point2  tileCount = tilemap != null ? tilemap.Size : Point2.Zero;
            Vector2 tileSize  = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize;

            // Determine the tile index at the specified local position
            Point2 tileIndex = new Point2(
                (int)MathF.Floor((localPos.X - localRect.X) / tileSize.X),
                (int)MathF.Floor((localPos.Y - localRect.Y) / tileSize.Y));

            // Clamp or reject the tile index when required
            if (pickMode != TilePickMode.Free)
            {
                if (tileCount.X <= 0 || tileCount.Y <= 0)
                {
                    return(new Point2(-1, -1));
                }

                tileIndex = new Point2(
                    MathF.Clamp(tileIndex.X, 0, tileCount.X - 1),
                    MathF.Clamp(tileIndex.Y, 0, tileCount.Y - 1));
            }

            return(tileIndex);
        }
Example #7
0
        private void UpdateRotation(float mouseMoveX, float mouseMoveY)
        {
            if (!this._initialized)
            {
                return;
            }
            this._panRotation  += mouseMoveX * ((float)Math.PI / 720f);
            this._tiltRotation += mouseMoveY * ((float)Math.PI / 720f);
            this._tiltRotation  = MathF.Clamp(this._tiltRotation, -2.984513f, -0.1570796f);
            MatrixFrame frame1    = this._model.GetFrame();
            Vec3        vec3      = (this._model.GetBoundingBoxMax() + this._model.GetBoundingBoxMin()) * 0.5f;
            MatrixFrame identity1 = MatrixFrame.Identity;

            identity1.origin = vec3;
            MatrixFrame identity2 = MatrixFrame.Identity;

            identity2.origin = -vec3;
            MatrixFrame matrixFrame = frame1 * identity1;

            matrixFrame.rotation = Mat3.Identity;
            matrixFrame.rotation.ApplyScaleLocal(this._initialFrame.rotation.GetScaleVector());
            matrixFrame.rotation.RotateAboutSide(this._tiltRotation);
            matrixFrame.rotation.RotateAboutUp(this._panRotation);
            MatrixFrame frame2 = matrixFrame * identity2;

            this._model.SetFrame(ref frame2);
        }
Example #8
0
        void UpdateLineRenderer(bool in_shoot)
        {
            if (m_scanLineRenderer != null)
            {
                SetLineRendererEndPos();

                if (in_shoot)
                {
                    m_scanLineRenderer.ColorStart = m_scanColorDetected1;
                    m_scanLineRenderer.ColorEnd   = m_scanColorDetected2;
                }
                else
                {
                    float fadeIn = MathF.Clamp(1 - (m_countdownToAttack / m_scanDuration), 0.0f, 1.0f);
                    byte  alpha  = (byte)((int)(255 * fadeIn));
                    //VisualLog.Default.DrawText(this.GameObj.Transform.Pos.X, this.GameObj.Transform.Pos.Y, 0, String.Format("alpha: {0}, alphaMult: {1}", alpha, alphaMult));

                    ColorRgba startColor = m_scanColor1;
                    startColor.A = alpha;
                    ColorRgba endColor = m_scanColor2;
                    endColor.A = alpha;
                    m_scanLineRenderer.GameObj.Transform.Angle = 0.0f;
                    m_scanLineRenderer.EndWidth   = MathF.Lerp(100.0f, 30.0f, fadeIn);
                    m_scanLineRenderer.ColorStart = startColor;
                    m_scanLineRenderer.ColorEnd   = endColor;
                }
            }
        }
Example #9
0
        void ICmpUpdatable.OnUpdate()
        {
            // Early-out, if no target is specified
            if (this.targetObj == null)
            {
                return;
            }
            if (this.targetObj.Transform == null)
            {
                return;
            }

            Transform transform = this.GameObj.Transform;
            Camera    camera    = this.GameObj.GetComponent <Camera>();

            Vector3 camAreaTopLeft     = camera.GetSpaceCoord(new Vector2(0.0f, 0.0f));
            Vector3 camAreaBottomRight = camera.GetSpaceCoord(DualityApp.TargetResolution);
            Rect    camArea            = new Rect(
                camAreaTopLeft.X,
                camAreaTopLeft.Y,
                camAreaBottomRight.X - camAreaTopLeft.X,
                camAreaBottomRight.Y - camAreaTopLeft.Y);

            Vector3 targetPos     = this.GetTargetPos();
            Vector3 posDiff       = (targetPos - transform.Pos);
            float   posDiffLength = posDiff.Length;

            if (posDiffLength > 0.0f)
            {
                Vector3 posDiffDir = posDiff.Normalized;
                Vector3 moveBy     = posDiffDir * posDiffLength * MathF.Clamp(0.1f * MathF.Pow(2.0f, -this.smoothness) * Time.TimeMult, 0.2f * Time.TimeMult, 1.0f);
                transform.MoveByAbs(moveBy);
            }
        }
Example #10
0
 /// <summary>
 /// Creates a new color based on value (brightness) and alpha.
 /// </summary>
 /// <param name="value">The value / brightness of the color as float [0.0f - 1.0f].</param>
 /// <param name="a">The colors alpha value as float [0.0f - 1.0f].</param>
 public ColorRgba(float value, float a = 1.0f)
 {
     this.R = (byte)MathF.Clamp((int)(value * 255.0f), 0, 255);
     this.G = this.R;
     this.B = this.R;
     this.A = (byte)MathF.Clamp((int)(a * 255.0f), 0, 255);
 }
        private static IEnumerable <ItemRosterElement> LootCasualties2(ICollection <TroopRosterElement> shareFromCasualties, float lootChance)
        {
            // MobileParty.GetMainPartySkillCounsellor(DefaultSkills.Roguery).GetSkillValue(DefaultSkills.Roguery)
            ItemRoster itemRosters         = new ItemRoster();
            Dictionary <string, int> loots = new Dictionary <string, int>();

            lootChance = MathF.Clamp(lootChance * 1.3f, 20f, 95f);

            foreach (TroopRosterElement casualty in shareFromCasualties)
            {
                Equipment randomEquipment    = GetRandomEquipment(casualty.Character);
                var       potentialLootItems = GetItemsFromEquipmentSlots(randomEquipment);
                foreach (ItemObject item in potentialLootItems)
                {
                    float rdm = MBRandom.RandomFloatRanged(100f);
                    if (rdm < lootChance)
                    {
                        if (loots.ContainsKey(item.StringId))
                        {
                            loots[item.StringId] += 1;
                        }
                        else
                        {
                            loots.Add(item.StringId, 1);
                        }
                    }
                }
            }
            foreach (var stringId in loots.Keys)
            {
                itemRosters.Add(new ItemRosterElement(MBObjectManager.Instance.GetObject <ItemObject>(stringId), loots[stringId]));
            }
            return(itemRosters);
        }
Example #12
0
        public Vector2 Activate(ActorBase other)
        {
            Player collider = other as Player;

            if (collider != null && Transform.Pos.Y > collider.Transform.Pos.Y)
            {
                if (currentTransitionState == AnimState.Idle)
                {
                    float selfX     = Transform.Pos.X;
                    float colliderX = collider.Transform.Pos.X;

                    float mult = (colliderX - selfX) / currentAnimation.Base.FrameDimensions.X;
                    if (IsFacingLeft)
                    {
                        mult = 1 - mult;
                    }
                    mult = MathF.Clamp(mult * 1.6f, 0.4f, 1f);

                    float force = 1.9f * mult;
                    collider.AddExternalForce(0f, force);

                    SetTransition(AnimState.TransitionActivate, false);
                    return(new Vector2(0f, -1f));
                }
            }

            return(Vector2.Zero);
        }
Example #13
0
 /// <summary>
 /// Creates a new color.
 /// </summary>
 /// <param name="r">The red component as float [0.0f - 1.0f].</param>
 /// <param name="g">The green component as float [0.0f - 1.0f].</param>
 /// <param name="b">The blue component as float [0.0f - 1.0f].</param>
 /// <param name="a">The alpha component as float [0.0f - 1.0f].</param>
 public ColorRgba(float r, float g, float b, float a = 1.0f)
 {
     this.R = (byte)MathF.Clamp((int)(r * 255.0f), 0, 255);
     this.G = (byte)MathF.Clamp((int)(g * 255.0f), 0, 255);
     this.B = (byte)MathF.Clamp((int)(b * 255.0f), 0, 255);
     this.A = (byte)MathF.Clamp((int)(a * 255.0f), 0, 255);
 }
Example #14
0
        private void UpdateColor()
        {
            SpriteRenderer sprite  = this.GameObj.GetComponent <SpriteRenderer>();
            float          fadeOut = MathF.Clamp(this.lifetime / 0.25f, 0.0f, 1.0f);

            sprite.ColorTint = this.teamColor.WithAlpha(fadeOut);
        }
Example #15
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     base.OnKeyDown(e);
     if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
     {
         this.SelectedEntry = null;
     }
     else if (e.KeyCode == Keys.Return)
     {
         this.entryMenu_CopyItem_Click(this, EventArgs.Empty);
     }
     else if (e.KeyCode == Keys.C && e.Control && this.SelectedEntry != null)
     {
         this.entryMenu_CopyItem_Click(this, EventArgs.Empty);
     }
     else if (e.KeyCode == Keys.Down && this.displayedEntryList.Any())
     {
         int newEntryIndex = MathF.Clamp(this.displayedEntryList.IndexOfFirst(this.SelectedEntry) + 1, 0, this.displayedEntryList.Count - 1);
         this.SelectedEntry = this.displayedEntryList[newEntryIndex];
         this.EnsureVisible(this.SelectedEntry);
     }
     else if (e.KeyCode == Keys.Up && this.displayedEntryList.Any())
     {
         int newEntryIndex = MathF.Clamp(this.displayedEntryList.IndexOfFirst(this.SelectedEntry) - 1, 0, this.displayedEntryList.Count - 1);
         this.SelectedEntry = this.displayedEntryList[newEntryIndex];
         this.EnsureVisible(this.SelectedEntry);
     }
 }
Example #16
0
        private bool Iterate()
        {
            if (_time.CurrentFloat >= _finishTime)
            {
                SetValue(_finishValue);

                if (_finishCallback == null)
                {
                    _state = TweenState.Finished;
                    return(false);
                }
                else
                {
                    _state = TweenState.Callback;
                    return(true);
                }
            }
            else
            {
                var time = MathF.Clamp(_time.CurrentFloat - _startTime, 0, _duration);
                var v    = _function(time, 0, 1, _duration);
                _current = MathF.Lerp(_startValue, _finishValue, v);

                SetValue(_current);
                return(true);
            }
        }
Example #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public float this[int index]
        {
            get
            {
                switch (index)
                {
                case 0: return(r);

                case 1: return(g);

                case 2: return(b);

                case 3: return(a);
                }

                throw new ArgumentOutOfRangeException("index", "less than 4");
            }

            set
            {
                switch (index)
                {
                case 0: r = MathF.Clamp(value, 0.0f, 1.0f); break;

                case 1: g = MathF.Clamp(value, 0.0f, 1.0f); break;

                case 2: b = MathF.Clamp(value, 0.0f, 1.0f); break;

                case 3: a = MathF.Clamp(value, 0.0f, 1.0f); break;

                default: throw new ArgumentOutOfRangeException("index", "less than 4");
                }
            }
        }
Example #18
0
        public HitObject[] GenerateHitObjects(Table.Table table, PrimitiveMeshGenerator meshGenerator, IItem item)
        {
            if (_data.Name == "playfield_mesh")
            {
                _data.IsVisible           = false;
                _primitive.UseAsPlayfield = true;
            }

            // playfield can't be a toy
            if (_data.IsToy && !_primitive.UseAsPlayfield)
            {
                return(new HitObject[0]);
            }

            var mesh = meshGenerator.GetTransformedMesh(table, Origin.Global, false);

            var reducedVertices = System.Math.Max(
                (uint)MathF.Pow(mesh.Vertices.Length,
                                MathF.Clamp(1f - _data.CollisionReductionFactor, 0f, 1f) * 0.25f + 0.75f),
                420u                 //!! 420 = magic
                );

            if (reducedVertices < mesh.Vertices.Length)
            {
                mesh = ComputeReducedMesh(mesh, reducedVertices);
            }

            return(MeshToHitObjects(mesh, ItemType.Primitive, item).Select(ho => SetupHitObject(ho, table)).ToArray());
        }
Example #19
0
        /// <summary>
        /// Resolves the <see cref="Index"/> values of the specified <see cref="Tile"/> grid area, given the grid's raw data block.
        /// </summary>
        /// <param name="tileGridData"></param>
        /// <param name="beginX"></param>
        /// <param name="beginY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="stride"></param>
        /// <param name="tilesetRes"></param>
        public static void ResolveIndices(Tile[] tileGridData, int stride, int beginX, int beginY, int width, int height, ContentRef <Tileset> tileset)
        {
            if (tileset.Res == null)
            {
                throw new ArgumentNullException("tileset");
            }
            if (!tileset.Res.Compiled)
            {
                throw new InvalidOperationException("The specified Tileset needs to be compiled first.");
            }

            Tileset tilesetRes = tileset.Res;

            TileInfo[] tileData  = tilesetRes.TileData.Data;
            int        tileCount = tilesetRes.TileCount;

            for (int y = beginY; y < beginY + height; y++)
            {
                for (int x = beginX; x < beginX + width; x++)
                {
                    int i                        = y * stride + x;
                    int baseIndex                = MathF.Clamp(tileGridData[i].BaseIndex, 0, tileCount - 1);
                    int autoTileIndex            = tileData[baseIndex].AutoTileLayer - 1;
                    TilesetAutoTileInfo autoTile = autoTileIndex > -1 ? tilesetRes.AutoTileData[autoTileIndex] : null;

                    tileGridData[i].ResolveIndex(autoTile);
                }
            }
        }
Example #20
0
            public void UpdateFromSource(IMouseInputSource source)
            {
                this.IsAvailable = source != null ? source.IsAvailable : false;
                if (source == null)
                {
                    return;
                }

                this.WindowPos = source.Pos;
                this.Wheel     = source.Wheel;
                for (int i = 0; i < this.ButtonPressed.Length; i++)
                {
                    this.ButtonPressed[i] = source[(MouseButton)i];
                }

                // Map window position to game view position
                Rect    viewportRect;
                Vector2 gameViewSize;

                DualityApp.CalculateGameViewport(DualityApp.WindowSize, out viewportRect, out gameViewSize);
                Vector2 relativePos = new Vector2(
                    MathF.Clamp((this.WindowPos.X - viewportRect.X) / viewportRect.W, 0.0f, 1.0f),
                    MathF.Clamp((this.WindowPos.Y - viewportRect.Y) / viewportRect.H, 0.0f, 1.0f));

                this.ViewPos = relativePos * gameViewSize;
            }
Example #21
0
        void ICmpUpdatable.OnUpdate()
        {
            Transform transform = this.GameObj.Transform;
            Camera    camera    = this.GameObj.GetComponent <Camera>();

            transform.Pos   -= this.screenShakeOffset;
            transform.Angle -= this.screenShakeAngle;

            Vector3 focusPos  = this.targetObj.Transform.Pos;
            Vector3 targetPos = focusPos - new Vector3(0.0f, 0.0f, camera.FocusDist / MathF.Max(this.zoomLevel, 0.01f)) * (1.0f + this.extraDist);

            this.extraDist = MathF.Max(0.0f, this.extraDist - Time.TimeMult * Time.SPFMult * 0.15f);
            this.extraDist = MathF.Max(this.extraDist, MathF.Clamp((focusPos.Xy - transform.Pos.Xy).Length / 500.0f, 0.0f, 1.0f));

            Vector3 posDiff        = (targetPos - transform.Pos);
            Vector3 targetVelocity = posDiff * 0.1f * MathF.Pow(2.0f, -this.smoothness);

            transform.MoveByAbs(targetVelocity * Time.TimeMult);

            this.screenShakeOffset = this.screenShake * MathF.Rnd.NextVector3(75.0f);
            this.screenShakeAngle  = this.screenShake * 0.2f * MathF.Rnd.NextFloat(-1.0f, 1.0f);
            this.screenShake      += (0.0f - this.screenShake) * 0.075f * Time.TimeMult;
            if (this.screenShake < 0.01f)
            {
                this.screenShake = 0.0f;
            }

            transform.Pos   += this.screenShakeOffset;
            transform.Angle += this.screenShakeAngle;
        }
Example #22
0
        void ICmpUpdatable.OnUpdate()
        {
            ParticleEffect effect = this.GameObj.GetComponent <ParticleEffect>();

            bool      isActive      = this.teamColor != ColorRgba.White;
            ColorHsva teamColorHsva = this.teamColor.ToHsva();

            foreach (ParticleEmitter emitter in effect.Emitters)
            {
                float spawnAlpha = 1.0f - MathF.Clamp(this.spawnTimer / 5.0f, 0.0f, 1.0f);
                float alpha      = 0.25f + 0.75f * (isActive ? spawnAlpha : 0.0f);
                emitter.MinColor = this.teamColor.WithAlpha(alpha).ToHsva();
                emitter.MaxColor = this.teamColor.WithAlpha(alpha).ToHsva();
            }

            this.spawnTimer -= Time.SPFMult * Time.TimeMult;
            if (this.spawnTimer <= 0.0f)
            {
                if (isActive)
                {
                    this.Spawn();
                }
                this.spawnTimer += this.spawnDelay;
            }
        }
Example #23
0
        private void HurtCharacters()
        {
            float            radius     = 20.0f;
            Vector2          basePos    = this.GameObj.Transform.Pos.Xy;
            Vector2          size       = Vector2.One * radius * 2.0f;
            List <RigidBody> nearBodies = RigidBody.QueryRectGlobal(basePos - 0.5f * size, size);

            float energyFactor = MathF.Clamp(this.Energy / 200.0f, 0.0f, 3.0f);

            foreach (RigidBody body in nearBodies)
            {
                Transform transform = body.GameObj.Transform;
                Character character = body.GameObj.GetComponent <Character>();
                if (character == null)
                {
                    continue;
                }

                float distance = (transform.Pos.Xy - basePos).Length;
                if (distance > radius)
                {
                    continue;
                }

                character.DoDamage(energyFactor * 0.1f * Time.TimeMult);
            }
        }
Example #24
0
        void ICmpUpdatable.OnUpdate()
        {
            Transform transform = this.GameObj.Transform;

            this.mana            = MathF.Clamp(this.mana + Time.TimeMult * 0.01f, 0.0f, 100.0f);
            this.health          = MathF.Clamp(this.health + Time.TimeMult * 0.001f, 0.0f, 100.0f);
            this.damageReaction -= MathF.Clamp(this.damageReaction * Time.TimeMult * 0.1f, 0.0f, 1.0f);

            if (this.damageReaction > 0.005f && this.painSound != null)
            {
                if (this.damageSound == null)
                {
                    this.damageSound = DualityApp.Sound.PlaySound3D(this.painSound, this.GameObj);
                }
                this.damageSound.Volume = MathF.Clamp(0.05f + this.damageReaction, 0.0f, 1.0f);
            }
            else
            {
                if (this.damageSound != null)
                {
                    this.damageSound.FadeOut(0.5f);
                }
            }
            if (this.damageSound != null && this.damageSound.Disposed)
            {
                this.damageSound = null;
            }
        }
Example #25
0
        /// <summary>
        /// Transforms regular AutoTile input data into an output format that is optimized for
        /// efficient reading and updating operations.
        /// </summary>
        /// <param name="autoTileIndex"></param>
        /// <param name="autoTileInput"></param>
        /// <param name="tileData"></param>
        /// <param name="sourceTileCount"></param>
        /// <returns></returns>
        private TilesetAutoTileInfo TransformAutoTileData(int autoTileIndex, TilesetAutoTileInput autoTileInput, RawList <TileInfo> tileData, int sourceTileCount)
        {
            int[] stateToTileMap = new int[(int)TileConnection.All + 1];
            TilesetAutoTileItem[] autoTileInfo = new TilesetAutoTileItem[sourceTileCount];
            int baseTile = MathF.Clamp(autoTileInput.BaseTileIndex, 0, sourceTileCount - 1);

            // Initialize the tile mapping for all potential connection states with the base tile
            for (int conIndex = 0; conIndex < stateToTileMap.Length; conIndex++)
            {
                stateToTileMap[conIndex] = baseTile;
            }

            // Use the directly applicable tile mapping as-is
            int autoTileSourceTileCount = MathF.Min(autoTileInput.TileInput.Count, sourceTileCount);

            bool[] isStateAvailable = new bool[stateToTileMap.Length + 1];
            for (int tileIndex = autoTileSourceTileCount - 1; tileIndex >= 0; tileIndex--)
            {
                TilesetAutoTileItem tileInput = autoTileInput.TileInput[tileIndex];
                autoTileInfo[tileIndex] = tileInput;

                if (tileInput.IsAutoTile)
                {
                    isStateAvailable[(int)tileInput.Neighbours] = true;
                    stateToTileMap[(int)tileInput.Neighbours]   = tileIndex;
                    autoTileInfo[tileIndex].ConnectsToAutoTile  = true;

                    // Apply base tile information to the main tile dataset
                    tileData.Count = Math.Max(tileData.Count, tileIndex + 1);
                    tileData.Data[tileIndex].AutoTileLayer = autoTileIndex + 1;
                }
            }

            // Fill up unavailable state mappings with the closest available match
            for (int stateIndex = 0; stateIndex < isStateAvailable.Length; stateIndex++)
            {
                if (isStateAvailable[stateIndex])
                {
                    continue;
                }

                IReadOnlyList <TileConnection> fallbacks = AutoTileFallbackMap.GetFallback((TileConnection)stateIndex);
                for (int i = 0; i < fallbacks.Count; i++)
                {
                    int fallbackStateIndex = (int)fallbacks[i];
                    if (isStateAvailable[fallbackStateIndex])
                    {
                        stateToTileMap[stateIndex] = stateToTileMap[fallbackStateIndex];
                        break;
                    }
                }
            }

            // Add the complete AutoTile info / mapping to the result data
            return(new TilesetAutoTileInfo(
                       baseTile,
                       stateToTileMap,
                       autoTileInfo));
        }
Example #26
0
        void ICmpUpdatable.OnUpdate()
        {
            this.fadeValue += 0.5f * Time.SPFMult * Time.TimeMult;

            SpriteRenderer sprite = this.GameObj.GetComponent <SpriteRenderer>();

            sprite.ColorTint = ColorRgba.White.WithAlpha(MathF.Clamp(this.fadeValue, 0.0f, 1.0f));
        }
Example #27
0
        public Point2 ToGrid(float worldX, float worldY)
        {
            var position = ToLocal(worldX, worldY);
            var x        = PathfindaxMathF.RoundToInt(MathF.Clamp(position.X, 0, GridSize.X - 1));
            var y        = PathfindaxMathF.RoundToInt(MathF.Clamp(position.Y, 0, GridSize.Y - 1));

            return(new Point2(x, y));
        }
Example #28
0
 public static ColorRgba ToColor(this Vector4 vec)
 {
     return(new ColorRgba(
                (byte)MathF.Clamp(vec.X * 255.0f, 0.0f, 255.0f),
                (byte)MathF.Clamp(vec.Y * 255.0f, 0.0f, 255.0f),
                (byte)MathF.Clamp(vec.Z * 255.0f, 0.0f, 255.0f),
                (byte)MathF.Clamp(vec.W * 255.0f, 0.0f, 255.0f)));
 }
Example #29
0
 /// <summary>
 /// Scales a color by the specified factor. This affects color and alpha equally.
 /// </summary>
 /// <param name="left">The color that is to be scaled.</param>
 /// <param name="right">The scaling factor.</param>
 /// <param name="result"></param>
 public static void Scale(ref ColorRgba left, float right, out ColorRgba result)
 {
     result = new ColorRgba(
         (byte)MathF.Clamp(MathF.Round(left.R * right), 0.0f, 255.0f),
         (byte)MathF.Clamp(MathF.Round(left.G * right), 0.0f, 255.0f),
         (byte)MathF.Clamp(MathF.Round(left.B * right), 0.0f, 255.0f),
         (byte)MathF.Clamp(MathF.Round(left.A * right), 0.0f, 255.0f));
 }
        private float GetShieldStrength(ItemObject item)
        {
            var   weaponData = item.PrimaryWeapon;
            float tierf      = (float)((weaponData.MaxDataValue + 3.0 * weaponData.BodyArmor + weaponData.ThrustSpeed) / (6.0 + weaponData.Item.Weight) * 0.13 - 3.0);

            tierf = MathF.Clamp(tierf, 0, 10);
            return((tierf * 0.2f + 0.8f) * 0.25f);
        }