Exemplo n.º 1
0
        // Constructs a new Enemy.
        public Enemy(Level level, Vector2 position, string spriteSet, bool createdByEvent)
        {
            this.level = level;
            this.position = position;
            this.startPosition = position;
            this.monsterType = spriteSet;
            this.createdByEvent = createdByEvent;
            this.currMoveSpeed = EnemySpeed;
            this.bouncingBullets = false;
            this.fireVertical = false;
            this.multiDirectoinalFiring = false;
            this.enemyTurrets = new Turret[2];

            SetupEnemy();

            LoadContent(spriteSet);

            // For bosses other continously firing enemies make turrets to act as their guns
            if (isBoss)
            {
                    Vector2 turretOffset = new Vector2(BoundingRectangle.X + BoundingRectangle.Width / 2, BoundingRectangle.Y + BoundingRectangle.Height / 2);

                    // Water boss - fires 2 parallel guns
                    if (monsterType == "Boss1")
                    {
                        Vector2 upperGun = new Vector2(BoundingRectangle.X + BoundingRectangle.Width / 2, BoundingRectangle.Y + BoundingRectangle.Height * 0.25f);
                        Vector2 lowerGun = new Vector2(BoundingRectangle.X + BoundingRectangle.Width / 2, BoundingRectangle.Y + BoundingRectangle.Height * 0.75f);
                        enemyTurrets[0] = new Turret(level, upperGun, false, this, false);
                        enemyTurrets[1] = new Turret(level, lowerGun, false, this, false);
                    }

                    // Space boss - fires bouncing bullets
                    else if (monsterType == "Boss2")
                    {
                        this.bouncingBullets = true;
                        enemyTurrets[0] = new Turret(level, turretOffset, false, this, false);
                    }

                    // Witch boss - fires upwards
                    else if (monsterType == "Boss3")
                    {
                        this.fireVertical = true;
                        enemyTurrets[0] = new Turret(level, turretOffset, false, this, false);
                    }

                    // Angel boss
                    else if (monsterType == "Boss4")
                    {
                        enemyTurrets[0] = new Turret(level, turretOffset, false, this, true);
                    }

                    // Devil boss
                    else if (monsterType == "Boss5" || monsterType == "Boss5R")
                    {
                        switch (level12bossCount)
                        {
                            case 0:
                                this.bouncingBullets = true;
                                enemyTurrets[0] = new Turret(level, turretOffset, false, this, false);
                                break;
                            case 1:
                                //this.bouncingBullets = false;
                                this.fireVertical = true;
                                enemyTurrets[0] = new Turret(level, turretOffset, false, this, true);
                                break;
                            case 2:
                                this.bouncingBullets = true;
                                Vector2 upperGun = new Vector2(BoundingRectangle.X + BoundingRectangle.Width / 2, BoundingRectangle.Y + BoundingRectangle.Height * 0.25f);
                                Vector2 lowerGun = new Vector2(BoundingRectangle.X + BoundingRectangle.Width / 2, BoundingRectangle.Y + BoundingRectangle.Height * 0.75f);
                                enemyTurrets[0] = new Turret(level, upperGun, false, this, true);
                                enemyTurrets[1] = new Turret(level, lowerGun, false, this, false);
                                break;

                        }
                    }

                    // Multidirecitional firing enemies
                    else if (multiDirectoinalFiring)
                    {
                        enemyTurrets[0] = new Turret(level, turretOffset, false, this, true);
                    }

                }
        }
Exemplo n.º 2
0
        // For creating player bullets, turret bullets or continously firing enemies (implemented as turrets)
        public Bullet(Level level, Vector2 position, GameTime gameTime, Turret turret)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            float MoveVelocity = MoveAcceleration * elapsed * AirDragFactor;
            this.level = level;
            this.position = position;
            this.initialPosition = position;
            this.turret = turret;
            this.removeBullet = false;
            this.airTime = 0.0f;
            this.explodeTimer = 0.0f;

            this.playerBullet = (turret == null);
            if (level.LevelIndex == 9)
                LoadContent();

            animationPlayer.PlayAnimation(blankAnimation);

            if (playerBullet)
            {
                // This bullet is from a player

                // Set range and bullet velocity depending on weapon
                if (level.Player.powerBulletCount > 0)
                {
                    powerBullet = true;
                    MoveVelocity *= powerBulletVelocity;
                    range = powerBulletRange;
                }
                else
                {
                    if (level.Player.inVehicle)
                    {
                        switch (level.Player.currVehicle)
                        {
                            case Vehicle.Submarine:
                                MoveVelocity *= submarineGunVelocity;
                                range = harpoonRange;
                                break;
                            case Vehicle.Spaceship:
                                MoveVelocity *= spaceBlasterVelocity;
                                range = spaceBlasterRange;
                                break;
                            case Vehicle.Snowmobile:
                                MoveVelocity *= spaceBlasterVelocity;
                                range = spaceBlasterRange;
                                break;
                            case Vehicle.Car:
                                MoveVelocity *= multiDirectionalVelocity;
                                range = multiDirectionalRange;
                                break;
                            default:
                                MoveVelocity *= uziVelocity;
                                range = pistolRange;
                                break;
                        }
                    }

                    else
                    {
                        switch (Level.Player.currGun)
                        {
                            case Gun.Pistol:
                                MoveVelocity *= pistolVelocity;
                                range = pistolRange;
                                break;
                            case Gun.Uzi:
                                MoveVelocity *= uziVelocity;
                                range = uziRange;
                                break;
                            case Gun.Sniper:
                                MoveVelocity *= sniperVelocity;
                                range = sniperRange;
                                break;
                            case Gun.Harpoon:
                                if (level.Player.inVehicle)
                                    MoveVelocity *= submarineGunVelocity;
                                else
                                    MoveVelocity *= harpoonVelocity;
                                range = harpoonRange;
                                break;
                            case Gun.SpaceBlaster:
                                MoveVelocity *= spaceBlasterVelocity;
                                range = spaceBlasterRange;
                                break;
                            case Gun.Multidirectional:
                                MoveVelocity *= multiDirectionalVelocity;
                                range = multiDirectionalRange;
                                break;
                            default:
                                range = pistolRange;
                                break;
                        }
                    }
                }

                //// If there is horizontal movement or no vertical movement fire horizontally
                //if (level.Player.Velocity.X == 0 || level.Player.vertMovement == 0)
                //{
                if (level.Player.shootWithMouse)
                {
                    if (level.Player.sniperMode)
                    {
                        animationPlayer.PlayAnimation(sniperShotAnimation);
                        initialVelocityX = 0;
                        initialVelocityY = 0;

                        // Update stats
                        shotsFired++;
                    }
                    else
                    {
                        Vector2 vector = level.Player.bulletVector;
                        initialVelocityX = vector.X * MoveVelocity;
                        initialVelocityY = vector.Y * MoveVelocity;
                    }
                }

                // Drop power bullets (like bombs in level 6)
                else if (DropBomb)
                {
                    initialVelocityX = 0;
                    initialVelocityY = MoveVelocity;
                }
                else
                {
                    if (level.Player.FacingRight)
                        initialVelocityX = MoveVelocity;
                    else
                        initialVelocityX = -MoveVelocity;

                    // In sudo 3D levels can also fire up or down when moving in those directions
                    if (level.inSudo3D())
                    {
                        if (level.Player.vertMovement != 0 && level.Player.Velocity.X == 0)
                        {
                            initialVelocityX = 0;
                            bulletRotation = MathHelper.ToRadians(90);

                            if (level.Player.vertMovement > 0)
                                initialVelocityY = MoveVelocity;
                            else if (level.Player.vertMovement < 0)
                                initialVelocityY = -MoveVelocity;
                        }
                    }
                }
            }

            else
            {
                // This bullet is from a turret/enemy
                // Set range for turret
                range = turretRange;
                MoveVelocity *= turretVelocity;

                // Set direction to fire
                if (turret.multiDirectionalFire)
                {
                    // Find top-left camera position
                    int left = (int)Math.Floor(level.cameraPosition.X);
                    int top = (int)Math.Floor(level.cameraPosition.Y);
                    turret.turretVector = level.Player.Position - turret.Position;

                    // Normalize movement vector
                    if (turret.turretVector != Vector2.Zero)
                        turret.turretVector.Normalize();
                    Vector2 vector = this.turret.turretVector;
                    initialVelocityX = vector.X * MoveVelocity;
                    initialVelocityY = vector.Y * MoveVelocity;
                }
                else if (turret.currFiringDireciton == TurretFiringDirection.Right)
                    initialVelocityX = MoveVelocity;
                else
                    initialVelocityX = -MoveVelocity;

                // If bullet is from enemy and fires bouncing bullets or vertical bullets
                if (turret.enemy != null)
                {
                    if (turret.enemy.bouncingBullets)
                    {
                        bouncable = true;
                        if (turret.enemy.Velocity.Y < 0)
                            initialVelocityY = -MoveVelocity;
                        else
                            initialVelocityY = MoveVelocity;
                    }
                    else if (turret.enemy.fireVertical)
                    {
                        initialVelocityX = 0;
                        initialVelocityY = -MoveVelocity;
                        bulletRotation = MathHelper.ToRadians(270);
                    }
                }
            }

            LoadContent();
        }