コード例 #1
0
ファイル: Collider.cs プロジェクト: daithyy/Games-Fleadh
        private void UpdateCollisions()
        {
            sentries          = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));
            player            = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
            playerProjectile  = (Projectile)Game.Services.GetService(typeof(Projectile));
            projectile        = (Ricochet)Game.Services.GetService(typeof(Ricochet));
            sentryProjectiles = (List <Projectile>)Game.Services.GetService(typeof(List <Projectile>));

            CollideWithProjectile(playerProjectile);
            CollideWithProjectile(projectile);
            CollideWithTank(player);

            for (int i = 0; i < sentries.Count; i++)
            {
                if (!sentries[i].IsDead)
                {
                    CollideWithTank(sentries[i]);
                }
            }

            for (int i = 0; i < sentryProjectiles.Count; i++)
            {
                CollideWithProjectile(sentryProjectiles[i]);
            }
        }
コード例 #2
0
ファイル: Collider.cs プロジェクト: daithyy/Games-Fleadh
        private void MinkowskiSum(Ricochet obj)
        {
            w  = 0.5f * (obj.BoundingRectangle.Width + CollisionField.Width);
            h  = 0.5f * (obj.BoundingRectangle.Height + CollisionField.Height);
            dx = obj.BoundingRectangle.Center.X - CollisionField.Center.X;
            dy = obj.BoundingRectangle.Center.Y - CollisionField.Center.Y;

            if (Math.Abs(dx) <= w && Math.Abs(dy) <= h)
            {
                /* collision! */
                wy = w * dy;
                hx = h * dx;

                if (wy > hx)
                {
                    if (wy > -hx)
                    {
                        /* collision at the top */
                        obj.Direction.Y = -obj.Direction.Y;
                        return;
                    }
                    else
                    {
                        /* on the left */
                        obj.Direction.X = -obj.Direction.X;
                        obj.Scale       = -obj.Scale;
                        return;
                    }
                }
                else
                {
                    if (wy > -hx)
                    {
                        /* on the right */
                        obj.Direction.X = -obj.Direction.X;
                        obj.Scale       = -obj.Scale;
                        return;
                    }
                    else
                    {
                        /* at the bottom */
                        obj.Direction.Y = -obj.Direction.Y;
                        return;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Collider.cs プロジェクト: daithyy/Games-Fleadh
        private void CollideWithProjectile(Ricochet obj)
        {
            if (obj != null && obj.ProjectileState != Projectile.PROJECTILE_STATUS.Idle)
            {
                projectileBounds = new Rectangle(
                    new Point(
                        (int)obj.CentrePos.X - (obj.ProjectileWidth),
                        (int)obj.CentrePos.Y),
                    new Point(obj.ProjectileWidth, obj.ProjectileHeight));

                if (projectileBounds.Intersects(CollisionField))
                {
                    obj.PixelPosition   = obj.PreviousPosition;
                    obj.angleOfRotation = -obj.angleOfRotation;
                    MinkowskiSum(obj);
                }
            }
        }