Beispiel #1
0
        public void Fire(Vector currentPosition, Vector playerPosition)
        {
            Bullet bullet = new Bullet(_bulletTexture);

            bullet.Speed = 350;

            Vector bulletDir = playerPosition - currentPosition;

            bulletDir        = bulletDir.Normalize(bulletDir);
            bullet.Direction = bulletDir;
            bullet.SetPosition(currentPosition);
            bullet.SetColor(new Color(0, 1, 1, 1));
            _bulletManager.EnemyShoot(bullet);

            RestartShootCountDown();
        }
Beispiel #2
0
        public override void Update(GameTime gameTime, CollisionManager cb)
        {
            cb.UdateObjectPositionWithFunction(this, () =>
            {
                if (!this.isDead)
                {
                    if (this.BoundsContains(Player.Instance) || Player.Instance.BoundsContains(this))
                    {
                        Player.Instance.TakeDamage(1);
                        this.TakeDamage(1);
                    }

                    //Now handle movement. First check if they have movement, then oscillation, then all other cases
                    if (this.movementPattern == MovementPattern.None)
                    {
                        //Shoot
                        if (this.Shoot())
                        {
                            bulletManager.EnemyShoot(this.enemyType);
                        }
                    }
                    else if (this.movementPattern == MovementPattern.Oscillate)
                    {
                        OscillateMovement move = new OscillateMovement(movement.CurrentPosition(), (float)this.velocity);

                        //First check if the object has hit the window. Flip direction if it did
                        if (position.X > GameConfig.Height)
                        {
                            //Move enemy to next point
                            position = move.NextOscillatedPoint(true); //pass it true so it switches directions
                            //Shoot
                            if (this.Shoot())
                            {
                                bulletManager.EnemyShoot(this.enemyType);
                            }
                        }
                        else
                        {
                            //Move enemy to next point
                            position = move.NextOscillatedPoint(false);
                            //Shoot
                            if (this.Shoot())
                            {
                                bulletManager.EnemyShoot(this.enemyType);
                            }
                        }
                    }
                    else
                    {
                        //Move Enemy to new position in its set path
                        position = movement.NextPoint();
                        // enemy went off screen without dying, so destroy it
                        if (position.Y > GameConfig.Height)
                        {
                            this.IsDead = true;
                            movement.Reset();
                        }
                        else
                        {
                            //Shoot
                            if (this.Shoot())
                            {
                                bulletManager.EnemyShoot(this.enemyType);
                            }
                        }
                    }
                }
                base.Update(gameTime, cb);
                return(true);
            });
        }