Example #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            inputCommandManager = new CommandManager();

            collisionManager = new CollisionManager();

            fsmMenus = new FSM(this);

            loader = new Loader();

            // Different Game States
            MainMenuState mainMenuState = new MainMenuState();
            GameplayState gameplayState = new GameplayState();
            GameOverState gameOverState = new GameOverState();
            VictoryState  victoryState  = new VictoryState();

            // Adding appropriate transitions to each state
            mainMenuState.AddTransition(new Transition(gameplayState, () => currentMenu == Menu.Gameplay));

            gameplayState.AddTransition(new Transition(mainMenuState, () => currentMenu == Menu.MainMenu));
            gameplayState.AddTransition(new Transition(gameOverState, () => currentMenu == Menu.GameOver));
            gameplayState.AddTransition(new Transition(victoryState, () => currentMenu == Menu.Victory));

            gameOverState.AddTransition(new Transition(mainMenuState, () => currentMenu == Menu.MainMenu));
            gameOverState.AddTransition(new Transition(gameplayState, () => currentMenu == Menu.Gameplay));

            victoryState.AddTransition(new Transition(mainMenuState, () => currentMenu == Menu.MainMenu));
            victoryState.AddTransition(new Transition(gameplayState, () => currentMenu == Menu.Gameplay));

            // Add all the states to the FSM
            fsmMenus.AddState(mainMenuState);
            fsmMenus.AddState(gameplayState);
            fsmMenus.AddState(gameOverState);
            fsmMenus.AddState(victoryState);

            fsmMenus.Initialise("MainMenu");
            currentMenu = Menu.MainMenu;

            player = new Player(Services);

            healthPickup = new Pickup(Services);
            magicPickup  = new Pickup(Services);

            ground = new Platform(Services);

            TutorialTexts = new List <string>();

            IsMouseVisible = false;

            InitialiseBindings();

            base.Initialize();
        }
        public BlackFog(IServiceProvider services, GraphicsDevice graphics, int hp = 0)
        {
            graphicsDevice = graphics;

            if (content == null)
            {
                content = new ContentManager(services)
                {
                    RootDirectory = "Content"
                }
            }
            ;

            fsm = new FSM(this);

            rand = new Random();

            BF_RampageState     rampage     = new BF_RampageState();
            BF_SwordAttackState swordAttack = new BF_SwordAttackState();
            BF_SlamAttackState  slamAttack  = new BF_SlamAttackState();

            // Adding transitions for states to all other states
            // if it satisfies the enum condition
            rampage.AddTransition(new Transition(swordAttack, () => currentMove == MoveSet.SwordAttack));
            rampage.AddTransition(new Transition(slamAttack, () => currentMove == MoveSet.SlamAttack));

            swordAttack.AddTransition(new Transition(rampage, () => currentMove == MoveSet.Rampage));
            swordAttack.AddTransition(new Transition(slamAttack, () => currentMove == MoveSet.SlamAttack));

            slamAttack.AddTransition(new Transition(rampage, () => currentMove == MoveSet.Rampage));
            slamAttack.AddTransition(new Transition(swordAttack, () => currentMove == MoveSet.SwordAttack));

            // Add all the states to the state machine
            fsm.AddState(rampage);
            fsm.AddState(swordAttack);
            fsm.AddState(slamAttack);

            fsm.Initialise("Rampage");

            idleAnimation = new Animation(content.Load <Texture2D>("Graphics/Boss/BlackFogIdle"), 0.1f, true, 18);
            runAnimation  = new Animation(content.Load <Texture2D>("Graphics/Boss/BlackFogRunning"), 0.06f, true, 12);
            fallAnimation = new Animation(content.Load <Texture2D>("Graphics/Boss/BlackFogFalling"), 0.3f, false, 6);
            dieAnimation  = new Animation(content.Load <Texture2D>("Graphics/Boss/BlackFogDying"), 0.08f, false, 15);

            shockwaveSound = content.Load <SoundEffect>("Audio/shockwave_pound");

            movementSpeed = 500.0f;

            startingPosition = new Vector2(graphics.Viewport.Width / 2, 0.0f);
            position         = startingPosition;
            dest             = Vector2.Zero;

            direction = 1;

            maxHealth = 500;

            // If it's initialised with 0 from the script
            // then set it to the max health
            if (hp == 0)
            {
                health = maxHealth;
            }
            else
            {
                health = hp;
            }

            // Time to wait to switch
            // to the next state
            FSMWaitDelay = 3.0f;
            FSMWaitTime  = FSMWaitDelay;

            // Modified Rectangle dimensions
            // of the frame for collisions
            int width  = (int)(idleAnimation.FrameWidth * 0.4);
            int left   = (idleAnimation.FrameWidth - width) / 2;
            int height = (int)(idleAnimation.FrameWidth * 0.1);
            int top    = idleAnimation.FrameHeight - height;

            localBounds = new Rectangle(left, top, width, height);

            sprite = new Animator(OriginLocation.Center);
            sprite.PlayAnimation(idleAnimation);

            sword      = new BlackFogSword();
            left_wave  = new BlackFogShockwave();
            right_wave = new BlackFogShockwave();

            sword.Initialise(content, position);
            left_wave.Initialise(content);
            right_wave.Initialise(content);

            haltMovement       = false;
            castShockWave      = false;
            initialPositionSet = false;

            currentMoveNum = 0;
        }
        public SwampCry(IServiceProvider services, GraphicsDevice graphics, int hp = 0)
        {
            graphicsDevice = graphics;

            if (content == null)
            {
                content = new ContentManager(services)
                {
                    RootDirectory = "Content"
                }
            }
            ;

            fsm = new FSM(this);

            rand = new Random();

            SC_RampageState    idle        = new SC_RampageState();
            SC_ClubAttackState clubAttack  = new SC_ClubAttackState();
            SC_ThrowAttack     throwAttack = new SC_ThrowAttack();

            idle.AddTransition(new Transition(clubAttack, () => currentMove == MoveSet.ClubAttack));
            idle.AddTransition(new Transition(throwAttack, () => currentMove == MoveSet.ThrowAttack));

            clubAttack.AddTransition(new Transition(idle, () => currentMove == MoveSet.Rampage));
            clubAttack.AddTransition(new Transition(throwAttack, () => currentMove == MoveSet.ThrowAttack));

            throwAttack.AddTransition(new Transition(idle, () => currentMove == MoveSet.Rampage));
            throwAttack.AddTransition(new Transition(clubAttack, () => currentMove == MoveSet.ClubAttack));

            fsm.AddState(idle);
            fsm.AddState(clubAttack);
            fsm.AddState(throwAttack);

            fsm.Initialise("Rampage");

            idleAnimation  = new Animation(content.Load <Texture2D>("Graphics/Boss/SwampCryIdle"), 0.1f, true, 18);
            runAnimation   = new Animation(content.Load <Texture2D>("Graphics/Boss/SwampCryRunning"), 0.06f, true, 12);
            throwAnimation = new Animation(content.Load <Texture2D>("Graphics/Boss/SwampCryThrowing"), 0.07f, true, 12);
            fallAnimation  = new Animation(content.Load <Texture2D>("Graphics/Boss/SwampCryFalling"), 0.3f, false, 6);
            dieAnimation   = new Animation(content.Load <Texture2D>("Graphics/Boss/SwampCryDying"), 0.08f, false, 15);

            movementSpeed = 750.0f;

            startingPosition = new Vector2(graphics.Viewport.Width / 2, 0.0f);
            position         = startingPosition;
            dest             = Vector2.Zero;

            direction = 1;

            maxHealth = 500;

            if (hp == 0)
            {
                health = maxHealth;
            }
            else
            {
                health = hp;
            }

            FSMWaitDelay = 3.0f;
            FSMWaitTime  = FSMWaitDelay;

            int width  = (int)(idleAnimation.FrameWidth * 0.4);
            int left   = (idleAnimation.FrameWidth - width) / 2;
            int height = (int)(idleAnimation.FrameWidth * 0.1);
            int top    = idleAnimation.FrameHeight - height;

            localBounds = new Rectangle(left, top, width, height);

            sprite = new Animator(OriginLocation.Center);
            sprite.PlayAnimation(fallAnimation);

            club  = new SwampCryClub();
            spell = new SwampCrySpell();

            club.Initialise(content, position);
            spell.Initialise(content);

            currentMoveNum = 0;
        }