private void CheckCollisions(Projectile projectile, GsPolygon projectilePolygon, UpdateParams uparams)
        {
            // if the projectile parent is null, then don't worry about it
            if (projectile.Parent == null)
            {
                return;
            }

            // cycle through all of the entities
            for (int i = mInvaders.Count - 1; i > -1; --i)
            {
                // get the entity
                Invader invader = mInvaders[i];

                // if this invader isn't the type of invader that the projectile can hit, then keep going
                if (!projectile.CanHit(invader))
                {
                    continue;
                }

                // get the entity polygon
                GsPolygon entityPolygon = invader.GetHull(uparams.Offset);

                // let the entity and polygon know they were attacked
                if (entityPolygon.IntersectsWith(projectilePolygon))
                {
                    // let the projectile know it collided
                    projectile.OnCollidedWithInvader(invader);

                    // let the entity know it was attacked
                    invader.OnAttackedByProjectile(projectile);
                }
            }
        }
Exemple #2
0
 /// <summary>
 ///
 /// </summary>
 public Sprite()
 {
     Orientation    = 0f;
     Bounds         = GsRectangle.Empty;
     previousBounds = Bounds;
     hullCache      = null;
     VelocityFactor = GsVector.One;
     Origin         = GsVector.Zero;
 }
Exemple #3
0
 /// <summary></summary>
 public GsPolygon GetHull(GsVector offset)
 {
     GsVector[] polygon = GetImageHull();
     if (hullCache == null || Bounds != previousBounds)
     {
         GsMatrix transform = CreateTransform(GetTextureDrawData(offset));
         hullCache      = new GsPolygon(polygon, transform);
         previousBounds = Bounds;
     }
     return(hullCache);
 }
        private void DrawProjectiles(DrawParams dparams)
        {
            foreach (Projectile projectile in mProjectiles)
            {
                switch (dparams.FillMode)
                {
                case GridFillMode.Polygons:
                {
                    GsPolygon hull = projectile.GetHull(dparams.Offset);
                    dparams.Graphics.DrawPolygon(GsColor.Red, hull.Points);
                    break;
                }

                case GridFillMode.Solid:
                {
                    projectile.Draw(dparams);
                    break;
                }
                }
            }
        }
        private void DrawInvaders(DrawParams dparams)
        {
            foreach (Invader invader in mInvaders)
            {
                switch (dparams.FillMode)
                {
                case GridFillMode.Polygons:
                {
                    GsPolygon hull = invader.GetHull(dparams.Offset);
                    dparams.Graphics.DrawPolygon(GsColor.Yellow, hull.Points);
                    break;
                }

                case GridFillMode.Solid:
                {
                    invader.Draw(dparams);
                    break;
                }
                }
            }
        }
        private void UpdateProjectiles(UpdateParams uparams)
        {
            float dx = CellWidth * 2f;
            float dy = CellHeight * 2f;

            GsRectangle viewport = new GsRectangle(X - dx, Y - dy, Width + dx, Height + dy);

            for (int i = mProjectiles.Count - 1; i > -1; --i)
            {
                // get the projectile
                Projectile projectile = mProjectiles[i];

                // update the projectile data
                projectile.Update(uparams.Elapsed);

                // get the polygon data
                GsPolygon polygon = projectile.GetHull(uparams.Offset);

                // if the projectile is still alive, check to see if it went out of bounds
                if (projectile.IsAlive)
                {
                    bool projectileIntersectsWithBounds = viewport.IntersectsWith(projectile.Bounds);
                    bool projectileInsideBounds         = viewport.Contains(projectile.Bounds);
                    projectile.IsAlive = projectile.StayAlive || (projectileInsideBounds || projectileIntersectsWithBounds);
                }

                // if the projectile is still alive, check to see if it hit anything
                if (projectile.IsAlive)
                {
                    CheckCollisions(projectile, polygon, uparams);
                }

                // if the projectile is dead, then remove it from the list
                if (!projectile.IsAlive)
                {
                    mProjectiles.RemoveAt(i);
                    OnProjectileRemoved(projectile);
                }
            }
        }
        private void DrawPieces(DrawParams dparams)
        {
            foreach (Piece piece in mPieces)
            {
                switch (dparams.FillMode)
                {
                case GridFillMode.Polygons:
                {
                    GsPolygon hull = piece.GetHull(dparams.Offset);
                    dparams.Graphics.DrawPolygon(GsColor.Blue, hull.Points);
                    break;
                }

                case GridFillMode.Solid:
                {
                    piece.Draw(dparams);
                    break;
                }
                }
            }
            mSelection.Draw(dparams);
        }