コード例 #1
0
ファイル: Hitbox.cs プロジェクト: joeecarter/Asteroids
 //Collision between two circles
 public static bool Collision(CircleHitbox circle1, CircleHitbox circle2)
 {
     if (circle1.Position.EuclideanDistance(circle2.Position) < (circle1.Radius + circle2.Radius))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
コード例 #2
0
ファイル: Hitbox.cs プロジェクト: joeecarter/Asteroids
        //Collision between a polygon and a circle
        public static bool Collision(CircleHitbox circle, PolygonHitbox polygon)
        {
            bool value = false;
            foreach (Vector2 vector in polygon.Vectors)
            {
                if (circle.Contains(vector))
                {
                    value = true;
                    break;
                }
            }

            return value;
        }
コード例 #3
0
ファイル: Bullet.cs プロジェクト: joeecarter/Asteroids
        public Bullet(InGameState Game, Vector2 position, Vector2 direction , double startTime)
            : base(Game, null, position)
        {
            //we dont want bullets to loop around the screen when then go off the screen
            Loop = false;

            //we set the initial velocity which never lowers as theres no friction
            Velocity = direction * BulletSpeed;

            //set the start time so we cna kill off the bullet after an interval
            this.startTime = startTime;

            //Create a collision shape for the bullet
            hitbox = new CircleHitbox(this, 2);
        }
コード例 #4
0
ファイル: Asteroid.cs プロジェクト: joeecarter/Asteroids
        public Asteroid(InGameState Game, Vector2 StartPosition, AsteroidSize size)
            : base(Game, new LineModel(AsteroidLarge1Vectors), StartPosition)
        {
            this.size = size;
            Velocity = Vector2.RandomVector2(new Vector2(-50, -50), new Vector2(50, 50)).Normalise() * 2;

            switch (size)
            {
                case AsteroidSize.Large:
                    this.Model.Scale = 1;
                    break;
                case AsteroidSize.Medium:
                    this.Model.Scale = 0.5;
                    break;
                case AsteroidSize.Small:
                    this.Model.Scale = 0.35;
                    break;
            }

            hitbox = new CircleHitbox(this, Model.GetRadius());
        }
コード例 #5
0
ファイル: Asteroid.cs プロジェクト: joeecarter/Asteroids
        public Asteroid(InGameState Game, Vector2 StartPosition, Vector2 velocity, AsteroidSize size)
            : base(Game, new LineModel(AsteroidLarge1Vectors), StartPosition)
        {
            this.size = size;
            Velocity = velocity;

            switch (size)
            {
                case AsteroidSize.Large:
                    this.Model.Scale = 1;
                    break;
                case AsteroidSize.Medium:
                    this.Model.Scale = 0.5;
                    break;
                case AsteroidSize.Small:
                    this.Model.Scale = 0.35;
                    break;
            }

            hitbox = new CircleHitbox(this, Model.GetRadius());
        }