コード例 #1
0
        /*
        public static bool overlaps(this Character ch, Character ch2)
        {
            // Convert ch  => pointarray
            // Convert ch2 => pointarray

            //Dictionary<int, int> ch1Points = new Dictionary<int, int>();
            if (ch is StoryCharacter && ch2 is StoryCharacter)
            {
                double requiredDistance = ch.Size / 2 + ch2.Size / 2;
                requiredDistance++;

                // check if radius of both circles are in reach
                if (Math.Abs(ch.origin()[0] - ch2.origin()[0]) > requiredDistance && Math.Abs(ch.origin()[1] - ch2.origin()[1]) > requiredDistance) {
                    return true;
                }
            }
            return false;
        }
        */
        public static bool overlapsCircle(this Character ch, Character ch2)
        {
            double requiredDistance = ch.Size / 2 + ch2.Size / 2;
            requiredDistance++;

            // check if radius of both circles are in reach
            if (Math.Abs(ch.origin().X - ch2.origin().X) < requiredDistance && Math.Abs(ch.origin().Y - ch2.origin().Y) < requiredDistance)
            {
                //Debug.WriteLine("Point 1: {0}:{1}, Point 2: {2}:{3} -- {4}", ch.origin().X, ch.origin().Y, ch2.origin().X, ch2.origin().Y, requiredDistance);
                return true;
            }

            return false;
        }
コード例 #2
0
ファイル: Character.cs プロジェクト: BilelAvans/BallDrive
        // Rects
        public bool collidesWith(Character c)
        {
            if (this.Position.X < c.Position.X + c.Size &&
                    this.Position.X + this.Size > c.Position.X &&
                    this.Position.Y < c.Position.Y + c.Size &&
                    this.Size + this.Position.Y > c.Position.Y
            )
                return true;

            return false;
        }
コード例 #3
0
        public bool EnemiesHitByBullet(Character c){
            //List<Character> enemiesShot = Characters.Where(ch => ShotsFired.Exists(shot => shot.overlapsCircle(ch))).ToList();
            foreach (BulletNPC bullet in ShotsFired) {
                if (bullet.overlapsCircle(c))
                {
                    // Remove bullet when it hits a first object
                    ShotsFired.Remove(bullet);
                    // return the character
                    return true;
                }
            }

            return false;
        }