public override void OnPlayerCollision(Player player)
        {
            if (player.RecentlyDamaged)
                return;

            Rectangle collisionArea = Rectangle.Intersect(player.AABB, this.AABB);
            bool yCollision = false;
            if (collisionArea.Width > collisionArea.Height)
                yCollision = true;

            Vector2 depth = player.AABB.GetIntersectionDepth(this.AABB);
            if (yCollision)
            {
                var origin = new Vector2(AABB.Center.X, AABB.Center.Y);
                var destination = new Vector2(AABB.Center.X, AABB.Center.X + (Texture.Height / 2));
                var normal = (destination - origin);
                normal.Normalize();
                var reflected = player.Velocity - 2 * normal * (player.Velocity * normal);
                player.Velocity = reflected;
                player.Damage();
            }
            else
            {
                player.Position = new Vector2(player.Position.X + depth.X, player.Position.Y);
                player.CollidedWithSurface(true);
            }
        }
Exemplo n.º 2
0
        public void OnPlayerCollision(Player player)
        {
            if (player.AABB.Y + player.AABB.Height - 10 < AABB.Y)
            {
                Console.WriteLine("Enemy Killed!");
                this.Kill();
            }
            else
            {
                Console.WriteLine("Player Killed");
                player.Damage();
            }

            var origin = new Vector2(AABB.Center.X, AABB.Center.Y);
            var destination = new Vector2(AABB.Center.X, AABB.Center.X + (Texture.Height / 2));
            var normal = (destination - origin);
            normal.Normalize();
            var reflected = player.Velocity - 2 * normal * (player.Velocity * normal);
            player.Velocity = reflected;
        }