Пример #1
0
 public SprinklerProjectile(Piece parent, double timeToLiveInSeconds)
     : base(parent, timeToLiveInSeconds)
 {
     Color    = GsMath.Lerp(GsColor.LightBlue, GsColor.DarkBlue, .65f);
     Size     = new GsSize(10f, 8f);
     ImageKey = "fragment";
 }
Пример #2
0
 public LightningProjectile(Piece parent, double timeToLiveInSeconds, Invader target)
     : base(parent, timeToLiveInSeconds)
 {
     mTarget  = target;
     Size     = new GsSize(48f, 12f);
     ImageKey = "lightning";
 }
Пример #3
0
 public ImageParams(GsImage image, GsSize imageSize, GsVector position, GsVector origin, GsVector scale)
 {
     Image     = image;
     ImageSize = imageSize;
     Position  = position;
     Origin    = origin;
     Scale     = scale;
 }
Пример #4
0
        public FlameProjectile(Piece parent, double timeToLiveInSeconds)
            : base(parent, timeToLiveInSeconds)
        {
            Size     = new GsSize(20f, 80f);
            ImageKey = "flame";

            var size = ImageProvider.GetSize(GetImage());

            Origin = new GsVector(0, size.Height / 2);
        }
Пример #5
0
 public DebriProjectile(Piece parent, Projectile projectile, float orientation)
     : base(parent, .3)
 {
     Velocity    = Calculator.ComputeProjectileDirection(orientation) * 100f;
     Attack      = projectile.Attack * 3f;
     Color       = GsMath.Lerp(GsColor.Yellow, GsColor.Black, .55f);
     Orientation = orientation;
     Position    = projectile.Position;
     Size        = new GsSize(3.5f, 3.5f);
     ImageKey    = "debri";
 }
Пример #6
0
        public Projectile(Piece parent, double timeToLiveInSeconds)
        {
            IsAlive     = true;
            mTimeToLive = timeToLiveInSeconds;

            ImageKey = "bullet";
            var sz = ImageProvider.GetSize(GetImage());

            Origin    = new GsVector(0, sz.Height / 2f);
            Color     = GsColor.White;
            Size      = new GsSize(20f, 6.5f);
            StayAlive = false;
            Parent    = parent;
        }
Пример #7
0
        protected override ImageParams GetTextureDrawData(GsVector offset)
        {
            var outin  = GetOutsideInsideBounds(offset);
            var bounds = outin.Outside;

            var wtower  = GetImage();
            var imgSize = ImageProvider.GetSize(wtower);
            var actSize = new GsSize(bounds.Width, bounds.Height);

            GsVector scale  = Calculator.ComputeScale(imgSize, actSize);
            GsVector origin = imgSize.ToVector() * .5f;
            GsVector center = actSize.ToVector() * .5f;

            return(new ImageParams(wtower, imgSize, bounds.Location + center, origin, scale));
        }
Пример #8
0
        public void ChooseTarget(IEnumerable <Invader> invaders, GsVector offset)
        {
            Invader     bestInvader    = null;
            float       bestFuzzyValue = 0.0f;
            float       radiusSquared  = Radius * Radius;
            GsRectangle pieceBounds    = GsRectangle.Offset(Bounds, offset);

            foreach (Invader invader in invaders)
            {
                // calculate the position. In the future, we should get this directly from the invader
                GsVector position = invader.Position + offset + (invader.Size.ToVector() * .5f);
                GsVector origin   = invader.Origin;
                GsSize   size     = invader.Size;

                // calculate the bounds
                GsRectangle invaderBounds = new GsRectangle(position - (origin * .5f), size);

                // determine the distance
                float distance = GsVector.DistanceSquared(pieceBounds.Center, invaderBounds.Center);
                if (InvalidTarget(distance, radiusSquared, invader, invaderBounds))
                {
                    continue;
                }

                // determine the fuzzy number
                float fuzzy = 0.0f;
                fuzzy += CalculateFuzzyLife(invader) * FuzzyLifeWeight;
                fuzzy += CalculateFuzzyTime(invader) * FuzzyTimeWeight;
                fuzzy += CalculateFuzzyDistance(distance) * FuzzyDistanceWeight;

                // if the fuzzy value is better, then select this invader
                if (fuzzy > bestFuzzyValue)
                {
                    bestInvader    = invader;
                    bestFuzzyValue = fuzzy;
                }
            }

            if (bestInvader == null)
            {
                Target = null;
            }
            else if (bestInvader != Target)
            {
                mTimeChasingTarget = TimeSpan.Zero;
                Target             = bestInvader;
            }
        }
Пример #9
0
        protected void FireProjectile(TimeSpan elapsed)
        {
            if (Target != null)
            {
                GsRectangle inside  = new GsRectangle(X + Pad, Y + Pad, Width - TwoPad, Height - TwoPad);
                GsSize      actSize = new GsSize(Width - Pad, inside.Height);

                GsVector myCenter = actSize.ToVector() * .5f;
                for (int i = 0; i < NumberProjectilesToFire; ++i)
                {
                    Projectile projectile = CreateProjectile();
                    projectile.Velocity    = Velocity * ProjectileSpeed;
                    projectile.Position    = inside.Location + myCenter;
                    projectile.Orientation = Orientation;
                    projectile.Attack      = Attack;
                    projectile.UpdateByFrameCount(elapsed, i * NumberProjectilesToFire);
                    mQueuedProjectiles.Add(projectile);
                }
            }
        }
Пример #10
0
        public TeslaCoilPiece()
        {
            // setup the description
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Fires a charged burst of electricity. The burst is very effective against ground units.");

            // set the properties needed
            Attack          = 9000;
            Price           = 2500;
            Radius          = 250;
            UpgradePercent  = 45;
            LevelVisibility = 75;

            Description             = sb.ToString();
            ProjectileLifeInSeconds = 6.7f;
            CanFireProjectiles      = false;
            Name         = TeslaCoilName;
            UltimateName = UltimateTeslaCoilName;
            Grouping     = PieceGrouping.Three;
            ImageKey     = "teslaCoil";
            Element      = Element.Electricity;
            Specialty    = PieceSpecialty.Both;

            // set the properties of the piece
            mIndex = 0;
            mAggregateTimeSinceUpdate = 0;
            mTeslaState = TeslaState.Idle;
            Color       = GsColor.White;

            // get the image
            var image     = GetImage();
            var imageSize = ImageProvider.GetSize(image);

            FrameSize      = new GsSize(imageSize.Width / (NumberIndexFrames + 1), imageSize.Height);
            LightningColor = GsMath.Lerp(GsColor.Purple, GsColor.DarkBlue, .5f);
            LightningColor = GsMath.Lerp(LightningColor, GsColor.Red, .75f);
        }
Пример #11
0
        private void DrawSprite(TextureData data, GsRectangle dst, GsRectangle?source, GsVector origin, float rotation, GsImageFlip flip, GsColor color)
        {
            if (color.A <= 0)
            {
                return;
            }

            GsSize      texSize = new GsSize(data.Bitmap.Width, data.Bitmap.Height);
            GsRectangle src     = source.GetValueOrDefault(
                new GsRectangle(GsVector.Zero, texSize));

            using (data.Bind())
            {
                GL.Color4(color.R, color.G, color.B, color.A);

                // Setup the matrix
                GL.PushMatrix();
                if ((dst.X != 0) || (dst.Y != 0))
                {
                    GL.Translate(dst.X, dst.Y, 0f);
                }

                if (rotation != 0)
                {
                    GL.Rotate(MathHelper.RadiansToDegrees(rotation), 0, 0, 1);
                }

                if ((dst.Width != 0 && origin.X != 0) || (dst.Height != 0 && origin.Y != 0))
                {
                    GL.Translate(
                        -origin.X * (float)dst.Width / (float)src.Width,
                        -origin.Y * (float)dst.Height / (float)src.Height, 0f);
                }

                // Calculate the points on the texture
                float x       = src.X / texSize.Width;
                float y       = src.Y / texSize.Height;
                float twidth  = src.Width / texSize.Width;
                float theight = src.Height / texSize.Height;

                Vector2[] tx = new Vector2[]
                {
                    new Vector2(x, y + theight),
                    new Vector2(x + twidth, y + theight),
                    new Vector2(x + twidth, y),
                    new Vector2(x, y),
                };

                var tcs = texCoords[flip];
                int t   = 0;

                GL.Begin(PrimitiveType.Quads);

                GL.TexCoord2(tx[tcs[t++]]);
                GL.Vertex2(0f, dst.Height);

                GL.TexCoord2(tx[tcs[t++]]);
                GL.Vertex2(dst.Width, dst.Height);

                GL.TexCoord2(tx[tcs[t++]]);
                GL.Vertex2(dst.Width, 0f);

                GL.TexCoord2(tx[tcs[t++]]);
                GL.Vertex2(0f, 0f);

                GL.End();
                GL.PopMatrix();
            }
        }
Пример #12
0
 public static GsVector ComputeScale(GsSize originalSize, GsSize desiredSize)
 {
     return(ComputeScale(originalSize.Width, originalSize.Height, desiredSize.Width, desiredSize.Height));
 }
Пример #13
0
 public static void FillEllipse(this IGsGraphics graphics, GsColor color, GsVector loc, GsSize size)
 {
     graphics.FillEllipse(color, loc.X, loc.Y, size.Width, size.Height);
 }
Пример #14
0
 public BulletProjectile(Piece parent, double timeToLiveInSeconds)
     : base(parent, timeToLiveInSeconds)
 {
     Size     = new GsSize(6f, 2f);
     ImageKey = "bullet";
 }
Пример #15
0
 protected void UpdateScaleAndOrientation(float elapsedSeconds)
 {
     mScale      += elapsedSeconds * ScalesPerSecond;
     Orientation += elapsedSeconds * RotationsPerSecond;
     Size         = new GsSize(mOwnerBounds.Width * mScale, mOwnerBounds.Height * mScale);
 }