Example #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();
            if (state.IsKeyUp(Keys.Up) && oldState.IsKeyDown(Keys.Up))
                enteredKeys.Add(Keys.Up);
            if (state.IsKeyUp(Keys.Down) && oldState.IsKeyDown(Keys.Down))
                enteredKeys.Add(Keys.Down);
            if (state.IsKeyUp(Keys.Left) && oldState.IsKeyDown(Keys.Left))
                enteredKeys.Add(Keys.Left);
            if (state.IsKeyUp(Keys.Right) && oldState.IsKeyDown(Keys.Right))
                enteredKeys.Add(Keys.Right);
            if (state.IsKeyUp(Keys.B) && oldState.IsKeyDown(Keys.B))
                enteredKeys.Add(Keys.B);
            if (state.IsKeyUp(Keys.A) && oldState.IsKeyDown(Keys.A))
                enteredKeys.Add(Keys.A);
            CheckCheatCode();
            oldState = state;
            //Check to see if the Gamer is Signed In
            if (SignedInGamer.SignedInGamers.Count < 1)
            {
                if (!Guide.IsVisible)
                    Guide.ShowSignIn(1, true);
            }
            else if (activePlayers.Count < 1)
            {
                GetPlayerInfo();
            }

            if (gameState == GameState.Main_Menu)
            {

                if (menuMusic.IsStopped)
                {
                    menuMusic = soundBank.GetCue("Plunder");
                    menuMusic.Play();
                }

                if (gwinner != null)
                {
                    if (!gwinner.Update())
                    {
                        scene.UIRenderer.Remove2DComponent(winners);
                        winners.RemoveChild(gwinner);
                        gwinner = null;
                    }
                }
            }

            //If joining a game, make sure you have all your markers
            if (gameState == GameState.Calibrating)
            {
                CheckReady();
            }

            if (gameState == GameState.Count_Down)
            {
                if (gwinner != null)
                {
                    if (!gwinner.Update())
                    {
                        scene.UIRenderer.Remove2DComponent(winners);
                        winners.RemoveChild(gwinner);
                        gwinner = null;
                    }
                }

                if (countDownTimer > 0)
                {
                    countDownTimer--;
                }
                else
                {
                    backgroundMusic = soundBank.GetCue("Boom Music");
                    backgroundMusic.Play();
                    gameState = GameState.In_Game;
                }
            }

            //Code for playing a match
            if (gameState == GameState.In_Game)
            {
                foreach (GameObject obj in ActiveGameObjects)
                {
                    //Update missle positions, remove any out of bounds ones
                    if (obj.Name == "Missile")
                    {
                        obj.MoveObjectForward(10);
                        if (OutOfBounds(obj))
                        {
                            obj.flagForRemoval = true;
                        }
                        else
                        {
                            if (obj.Player_Information.PlayerName == ActiveGameObjects[0].Player_Information.PlayerName)
                            {
                                if (CheckCollision(obj, ActiveGameObjects[1]))
                                {
                                    RegisterHitOnPlayer(1);
                                    obj.flagForRemoval = true;
                                }
                            }
                            else if (obj.Player_Information.PlayerName == ActiveGameObjects[1].Player_Information.PlayerName)
                            {
                                if (CheckCollision(obj, ActiveGameObjects[0]))
                                {
                                    RegisterHitOnPlayer(0);
                                    obj.flagForRemoval = true;
                                }
                            }
                        }
                    }

                    //Update the player ships
                    if (obj.Name == "Player Ship")
                    {
                        obj.Cool_Down--;
                        obj.MoveObjectForward(obj.Player_Information.Speed_Level+2);
                    }
                }

                //Update for the local player, his shooting, moving, etc...
                if( OutOfBounds(ActiveGameObjects[playerIndex])){

                    UpdateRotation(ActiveGameObjects[playerIndex],Vector3.Zero);

                }else if (MarkerNode1.MarkerFound)
                {
                    UpdateRotation(ActiveGameObjects[playerIndex], MarkerNode1.WorldTransformation.Translation);
                }

                if (!MarkerNode2.MarkerFound)
                {
                    if (ActiveGameObjects[playerIndex].CanFire)
                    {
                        if (gameMode == GameMode.Network_Multiplayer)
                            SendAttack();

                        Shoot(ActiveGameObjects[playerIndex]);
                        ActiveGameObjects[playerIndex].Cool_Down = 200;
                    }
                }

                //If this is a local game, update for player 2
                if (gameMode == GameMode.Local_Multiplayer)
                {
                    if (OutOfBounds(ActiveGameObjects[1]))
                    {
                        UpdateRotation(ActiveGameObjects[1], Vector3.Zero);
                    }
                    else if (MarkerNode4.MarkerFound)
                    {
                        UpdateRotation(ActiveGameObjects[1], MarkerNode4.WorldTransformation.Translation);
                    }

                    if (!MarkerNode5.MarkerFound)
                    {
                        if (ActiveGameObjects[1].CanFire)
                        {
                            Shoot(ActiveGameObjects[1]);
                            ActiveGameObjects[1].Cool_Down = 200;
                        }
                    }
                }

                //Update the network if this is a network game
                if (gameMode == GameMode.Network_Multiplayer)
                    UpdateNetwork();

                UpdateHUD();

                RemoveInactiveObjects();
            }

            if (session != null)
                session.Update();

            base.Update(gameTime);
        }
Example #2
0
        /// <summary>
        /// Called when a Game has ended
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void session_GameEnded(object sender, GameEndedEventArgs e)
        {
            string winner;
            Console.WriteLine("Game has ended...");
            if (ActiveGameObjects[playerIndex].Health > 0)
            {
                activePlayers[playerIndex].Money += 250;
                activePlayers[opponentIndex].Money += 100;
                winner = activePlayers[playerIndex].PlayerName;
            }
            else
            {
                activePlayers[playerIndex].Money += 100;
                activePlayers[opponentIndex].Money += 250;
                winner = activePlayers[opponentIndex].PlayerName;
            }
            if (session.IsHost)
            {
                activePlayers[playerIndex].UpdateInfoOnServer(SERVER_IP, SERVER_PORT_NUM);
                activePlayers[opponentIndex].UpdateInfoOnServer(SERVER_IP, SERVER_PORT_NUM);
            }

            backgroundMusic.Stop(AudioStopOptions.Immediate);
            scene.UIRenderer.Remove2DComponent(player1_hud);
            scene.UIRenderer.Remove2DComponent(player2_hud);
            HideMainMenu();
            scene.RootNode.RemoveChildren();
            session.Dispose();
            session = null;

            backgroundMusic = soundBank.GetCue("Boom Music");
            gameState = GameState.Main_Menu;
            gameMode = GameMode.Menu;
            DisplayMainMenu();

            /*added for winner label*/
            gwinner = new FadingMessage(winner + " is the Winner and recieves 250 in coins, ENJOY! ", 1000);
            gwinner.Bounds = new Rectangle(0, 0, 130, 30);
            gwinner.Name = "gwinner";
            gwinner.TextFont = hudFont;
            gwinner.TextColor = Color.ForestGreen;
            winners.Enabled = true;
            winners.Visible = true;
            gwinner.Enabled = true;
            gwinner.Visible = true;
            winners.AddChild(gwinner);
            gwinner.Transparency = 1.0f;
        }
Example #3
0
        /// <summary>
        /// Called when a game has started
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void session_GameStarted(object sender, GameStartedEventArgs e)
        {
            Console.WriteLine("Game has started...");

            if (playerIndex == 0)
                opponentIndex = 1;
            else
                opponentIndex = 0;

            CreateLights();
            CreateGameObjects();
            CreateHUD();
            //AddCollisionCallbackShips(ActiveGameObjects[0], ActiveGameObjects[1]);
            HideMainMenu();
            menuMusic.Stop(AudioStopOptions.Immediate);
            countDownTimer = 300;
            gameState = GameState.Count_Down;

            string color;
            if (playerIndex == 0)
            {
                color = "Red";
            }
            else
            {
                color = "Green";
            }

            gwinner = new FadingMessage("You are " + color, 1000);
            gwinner.Bounds = new Rectangle(0, 0, 130, 30);
            gwinner.Name = "gwinner";
            gwinner.TextFont = hudFont;
            if (playerIndex == 0)
            {
                color = "Red";
                gwinner.TextColor = Color.Red;
            }
            else
            {
                color = "Green";
                gwinner.TextColor = Color.Green;
            }

            winners.Enabled = true;
            winners.Visible = true;
            gwinner.Enabled = true;
            gwinner.Visible = true;
            winners.AddChild(gwinner);
            gwinner.Transparency = 1.0f;
        }
Example #4
0
        public void AddMessage(string text)
        {
            FadingMessage message = new FadingMessage(text, 180);
            message.Bounds = new Rectangle(150, 0, 100, 80);
            message.TextFont = TextFont;

            if (Children.Count > 2)
            {
                Children.RemoveAt(2);
            }

            AddChild(message);
        }