Exemplo n.º 1
0
 /// <summary>
 /// Called when the Button is highlighted.
 /// </summary>
 public void OnRollOver()
 {
     if (!mEnabled)
     {
         mCrossOut.pDoRender = true;
     }
     else
     {
         mSetActiveAnimationMsg.mAnimationSetName_In = "RollOver";
         mObject.OnMessage(mSetActiveAnimationMsg);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Trigger the explosive to detonate.
        /// </summary>
        private void Detonate()
        {
            // Do this now so that if another event is sent from within this function it will not trigger
            // a second detonation.
            mExploded = true;

            // Pick a random animation to play.
            Int32 index = RandomManager.pInstance.RandomNumber() % mExplosionAnimationNames.Count;

            mSetActiveAnimationMessage.mAnimationSetName_In = mExplosionAnimationNames[index];

            GameObject fx = GameObjectFactory.pInstance.GetTemplate(mExplosionEffect);

            mGetAttachmentPointMsg.mName_In = "Ground";
            mGetAttachmentPointMsg.mPoisitionInWorld_Out = mParentGOH.pPosition; // Set a default incase it doesn't have a Ground attachment point.
            mParentGOH.OnMessage(mGetAttachmentPointMsg);
            fx.pPosition = mGetAttachmentPointMsg.mPoisitionInWorld_Out;
            fx.OnMessage(mSetActiveAnimationMessage);
            GameObjectManager.pInstance.Add(fx);

            // Find all the objects near by and apply some damage to them.
            mObjectsInRange.Clear();
            GameObjectManager.pInstance.GetGameObjectsInRange(mParentGOH, ref mObjectsInRange, mDamageAppliedTo);
            mApplyDamageMsg.mDamageAmount_In = mDamagedCaused * mDamageMod;
            for (Int32 i = 0; i < mObjectsInRange.Count; i++)
            {
                mObjectsInRange[i].OnMessage(mApplyDamageMsg);
            }

            // This guy is exploded so he should be cleaned up.
            GameObjectManager.pInstance.Remove(mParentGOH);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            // Scale the progress bar to show how much time is left. Subtract from 1 so that the bar
            // drains down instead of filling up. Not sure if that is intuative to the player though.
            mProgressBar.pScaleX = 1.0f - mResearchTimer.pPercentRemaining;

            // Have we finished researching?
            if (mResearchTimer.IsExpired())
            {
                DebugMessageDisplay.pInstance.AddConstantMessage("Research complete.");

                System.Diagnostics.Debug.Assert(null != mTarget, "Attempting to send message without a target set.");

                // Safety check to make sure we don't try to access a null target. This
                // is possible since the target is set after the fact.
                if (null != mTarget)
                {
                    FillOnResearchCompleteMessage();

                    mTarget.OnMessage(mMessageOnComplete);
                }

                // Turn ourselves off now that the research is complete.
                mParentGOH.SetBehaviourEnabled <StatBoostResearch>(false);

                // Announce that the research has been completed.
                mParentGOH.OnMessage(mOnResearchCompleteMsg);

                pNextLevel++;
            }
        }
        /// <summary>
        /// Called once when the state starts.  This is a chance to do things that should only happen once
        /// during a particular state.
        /// </summary>
        public override void OnBegin()
        {
            base.OnBegin();

            mEnduranceModeBG = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeBG\\EnduranceModeBG");
            mEnduranceModeButton = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeButton\\EnduranceModeButton");
            mModeSelectBG = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ModeSelectBG\\ModeSelectBG");
            mScoreAttackModeBG = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeBG\\ScoreAttackModeBG");
            mScoreAttackModeButton = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeButton\\ScoreAttackModeButton");
            mModeSelectTitle = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ModeSelectTitle\\ModeSelectTitle");
            mGoButton = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\GoButton\\GoButton");
            
            System.Diagnostics.Debug.Assert(GameModeManager.pInstance.pMode != GameModeManager.GameMode.None, "Game Mode is still None. It should have been set in previous state.");

            Single unselectedAlpha = 0.25f;

            if (GameModeManager.pInstance.pMode == GameModeManager.GameMode.Endurance)
            {
                mModeDesc = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeDesc\\EnduranceModeDesc");

                mSetColorMsg.mColor_In = new Microsoft.Xna.Framework.Color(unselectedAlpha, unselectedAlpha, unselectedAlpha, unselectedAlpha);
                mScoreAttackModeButton.OnMessage(mSetColorMsg, pParentGOH);
                mScoreAttackModeBG.OnMessage(mSetColorMsg, pParentGOH);

                // Only show the Tutorial Option for Endurance.
                mTutBox = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\Options\\Tutorial\\Checkbox\\Checkbox");
                mTutCheckButton = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\Options\\Tutorial\\Checkmark\\Checkmark");
                mTutLabel = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\Options\\Tutorial\\Label\\Label");
                GameObjectManager.pInstance.Add(mTutCheckButton);
                GameObjectManager.pInstance.Add(mTutBox);
                GameObjectManager.pInstance.Add(mTutLabel);
            }
            else if (GameModeManager.pInstance.pMode == GameModeManager.GameMode.TrickAttack)
            {
                mModeDesc = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeDesc\\ScoreAttackModeDesc");

                mSetColorMsg.mColor_In = new Microsoft.Xna.Framework.Color(unselectedAlpha, unselectedAlpha, unselectedAlpha, unselectedAlpha);
                mEnduranceModeButton.OnMessage(mSetColorMsg, pParentGOH);
                mEnduranceModeBG.OnMessage(mSetColorMsg, pParentGOH);
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Unhandled mode type.");
            }

            GameObjectManager.pInstance.Add(mEnduranceModeBG);
            GameObjectManager.pInstance.Add(mEnduranceModeButton);
            GameObjectManager.pInstance.Add(mModeSelectBG);
            GameObjectManager.pInstance.Add(mScoreAttackModeBG);
            GameObjectManager.pInstance.Add(mScoreAttackModeButton);
            GameObjectManager.pInstance.Add(mModeSelectTitle);
            GameObjectManager.pInstance.Add(mGoButton);
            GameObjectManager.pInstance.Add(mModeDesc);
        }
        /// <summary>
        /// Call repeatedly until it returns a valid new state to transition to.
        /// </summary>
        /// <returns>Identifier of a state to transition to.</returns>
        public override String OnUpdate()
        {
            GameObject tile = mGetTileToRepairMsg.mTile_Out;

            if (null != tile)
            {
                tile.OnMessage(mGetHealthMsg);

                if (mGetHealthMsg.mCurrentHealth_Out < mGetHealthMsg.mMaxHealth_Out)
                {
                    mIncrementHealthMsg.mIncrementAmount_In = mHpRepairRate;
                    tile.OnMessage(mIncrementHealthMsg);
                }
                else
                {
                    return("Repair");
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Call repeatedly until it returns a valid new state to transition to.
        /// </summary>
        /// <returns>Identifier of a state to transition to.</returns>
        public override string OnUpdate()
        {
            if (pParentGOH.pCollisionRect.Intersects(GameObjectManager.pInstance.pPlayer.pCollisionRect))
            {
                if (null == mButtonHint)
                {
                    // Set up the button hint.
                    mButtonHint           = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Interface\\ButtonHint\\ButtonHint");
                    mButtonHint.pPosition = pParentGOH.pPosition;

                    mSetActiveAnimationMsg.mAnimationSetName_In = "X";
                    mButtonHint.OnMessage(mSetActiveAnimationMsg);

                    GameObjectManager.pInstance.Add(mButtonHint);
                }

                mButtonHint.pDoRender = true;

                // If the player stands on this Stranded, and presses the prompt button, bring up a popup
                // asking them what kind of task they wish to assign to this character.
                if (InputManager.pInstance.CheckAction(InputManager.InputActions.X, true))
                {
                    mPopup = GameObjectFactory.pInstance.GetTemplate(mPopupScript);
                    GameObjectManager.pInstance.Add(mPopup);

                    // Switch to a new update pass so that the game essentially pauses.
                    GameObjectManager.pInstance.pCurUpdatePass = BehaviourDefinition.Passes.POPUP;
                }
            }
            else
            {
                // Get rid of the Button Hint.
                if (null != mButtonHint)
                {
                    GameObjectManager.pInstance.Remove(mButtonHint);
                    mButtonHint = null;
                }
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            GameObject player = GameObjectManager.pInstance.pPlayer;

            // For now just check if we are colliding with the player.
            // TODO: Object should be able to specify what types of objects can pick it up.
            if (mParentGOH.pCollisionRect.Intersects(player.pCollisionRect))
            {
                DebugMessageDisplay.pInstance.AddConstantMessage("Pickup grabbed");

                // Grab an instance of the object that needs to be added to the Player's invantory
                // when this object is picked up.
                GameObject obj = GameObjectFactory.pInstance.GetTemplate(mInventoryTemplateFileName);

                // Add the object to the player's inventory.
                mAddObjectMsg.mObj_In = obj;
                player.OnMessage(mAddObjectMsg);

                // Stop updating and rendering the object. Also prevent things like collision checks finding it.
                GameObjectManager.pInstance.Remove(mParentGOH);
            }
        }
        /// <summary>
        /// Called once when the state starts.
        /// </summary>
        public override void OnBegin()
        {
            mSetActiveAnimationMsg.mAnimationSetName_In = "Idle";
            pParentGOH.OnMessage(mSetActiveAnimationMsg);

            pParentGOH.OnMessage(mGetTileToRepairMsg);

            if (mGetTileToRepairMsg.mTile_Out != null)
            {
                // Spawn some smoke to be more ninja like.
                mDust = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Effects\\Dust\\Dust");

                // Put the smoke at the right position relative to the Scout.
                mDust.pPosition = mGetTileToRepairMsg.mTile_Out.pPosition;

                mSetActiveAnimationMsg.mAnimationSetName_In = "Repair";
                mDust.OnMessage(mSetActiveAnimationMsg);

                // The Smoke gets pushed onto the GameObjectManager and will delete itself when
                // it finishes the animation.
                GameObjectManager.pInstance.Add(mDust);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Steps through all Tile objects in the level and generates a nave mesh from it.
        /// </summary>
        /// <param name="level"></param>
        public void CreateNavMesh(GameObject.GameObject level)
        {
            // The gets used over and over again throughout the life if this object.
            level.OnMessage(mGetMapInfoMsg);

            Int32 mapWidth = mGetMapInfoMsg.mInfo_Out.mMapWidth;
            Int32 mapHeight = mGetMapInfoMsg.mInfo_Out.mMapHeight;

            Int32 tileWidth = mGetMapInfoMsg.mInfo_Out.mTileWidth;
            Int32 tileHeight = mGetMapInfoMsg.mInfo_Out.mTileHeight;

            // Clusters get indexed based on their X, Y positions in the world.
            mClusters = new Cluster[mapWidth / mClusterSize, mapHeight / mClusterSize];

            // Loop through Cluster by Cluster initializing them.
            for (Int32 y = 0; y < mClusters.GetLength(1); y++)
            {
                for (Int32 x = 0; x < mClusters.GetLength(0); x++)
                {
                    Cluster temp = new Cluster(mClusterSize, tileWidth, tileHeight);

                    mGetTileAtPositionMsg.mPosition_In.X = x * (tileWidth * mClusterSize);
                    mGetTileAtPositionMsg.mPosition_In.Y = y * (tileHeight * mClusterSize);

                    level.OnMessage(mGetTileAtPositionMsg);

                    // The top left tile becomes a handy spot to start iterations over all Tile objects
                    // in a Cluster.
                    temp.pTopLeft = mGetTileAtPositionMsg.mTile_Out;

                    // Link Left <-> Right
                    if (x > 0)
                    {
                        temp.pNeighbouringClusters[(Int32)Cluster.AdjacentClusterDirections.Left] = mClusters[x - 1, y];
                        mClusters[x - 1, y].pNeighbouringClusters[(Int32)Cluster.AdjacentClusterDirections.Right] = temp;
                    }

                    // Link Up <-> Down
                    if (y > 0)
                    {
                        temp.pNeighbouringClusters[(Int32)Cluster.AdjacentClusterDirections.Up] = mClusters[x, y - 1];
                        mClusters[x, y - 1].pNeighbouringClusters[(Int32)Cluster.AdjacentClusterDirections.Down] = temp;
                    }

                    // Only walk the top and left walls for each cluster. The neighbouring clusters will do the same
                    // and as a result all walls will have been evaluated.
                    WalkWall(temp, temp.pTopLeft, null, Level.Tile.AdjacentTileDir.RIGHT, Level.Tile.AdjacentTileDir.UP, Cluster.AdjacentClusterDirections.Up);
                    WalkWall(temp, temp.pTopLeft, null, Level.Tile.AdjacentTileDir.DOWN, Level.Tile.AdjacentTileDir.LEFT, Cluster.AdjacentClusterDirections.Left);

                    // Store the cluster in the array index relative to its position in the world.
                    mClusters[x, y] = temp;
                }
            }

            // At this point all intra-connections have been made (cluster crossing connections), so now we need to
            // make all inter-connections (nodes linked inside of a cluster). We have to wait till now since the WallWalk 
            // done above only does 2 sides at a time.
            for (Int32 y = 0; y < mClusters.GetLength(1); y++)
            {
                for (Int32 x = 0; x < mClusters.GetLength(0); x++)
                {
                    Cluster temp = mClusters[x, y];

                    LinkClusterGraphNodes(temp);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            mSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Add any objects desired to the Game Object Factory.  These will be allocated now and can
            // be retrived later without any heap allocations.
            //
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Characters\\Scout\\Scout", 32);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Effects\\BulletSpark\\BulletSpark", 32);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Effects\\Dust\\Dust", 10);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Effects\\Explosion\\Explosion", 10);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Environments\\WallWood\\WallWood", 600);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Environments\\WallStone\\WallStone", 600);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Environments\\WallSteel\\WallSteel", 600);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Environments\\FloorSafeHouse\\FloorSafeHouse", 400);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Bullet\\Bullet", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\RifleBullet\\RifleBullet", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Grenade\\Grenade", 10);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Flare\\Flare", 10);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\WoodPickup\\WoodPickup", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\StonePickup\\StonePickup", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\SteelPickup\\SteelPickup", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\DetectorPickup\\DetectorPickup", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\GunTurretPickup\\GunTurretPickup", 100);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Detector\\Detector", 600);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\GunTurret\\GunTurret", 600);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\ButtonHint\\ButtonHint", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\ResearchProgressBar\\ResearchProgressBar", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\CivilianPopup\\CivilianPopup", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\ScoutPopup\\ScoutPopup", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\MilitantPopup\\MilitantPopup", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\MedicPopup\\MedicPopup", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Interface\\EngineerPopup\\EngineerPopup", 1);

            // The tiled background image that travels will the player creating the illusion of
            // an infinite background image.
            GameObject bg = new GameObject();

            MBHEngine.Behaviour.Behaviour t = new InfiniteBG(bg, null);
            bg.AttachBehaviour(t);
            bg.pRenderPriority = 20;
            GameObjectManager.pInstance.Add(bg);

            // Create the level.
            WorldManager.pInstance.Initialize();

            // Debug display for different states in the game.  This by creating new behaviours, additional
            // stats can be displayed.
            GameObject debugStatsDisplay = new GameObject();

            MBHEngine.Behaviour.Behaviour fps = new MBHEngine.Behaviour.FrameRateDisplay(debugStatsDisplay, null);
            debugStatsDisplay.AttachBehaviour(fps);
            GameObjectManager.pInstance.Add(debugStatsDisplay);

            // The player himself.
            GameObject player = new GameObject("GameObjects\\Characters\\Player\\Player");

            GameObjectManager.pInstance.Add(player);

            // Cheat to start the player with some walls in their inventory.
            if (CommandLineManager.pInstance["CheatFillInventory"] != null)
            {
                Inventory.AddObjectMessage addObj = new Inventory.AddObjectMessage();
                for (Int32 i = 0; i < 25; i++)
                {
                    addObj.mObj_In = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Environments\\WallWood\\WallWood");
                    player.OnMessage(addObj);

                    addObj.mObj_In = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Environments\\WallStone\\WallStone");
                    player.OnMessage(addObj);

                    addObj.mObj_In = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Environments\\WallSteel\\WallSteel");
                    player.OnMessage(addObj);
                }
            }

            // Store the player for easy access.
            GameObjectManager.pInstance.pPlayer = player;

            GameObject go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Items\\StonePickup\\StonePickup");

            go.pPosition = new Vector2(50, 50);
            GameObjectManager.pInstance.Add(go);

            for (Int32 i = 0; i < 16; i++)
            {
                GameObject chef = new GameObject("GameObjects\\Characters\\Civilian\\Civilian");
                chef.pPosX = 64;
                chef.pPosY = 64;
                GameObjectManager.pInstance.Add(chef);
            }

            //GameObject enemy = new GameObject("GameObjects\\Characters\\Kamikaze\\Kamikaze");
            //enemy.pPosition.X = 50;
            //enemy.pPosition.Y = 50;
            //GameObjectManager.pInstance.Add(enemy);

            // This GO doesn't need to exist beyond creation, so don't bother adding it to the GO Manager.
            new GameObject("GameObjects\\Utils\\RandEnemyGenerator\\RandEnemyGenerator");
            new GameObject("GameObjects\\Utils\\RandCivilianGenerator\\RandCivilianGenerator");
            new GameObject("GameObjects\\Utils\\RandMilitantGenerator\\RandMilitantGenerator");
            new GameObject("GameObjects\\Utils\\RandMedicGenerator\\RandMedicGenerator");
            new GameObject("GameObjects\\Utils\\RandEngineerGenerator\\RandEngineerGenerator");

            // The vingette effect used to dim out the edges of the screen.
            GameObject ving = new GameObject("GameObjects\\Interface\\Vingette\\Vingette");

#if SMALL_WINDOW
            ving.pScale = new Vector2(0.5f, 0.5f);
#endif
            GameObjectManager.pInstance.Add(ving);

            // Add the HUD elements.
            //
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Interface\\HUD\\PlayerHealthBar\\PlayerHealthBar"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Interface\\HUD\\PlayerScore\\PlayerScore"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Interface\\HUD\\PlayerInventory\\PlayerInventory"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Interface\\HUD\\MiniMap\\MiniMap"));

            DebugMessageDisplay.pInstance.AddConstantMessage("Game Load Complete.");
        }
Exemplo n.º 11
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Add any objects desired to the Game Object Factory.  These will be allocated now and can
            // be retrived later without any heap allocations.
            //
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Blood\\Blood", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Dust\\Dust", 64);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Kabooom\\Kabooom", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Sparks\\Sparks", 64);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\SparkEmitter\\SparkEmitter", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Tutorial\\Faster\\Faster", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\Items\\Tutorial\\Slower\\Slower", 4);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\CreditsButton\\CreditsButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\FacebookButton\\FacebookButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\FSMPauseScreen\\FSMPauseScreen", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\GoogleLeaderboardButton\\GoogleLeaderboardButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\HiScoreLabel\\HiScoreLabel", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\HitCountDisplay\\HitCountDisplay", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\HitCountDisplayRecord\\HitCountDisplayRecord", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\IndieDBButton\\IndieDBButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\LeaveCreditsButton\\LeaveCreditsButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\FSMMainMenu\\FSMMainMenu", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeBG\\EnduranceModeBG", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeDesc\\EnduranceModeDesc", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\EnduranceModeButton\\EnduranceModeButton", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\GoButton\\GoButton", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ModeSelectBG\\ModeSelectBG", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ModeSelectTitle\\ModeSelectTitle", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeBG\\ScoreAttackModeBG", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeButton\\ScoreAttackModeButton", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\MainMenu\\ModeSelect\\ScoreAttackModeDesc\\ScoreAttackModeDesc", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\NewHighScore\\NewHighScore", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\NumFont\\NumFont", 128);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\NumFontUI\\NumFontUI", 128);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\Options\\Tutorial\\Checkbox\\Checkbox", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\Options\\Tutorial\\Checkmark\\Checkmark", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\Options\\Tutorial\\Label\\Label", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PauseAchievementsButton\\PauseAchievementsButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PauseMainMenuButton\\PauseMainMenuButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PauseQuitButton\\PauseQuitButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PauseResumeButton\\PauseResumeButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PauseTrialModePurchaseButton\\PauseTrialModePurchaseButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\PointDisplay\\PointDisplay", 32);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\RecentTrickDisplay\\RecentTrickDisplay", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\ScoreLabel\\ScoreLabel", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\ScoreSummary\\ScoreSummary", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\ScoreSummaryBG\\ScoreSummaryBG", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TapStart\\TapStart", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\FSMTrialModeLimit\\FSMTrialModeLimit", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeWatermark\\TrialModeWatermark", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeInputDisabled\\TrialModeInputDisabled", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeLimitReached\\TrialModeLimitReached", 2);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeLimitReachedBG\\TrialModeLimitReachedBG", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModePurchaseButton\\TrialModePurchaseButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeEndGameButton\\TrialModeEndGameButton", 1);
            GameObjectFactory.pInstance.AddTemplate("GameObjects\\UI\\Tutorial\\TapToContinue\\TapToContinue", 1);

            // Add objects that exist from the moment the game starts.
            //
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Items\\Court\\Court"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\Items\\Net\\Net"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\Backdrop\\Backdrop"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\BG\\BG"));
            //GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\CKuklaButton\\CKuklaButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\MHughsonButton\\MHughsonButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\MImmonenButton\\MImmonenButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\SMcGeeButton\\SMcGeeButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\Credits\\SPaxtonButton\\SPaxtonButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\GameOver\\GameOver"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\PauseButton\\PauseButton"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\PausedBackdrop\\PausedBackdrop"));
            GameObjectManager.pInstance.Add(new GameObject("GameObjects\\UI\\PausedOverlay\\PausedOverlay"));

            GameObject titleScreen = GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\MainMenu\\FSMMainMenu\\FSMMainMenu");
            GameObjectManager.pInstance.Add(titleScreen);

            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\TrialModeLimit\\FSMTrialModeLimit\\FSMTrialModeLimit"));
            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\TrialModeLimit\\TrialModeWatermark\\TrialModeWatermark"));

            // Disabled recent trick display. Doesn't look very good and seems not very useful.
            //GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\RecentTrickDisplay\\RecentTrickDisplay"));

            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\ScoreLabel\\ScoreLabel"));
            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\HitCountDisplay\\HitCountDisplay"));
            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\HiScoreLabel\\HiScoreLabel"));
            GameObjectManager.pInstance.Add(GameObjectFactory.pInstance.GetTemplate("GameObjects\\UI\\HitCountDisplayRecord\\HitCountDisplayRecord"));

            // The tiled background image that travels will the player creating the illusion of
            // an infinite background image.
            GameObject bg = new GameObject();
            MBHEngine.Behaviour.Behaviour t = new InfiniteBG(bg, null);
            bg.AttachBehaviour(t);
            bg.pRenderPriority = 20;
            GameObjectManager.pInstance.Add(bg);
            
            // Create the level.
            WorldManager.pInstance.Initialize();

            // Debug display for different states in the game.  This by creating new behaviours, additional
            // stats can be displayed.
            GameObject debugStatsDisplay = new GameObject();
            MBHEngine.Behaviour.Behaviour fps = new MBHEngine.Behaviour.FrameRateDisplay(debugStatsDisplay, null);
            debugStatsDisplay.AttachBehaviour(fps);
            GameObjectManager.pInstance.Add(debugStatsDisplay);

            // The player himself.
            GameObject player = new GameObject("GameObjects\\Characters\\Player\\Player");
            GameObjectManager.pInstance.Add(player);

            // Store the player for easy access.
            GameObjectManager.pInstance.pPlayer = player;

            GroundShadow.SetTargetMessage setTarg = new GroundShadow.SetTargetMessage();

            GameObject shadow = new GameObject("GameObjects\\Items\\PlayerShadow\\PlayerShadow");
            GameObjectManager.pInstance.Add(shadow);
            setTarg.mTarget_In = player;
            shadow.OnMessage(setTarg);

            GameObject ball = new GameObject("GameObjects\\Items\\Ball\\Ball");
            GameObjectManager.pInstance.Add(ball);
            shadow = new GameObject("GameObjects\\Items\\BallShadow\\BallShadow");
            GameObjectManager.pInstance.Add(shadow);
            setTarg.mTarget_In = ball;
            shadow.OnMessage(setTarg);

            GameObject partner = new GameObject("GameObjects\\Characters\\Partner\\Partner");
            GameObjectManager.pInstance.Add(partner); 
            shadow = new GameObject("GameObjects\\Items\\PlayerShadow\\PlayerShadow");
            GameObjectManager.pInstance.Add(shadow);
            setTarg.mTarget_In = partner;
            shadow.OnMessage(setTarg);

            GameObject opponent = new GameObject("GameObjects\\Characters\\Opponent\\Opponent");
            GameObjectManager.pInstance.Add(opponent);
            shadow = new GameObject("GameObjects\\Items\\PlayerShadow\\PlayerShadow");
            GameObjectManager.pInstance.Add(shadow);
            setTarg.mTarget_In = opponent;
            shadow.OnMessage(setTarg);

            opponent = new GameObject("GameObjects\\Characters\\Opponent\\Opponent");
            opponent.pPosX = 75.0f;
            GameObjectManager.pInstance.Add(opponent);
            shadow = new GameObject("GameObjects\\Items\\PlayerShadow\\PlayerShadow");
            GameObjectManager.pInstance.Add(shadow);
            setTarg.mTarget_In = opponent;
            shadow.OnMessage(setTarg);

            // The vingette effect used to dim out the edges of the screen.
            //GameObject ving = new GameObject("GameObjects\\Interface\\Vingette\\Vingette");
#if SMALL_WINDOW
            //ving.pScale = new Vector2(0.5f, 0.5f);
#endif
            //GameObjectManager.pInstance.Add(ving);

            DebugMessageDisplay.pInstance.AddConstantMessage("Game Load Complete.");
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            // Grab the current state of the gamepad.
            GamePadThumbSticks padState = InputManager.pInstance.GetDirectionalInfo();

            // Store the original position prior to polling any input for use with collision reactions.
            Vector2 origPos = mParentGOH.pPosition;

            // The character will move at this rate in the direction of the Left Analog Stick.
            Vector2 dir1 = new Vector2(mMoveSpeed, -mMoveSpeed);

            dir1 *= padState.Left;
            mParentGOH.pPosition += dir1;

            // The position the Gun gets attached to is configured via an AttachPoint in the
            // Player template.
            mGetAttachmentPointMsg.mName_In = "Gun";
            mParentGOH.OnMessage(mGetAttachmentPointMsg);
            Vector2 mGunAttachPos = mGetAttachmentPointMsg.mPoisitionInWorld_Out;

            // Position the gun at the attachment point.
            mGun.pPosition = mGunAttachPos;

            // Flip the sprite to face the direction that we are moving.
            if (padState.Left.X > 0)
            {
                mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.None;
                mParentGOH.OnMessage(mSpriteFxMsg);

                // Initially the gun is positioned assuming the R-Stick is not pressed.  Just point straight
                // in the direction the player is walking.
                mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.None;
                mGun.OnMessage(mSpriteFxMsg);
                mGun.pRotation = 0.0f;
            }
            else if (padState.Left.X < 0)
            {
                mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.FlipHorizontally;
                mParentGOH.OnMessage(mSpriteFxMsg);

                mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.FlipVertically;
                mGun.OnMessage(mSpriteFxMsg);
                mGun.pRotation = MathHelper.ToRadians(180.0f);
            }

            // If the player is moving in any direction play the walking animation.
            if (padState.Left != Vector2.Zero)
            {
                mSpriteActiveAnimMsg.mAnimationSetName_In = "Run";
                mParentGOH.OnMessage(mSpriteActiveAnimMsg);
            }
            else
            {
                mSpriteActiveAnimMsg.mAnimationSetName_In = "Idle";
                mParentGOH.OnMessage(mSpriteActiveAnimMsg);
            }

            // Convert the direction of the right analog stick into an angle so that it can be used to set the rotation of
            // the sprite.
            Double angle = Math.Atan2(-padState.Right.Y, padState.Right.X);

            if (angle < 0)
            {
                angle += 2 * Math.PI;
            }

            //DebugMessageDisplay.pInstance.AddDynamicMessage("Angle: " + MathHelper.ToDegrees((Single)angle);
            //DebugMessageDisplay.pInstance.AddDynamicMessage("X: " + g.ThumbSticks.Right.X);
            //DebugMessageDisplay.pInstance.AddDynamicMessage("Y: " + g.ThumbSticks.Right.Y);

            // Determine the direction that right analog stick is pointing (if any).
            Vector2 dir = Vector2.Normalize(padState.Right);

            // If the user is pressing the right analog stick, then they need to fire a bullet.
            if (!Single.IsNaN(dir.X) && !Single.IsNaN(dir.Y))
            {
                //mGun.pPosition += dir;
                mGun.pRotation = (Single)angle;

                // Use dir, not finalDir, so that the direction does not include the spread randomization.
                if (dir.X > 0)
                {
                    mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.None;
                    mParentGOH.OnMessage(mSpriteFxMsg);

                    // To start the gun would be set to point in the direction we are walking.  We have turned to face the direction
                    // the player is shooting, so the gun needs to be updated as well.
                    mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.None;
                    mGun.OnMessage(mSpriteFxMsg);
                }
                else if (dir.X < 0)
                {
                    mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.FlipHorizontally;
                    mParentGOH.OnMessage(mSpriteFxMsg);

                    mSpriteFxMsg.mSpriteEffects_In = SpriteEffects.FlipVertically;
                    mGun.OnMessage(mSpriteFxMsg);
                }

                // We want some slight randomness to the bullets fired.  This is the randomness in radians.
                Single spread = 0.1f;

                // If they are holding R2, then the spread is even larger.
                if (InputManager.pInstance.CheckAction(InputManager.InputActions.R2, false))
                {
                    spread = 0.5f;
                }

                // Offset by a random amount within the spread range.
                Single offset = ((Single)RandomManager.pInstance.RandomPercent() * spread) - (spread * 0.5f);
                angle += offset;

                // Convert the angle back into a vector so that it can be used to move the bullet.
                Vector2 finalDir = new Vector2((Single)Math.Cos(angle), (Single)Math.Sin(angle));
                finalDir.Y *= -1;

                Vector2 finalUp = new Vector2(-finalDir.Y, -finalDir.X);
                if (finalDir.X < 0)
                {
                    finalUp *= -1;
                }

                if (mGunCooldown.IsExpired())
                {
                    mGunCooldown.Restart();

                    GameObject bullet = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Items\\Bullet\\Bullet");

                    if (bullet != null)
                    {
                        // Store the direction locally so as to not alter it and screw things
                        // up for the grenade afterwards.
                        Vector2 bulletDir = finalDir;

                        bullet.pDirection.mSpeed = 1.75f * mGunLevelInfo[mGunLevel].mSpeedMod;

                        // Update the game object with all the new data.
                        bullet.pPosition           = mGun.pPosition;
                        bullet.pRotation           = (Single)angle;
                        bullet.pDirection.mForward = bulletDir;

                        bulletDir.Y      *= -1;
                        bullet.pPosition += finalUp * 1.0f;
                        bullet.pPosition += bulletDir * 3.5f;

                        // The screen's y direction is opposite the controller.
                        bullet.pDirection.mForward.Y *= -1;

                        // Use our current gun level to upgrade the bullet.
                        mSetDamageModifierMessage.mDamageMod_In = mGunLevelInfo[mGunLevel].mDamageMod;
                        bullet.OnMessage(mSetDamageModifierMessage);

                        bullet.pScaleX = mGunLevelInfo[mGunLevel].mScaleMod;

                        GameObjectManager.pInstance.Add(bullet);
                    }
                }

                if (InputManager.pInstance.CheckAction(InputManager.InputActions.R1, true))
                {
                    if (mGrenadeCooldown.IsExpired())
                    {
                        mGrenadeCooldown.Restart();

                        GameObject go         = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Items\\Grenade\\Grenade");
                        Vector2    grenadeDir = finalDir;
                        grenadeDir.Y          *= -1;
                        go.pPosition           = mGun.pPosition;
                        go.pPosition          += finalUp * 1.0f;
                        go.pPosition          += grenadeDir * 3.5f;
                        go.pPosition           = go.pPosition;
                        go.pRotation           = (Single)angle;
                        go.pDirection.mForward = grenadeDir;
                        go.pDirection.mSpeed   = 0.25f;
                        GameObjectManager.pInstance.Add(go);
                    }
                }
            }

            if (InputManager.pInstance.CheckAction(InputManager.InputActions.L1, true))
            {
                // The first time they press L1, we place the safe house. After that, we drop extraction
                // flares.
                if (!mSafeHousePlaced)
                {
                    // Get the tile where mParentGOH is standing, so that we can start a Flood Fill
                    // at that position.
                    mGetTileAtObjectMsg.mObject_In = mParentGOH;
                    mGetTileAtObjectMsg.mTile_Out  = null;

                    WorldManager.pInstance.pCurrentLevel.OnMessage(mGetTileAtObjectMsg);

                    // Attempting to fill the world will SafeHouseFloors.
                    mSafeHousePlaced = mGOFloodFill.FloodFill(
                        mGetTileAtObjectMsg.mTile_Out,
                        10 * 10,
                        "GameObjects\\Environments\\FloorSafeHouse\\FloorSafeHouse");
                }
                else
                {
                    GameObject go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Items\\Flare\\Flare");
                    go.pPosition = mGun.pPosition;
                    GameObjectManager.pInstance.Add(go);

                    go.OnMessage(mSetExtractionPointActivateMsg);
                }
            }

            mGOFloodFill.ProcessFill();

            DebugMessageDisplay.pInstance.AddDynamicMessage("Player Pos: " + mParentGOH.pPosition);

            CameraManager.pInstance.pTargetPosition = mParentGOH.pPosition;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            mPotentialTargets.Clear();

            // Find all the possible targets in our firing range.
            GameObjectManager.pInstance.GetGameObjectsInRange(
                mParentGOH.pPosition,
                mFiringRange,
                ref mPotentialTargets,
                mTargetClassifications);

            // Most calculations are based on the attachment point of the Gun, rather than the position of
            // the parent GameObject.
            mGetAttachmentPointMsg.mName_In = "Gun";
            mParentGOH.OnMessage(mGetAttachmentPointMsg);

            // Position the gun at the attachment point every frame since we will be moving.
            mGun.pPosition = mGetAttachmentPointMsg.mPoisitionInWorld_Out;

            // If no targets were found there is still a bit of work to do.
            if (mPotentialTargets.Count <= 0)
            {
                // With no targets active, use the forward facing direction.
                Single dir = mParentGOH.pDirection.mForward.X;
                if (dir < 0)
                {
                    mSetSpriteEffectsMsg.mSpriteEffects_In = SpriteEffects.FlipVertically;
                    mGun.OnMessage(mSetSpriteEffectsMsg);
                    mGun.pRotation = MathHelper.ToRadians(180.0f);
                }
                else if (dir > 0)
                {
                    mSetSpriteEffectsMsg.mSpriteEffects_In = SpriteEffects.None;
                    mGun.OnMessage(mSetSpriteEffectsMsg);
                    mGun.pRotation = MathHelper.ToRadians(0.0f);
                }

                // Clear the look target.
                mSetLookTargetMsg.mTarget_In = null;
                mParentGOH.OnMessage(mSetLookTargetMsg);

                return;
            }

            // Just pick the first target. This might be improved with some logic to pick targets
            Vector2 target = mPotentialTargets[0].pPosition;

            mSetLookTargetMsg.mTarget_In = mPotentialTargets[0];
            mParentGOH.OnMessage(mSetLookTargetMsg);

            Vector2 toTarg = target - mGetAttachmentPointMsg.mPoisitionInWorld_Out;

            toTarg.Normalize();

            //DebugShapeDisplay.pInstance.AddSegment(mGetAttachmentPointMsg.mPoisitionInWorld_Out, mGetAttachmentPointMsg.mPoisitionInWorld_Out + (toTarg * 8.0f), Color.Red);

            // Convert the direction into an angle so that it can be used to set the rotation of
            // the sprite.
            Double angle = Math.Atan2(toTarg.Y, toTarg.X);

            if (angle < 0)
            {
                angle += 2 * Math.PI;
            }

            mGun.pRotation = (Single)angle;

            if (toTarg.X < 0)
            {
                mSetSpriteEffectsMsg.mSpriteEffects_In = SpriteEffects.FlipVertically;
                mGun.OnMessage(mSetSpriteEffectsMsg);
            }
            else if (toTarg.X > 0)
            {
                mSetSpriteEffectsMsg.mSpriteEffects_In = SpriteEffects.None;
                mGun.OnMessage(mSetSpriteEffectsMsg);
            }

            // We want some slight randomness to the bullets fired.  This is the randomness in radians.
            Single spread = 0.1f;

            // Offset by a random amount within the spread range.
            Single offset = ((Single)RandomManager.pInstance.RandomPercent() * spread) - (spread * 0.5f);

            angle += offset;

            // Convert the angle back into a vector so that it can be used to move the bullet.
            Vector2 finalDir = toTarg;

            finalDir.Y *= -1;

            Vector2 finalUp = new Vector2(-finalDir.Y, -finalDir.X);

            if (finalDir.X < 0)
            {
                finalUp *= -1;
            }

            if (mGunCooldown.IsExpired())
            {
                mGunCooldown.Restart();

                GameObject bullet = GameObjectFactory.pInstance.GetTemplate(mBulletScriptName);

                if (bullet != null)
                {
                    // Store the direction locally so as to not alter it and screw things
                    // up for the grenade afterwards.
                    Vector2 bulletDir = finalDir;

                    bullet.pDirection.mSpeed = mBulletSpeed;

                    // Update the game object with all the new data.
                    bullet.pPosition           = mGun.pPosition;
                    bullet.pRotation           = (Single)angle;
                    bullet.pDirection.mForward = bulletDir;

                    bulletDir.Y      *= -1;
                    bullet.pPosition += finalUp * 1.0f;
                    bullet.pPosition += bulletDir * 3.5f;

                    // The screen's y direction is opposite the controller.
                    bullet.pDirection.mForward.Y *= -1;

                    GameObjectManager.pInstance.Add(bullet);
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Called once per frame by the game object.
        /// </summary>
        /// <param name="gameTime">The amount of time that has passed this frame.</param>
        public override void Update(GameTime gameTime)
        {
            // Toggle between PLACEMENT mode on regular gameplay.
            //
            if (InputManager.pInstance.CheckAction(InputManager.InputActions.R2))
            {
                GameObjectManager.pInstance.pCurUpdatePass = BehaviourDefinition.Passes.PLACEMENT;
            }
            else
            {
                GameObjectManager.pInstance.pCurUpdatePass = BehaviourDefinition.Passes.DEFAULT;
            }

            if (GameObjectManager.pInstance.pCurUpdatePass != BehaviourDefinition.Passes.PLACEMENT)
            {
                // No need to continue on if we are not in placement mode.
                return;
            }

            // Switch to the next item in the inventory.
            //
            if (InputManager.pInstance.CheckAction(InputManager.InputActions.L1, true))
            {
                mParentGOH.OnMessage(mSelectNextItemMsg);
            }

            // Update the texture which appears on the cursor.
            UpdateItemTexture();

            // Move the cursor based on user input.
            MoveCursor();

            // Cache the current level object for quick reference.
            GameObject lvl = MBHEngine.World.WorldManager.pInstance.pCurrentLevel;

            // The the tile which the player is currently standing on. This will be our
            // starting point.
            mGetTileAtPositionMsg.mPosition_In = mParentGOH.pPosition;
            lvl.OnMessage(mGetTileAtPositionMsg);

            // We jump by tiles in terms of offsets (rather than pixels or something), so
            // figure out how many pixels each offset should be.
            lvl.OnMessage(mGetMapInfoMsg);

            // The final offset of the cursor is the cursor offset we are tracking times the
            // size of a single tile, so that we are always jumping one tile at a time.
            Vector2 offsetPx = new Vector2();

            offsetPx.X = mGetMapInfoMsg.mInfo_Out.mTileWidth * mCursorOffset.X;
            offsetPx.Y = mGetMapInfoMsg.mInfo_Out.mTileHeight * mCursorOffset.Y;

            // Reposition the cursor.
            mCursor.pPosition = mGetTileAtPositionMsg.mTile_Out.mCollisionRect.pCenterPoint + offsetPx;

            // Place and remove tiles.
            if (InputManager.pInstance.CheckAction(InputManager.InputActions.A, true))
            {
                // Remove the Object at the top of the Inventory.
                mGetCurrentObjectMsg.mObj_Out = null;
                mParentGOH.OnMessage(mGetCurrentObjectMsg);

                // We only want to attempt to place an object if we have something in the inventory to place.
                if (null != mGetCurrentObjectMsg.mObj_Out)
                {
                    mOnPlaceObjectMsg.Reset();

                    // Tell the object to place itself.
                    mOnPlaceObjectMsg.mPosition_In = mCursor.pPosition;
                    mGetCurrentObjectMsg.mObj_Out.OnMessage(mOnPlaceObjectMsg);

                    // It is possible that someone caught this event as decide this object should not
                    // be placed.
                    if (mOnPlaceObjectMsg.mObjectPlaced_Out)
                    {
                        // The object has been placed in the world, so the GameObjectManager needs to
                        // start managing it.
                        GameObjectManager.pInstance.Add(mGetCurrentObjectMsg.mObj_Out);
                    }
                    else
                    {
                        mAddObjectMsg.Reset();

                        // The object was removed from the inventory with the GerCurrentObjectMessage, so
                        // since it wasn't placed, it needs to be added back.
                        mAddObjectMsg.mObj_In         = mGetCurrentObjectMsg.mObj_Out;
                        mAddObjectMsg.mDoSelectObj_In = true;
                        mParentGOH.OnMessage(mAddObjectMsg);
                    }
                }
            }
            if (InputManager.pInstance.CheckAction(InputManager.InputActions.B, true))
            {
                mSetTileTypeAtPositionMsg.mType_In     = Level.Tile.TileTypes.Empty;
                mSetTileTypeAtPositionMsg.mPosition_In = mCursor.pPosition;
                MBHEngine.World.WorldManager.pInstance.pCurrentLevel.OnMessage(mSetTileTypeAtPositionMsg, mParentGOH);

                // Clear any objects that might still be stored from the previous frame.
                mCollidedObjects.Clear();

                // Check if any objects are colliding with the mouse.
                GameObjectManager.pInstance.GetGameObjectsInRange(mCursor, ref mCollidedObjects, mRemoveClassifications);

                for (Int32 i = 0; i < mCollidedObjects.Count; i++)
                {
                    GameObjectManager.pInstance.Remove(mCollidedObjects[i]);
                }
            }
        }