Example #1
0
        // Constructors a new player.
        public Player(Level level, Vector2 position)
        {
            this.level = level;
            this.showStats = true;
            this.inSudo3D = level.inSudo3D();

            hasGun = false;

            this.carRaceMode = level.inCarRaceMode();
            if (carRaceMode)
            {
                inVehicle = true;
                currVehicle = Vehicle.Car;
                inAutomaticVehicle = true;
                automaticVehicleRight = true;
                automaticVehicleSpeed = NormalVehicleSpeed;
            }

            this.automaticRun = level.inRunningMode();
            if (automaticRun)
            {
                automaticRunRight = true;
                automaticRunSpeed = NormalRunSpeed;
                this.playerHealth = playerMaxHealth;
            }

            sniperMode = level.inSniperMode();
            if (level.LevelIndex == 10)
                AssignAutomaticJumpPoints();
            LoadContent();

            Reset(position);
        }
Example #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();
        }