Example #1
0
        public static bool IsPlayerInSight(Enemy enemy, Player.Player player, GameWorld gameWorld, out List<Rectangle> rects)
        {
            Rectangle rect = new Rectangle(enemy.GetCollRectangle().Center.X, enemy.GetCollRectangle().Center.Y, 1, 1);
            rects = new List<Rectangle>();

            double xVector = (double)(player.GetCollRectangle().Center.X - rect.Center.X);
            double yVector = (double)(player.GetCollRectangle().Center.Y - rect.Center.Y);

            Vector2 maxVelocity = new Vector2(30, 30);
            double magnitude = Math.Sqrt((Math.Pow(xVector, 2.0)) + (Math.Pow(yVector, 2.0)));
            Vector2 newVelocity = new Vector2(maxVelocity.X * (float)(xVector / magnitude), maxVelocity.Y * (float)(yVector / magnitude));

            for (int i = 0; i < 10; i++)
            {
                rects.Add(rect);

                int index = (int)(rect.Y / Main.Tilesize * gameWorld.WorldData.LevelWidth) + (int)(rect.X / Main.Tilesize);

                if (rect.Intersects(player.GetCollRectangle()))
                    return true;
                if (index > GameWorld.Instance.TileArray.Length - 1 || index < 0)
                    return false;
                if (gameWorld.TileArray[index].IsSolid)
                    return false;

                rect.X += (int)newVelocity.X;
                rect.Y += (int)newVelocity.Y;
            }
            return false;
        }
Example #2
0
        /// <summary>
        /// Creates new food based on enemy killed.
        /// </summary>
        /// <param name="enemy"></param>
        public Food(Enemy enemy)
        {
            CollRectangle = new Rectangle(enemy.GetCollRectangle().X, enemy.GetCollRectangle().Y, 32, 32);
            Velocity.Y = -10f;

            _hitGround = new SoundFx("Sounds/Items/item_pop", this);
            _pickUpSound = ContentHelper.LoadSound("Player/eatSound");

            switch (enemy.Id)
            {
                case 201: // Snake
                    _healAmount = 10;
                    Texture = ContentHelper.LoadTexture("Objects/Food/snake_chest_v1");
                    break;
                case 202: // Frog
                    _healAmount = 5;
                    Texture = ContentHelper.LoadTexture("Objects/Food/frog_leg_v2");
                    break;
                case 204: // Lost
                    _healAmount = 10;
                    break;
                case 205: // Hellboar
                    _healAmount = 40;
                    break;
                case 207: // Bat
                    _healAmount = 10;
                    break;
                case 208: // Duck
                    _healAmount = 5;
                    break;
                case 209: // Being of Sight
                    _healAmount = 30;
                    break;
                default:
                    break;
            }

            OnPlayerPickUp += Food_OnPlayerPickUp;
            CollidedWithTileBelow += OnCollisionWithTerrainBelow;
        }
Example #3
0
        public ParabolicProjectile(Enemy enemy, GameWorld map, ProjectileSource currentProjectileSource)
        {
            this.CurrentProjectileSource = currentProjectileSource;
            this.Enemy = enemy;

            switch (currentProjectileSource)
            {
                case ProjectileSource.Snake:
                    Texture = ContentHelper.LoadTexture("Projectiles/venom_dark");
                    CollRectangle = new Rectangle(enemy.GetCollRectangle().X, enemy.GetCollRectangle().Y, 32, 32);
                   // animation = new Animation(Texture, collRectangle, 200, 0, AnimationType.Loop);
                    if (!enemy.IsFacingRight)
                    {
                        Velocity = new Vector2(-10, -15);
                        //animation.isFlipped = true;
                    }
                    else Velocity = new Vector2(10, -15);
                    break;
            }
        }
Example #4
0
 public void CreateEnemyDisintegrationEffect(Enemy enemy, Rectangle sourceRectangle, Projectile proj)
 {
     CurrentParticle = ParticleType.EnemyDesintegration;
     Texture = enemy.Texture;
     CollRectangle = new Rectangle(enemy.GetCollRectangle().X + sourceRectangle.X, enemy.GetCollRectangle().Y + sourceRectangle.Y,
         sourceRectangle.Width, sourceRectangle.Height);
     this.SourceRectangle = sourceRectangle;
     int maxTanSpeed = 10;
     Velocity.X = (float)(GameWorld.RandGen.Next((int)(proj.GetVelocity().X - maxTanSpeed), (int)(proj.GetVelocity().X + maxTanSpeed + 1)));
     Velocity.Y = (float)(GameWorld.RandGen.Next((int)(proj.GetVelocity().Y - maxTanSpeed), (int)(proj.GetVelocity().Y + maxTanSpeed + 1)));
 }
Example #5
0
 public void CreateEnemyDeathEffect(Enemy enemy, Rectangle sourceRectangle)
 {
     CurrentParticle = ParticleType.EnemyDesintegration;
     Texture = enemy.Texture;
     CollRectangle = new Rectangle(enemy.GetCollRectangle().X + sourceRectangle.X, enemy.GetCollRectangle().Y + sourceRectangle.Y,
         sourceRectangle.Width, sourceRectangle.Height);
     this.SourceRectangle = sourceRectangle;
     int maxTanSpeed = 5;
     Velocity = new Vector2(GameWorld.RandGen.Next(-maxTanSpeed, maxTanSpeed), GameWorld.RandGen.Next(-maxTanSpeed, maxTanSpeed));
 }
Example #6
0
        public Particle(Enemy enemy, Projectile projectile)
        {
            SourceRectangle = new Rectangle(0, 0, 32, 32);
            CurrentParticle = ParticleType.Impact;
            Texture = ContentHelper.LoadTexture("Explosion");

            if (projectile.GetVelocity().X > 0)
                CollRectangle = new Rectangle(enemy.GetCollRectangle().X - enemy.GetCollRectangle().Width / 2, projectile.GetCollRectangle().Center.Y - SourceRectangle.Height / 2, 32, 32);
            else CollRectangle = new Rectangle(enemy.GetCollRectangle().X + enemy.GetCollRectangle().Width / 2, projectile.GetCollRectangle().Center.Y - SourceRectangle.Height / 2, 32, 32);
            _frameCount = new Vector2(Texture.Width / 32, Texture.Height / 32);
        }