Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            // Turn on chat mode
            if (InputEngine.IsKeyPressed(Keys.F1))
            {
                // line represent the current line to be captured
                line = string.Empty;
                chatMode = !chatMode;
            }
            // if chatting then do not update game window
            if (chatMode)
            {
                if (InputEngine.IsKeyPressed(Keys.Enter))
                {
                    // replace connection id with name of logged in player
                    chatproxy.Invoke("SendMess", new object[] { connection.ConnectionId, line });
                    line = string.Empty;
                    //chatMessages.Add(line);
                }
                else
                {
                    //if (InputEngine.PressedKeys.Length > 0)

                    if (InputEngine.currentKey != Keys.None)
                        line += InputEngine.lookupKeys[InputEngine.currentKey];
                }
            }
            // update game window
            else
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    proxy.Invoke("GetPoint");
                if (!(PlayerAuthentication.PlayerStatus == AUTHSTATUS.OK))
                {
                    Exitcount -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (Exitcount < 1)
                        Exit();
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    scores = PlayerAuthentication.getScores(5, "Battle Call");
                    if (scores != null)
                    {
                        _scoreboard = true;

                    }
                }
            }

            newState = Keyboard.GetState(); //set the current keyboardState

           

            if (currentState == currentDisplay.Selection)
            {
                menu.CheckMouse();

                player = createPlayer(clientID, menu.MenuAction, playerColor);

                if (player != null)
                {
                    proxy.Invoke("SendPlayer", menu.MenuAction);

                    sendBarriers(Barriers);
                }

                menu.MenuAction = null; //reset the selection
            }

         




            if (currentState == currentDisplay.Game) //if the game is running
            {
                if (gameStarted)
                {
                    if (newState.IsKeyDown(Keys.Escape) && oldState != newState && gameStarted)
                    {

                        currentState = currentDisplay.LeaderBoard;

                    }


                    player.Move(newState); //check for the player movement
                    proxy.Invoke("UpdatePosition", player._position);

                   
                    foreach (var item in Bullets) //check if bullet hit a barrier and destroy it
                    {
                        foreach (var bar in Barriers)
                        {
                            if (item.CollisiionDetection(bar.Rectangle))
                            {
                                if (item.createdPlayerID != bar.createdClientID)
                                {
                                    bar.GotHit(item);
                                    item.IsVisible = false;
                                    destroyBullets.Add(item);
                                    if (!bar.IsVisible)
                                        destroyBarrier.Add(bar);

                                }
                            }
                        }
                        if (item.CollisiionDetection(Enemy.Rectangle))
                            Enemy.PlayerChar.GotShoot(item);

                        if (item.CollisiionDetection(player.Rectangle))
                            player.PlayerChar.GotShoot(item);
                    }

                    foreach (var item in Collectables)
                    {
                        if (player.CollisiionDetection(item.Rectangle))
                        {
                            pickUp.Add(item);
                            ammo += 100;
                            item.IsVisible = false;
                            player.Collect(item);
                        }

                        if (Enemy.CollisiionDetection(item.Rectangle))
                        {
                            pickUp.Add(item);
                            item.IsVisible = false;
                            Enemy.Collect(item);
                        }
                    }



                    if (newState.IsKeyDown(Keys.Space) && oldState != newState && gameStarted)
                    {
                        if (ammo > 0)
                        {

                            newBullet = player.PlayerChar.Shoot(player._position, player.FireDirection, playerColor); //create a bullet
                            if (newBullet != null)
                            {
                                Bullets.Add(newBullet); //add the new bullet to the list
                                proxy.Invoke("NewBullet", newBullet._position, newBullet.flyDirection);
                                ammo -= 100;
                            }

                        }

                    }
                    //Bullets.Add(new Bullet(player.PlayerChar._texture, player.PlayerChar.strength, player.Position, player.FireDirection));

                    foreach (var item in Bullets)
                    {
                        item.Update(); //update the Bullets
                        if (OutsideScreen(item))
                        {
                            destroyBullets.Add(item);
                        }
                    }

                    foreach (var item in destroyBarrier)
                    {
                        Barriers.Remove(item);
                    }
                    foreach (var item in pickUp)
                    {
                        Collectables.Remove(item);
                    }
                    foreach (var item in destroyBullets)
                    {
                        Bullets.Remove(item);
                    }

                    destroyBarrier.Clear();
                    pickUp.Clear();
                    destroyBullets.Clear();

                    if (Collectables.Count == 0)
                        currentState = currentDisplay.Score;
                    if (Enemy.PlayerChar.Health <= 0)
                        currentState = currentDisplay.Score;
                    if (player.PlayerChar.Health <= 0)
                        currentState = currentDisplay.Score;

                    if (currentState == currentDisplay.Score)
                    {
                        gameStarted = false;
                        proxy.Invoke("StartGame", gameStarted);
                        if (player.score > Enemy.score)
                            gameOutcome = endGameStatuses.Win;
                        if (player.score < Enemy.score)
                            gameOutcome = endGameStatuses.Lose;
                        if (player.score == Enemy.score)
                            gameOutcome = endGameStatuses.Draw;
                    }

                }
            }



            if (newState.IsKeyDown(Keys.Escape) && oldState != newState) // go back to the character selection
                Exit();

            // TODO: Add your update logic here
            base.Update(gameTime);
        }
Beispiel #2
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            // Turn on chat mode
            if (InputEngine.IsKeyPressed(Keys.F1))
            {
                // line represent the current line to be captured
                line     = string.Empty;
                chatMode = !chatMode;
            }
            // if chatting then do not update game window
            if (chatMode)
            {
                if (InputEngine.IsKeyPressed(Keys.Enter))
                {
                    // replace connection id with name of logged in player
                    chatproxy.Invoke("SendMess", new object[] { connection.ConnectionId, line });
                    line = string.Empty;
                    //chatMessages.Add(line);
                }
                else
                {
                    //if (InputEngine.PressedKeys.Length > 0)

                    if (InputEngine.currentKey != Keys.None)
                    {
                        line += InputEngine.lookupKeys[InputEngine.currentKey];
                    }
                }
            }
            // update game window
            else
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    proxy.Invoke("GetPoint");
                }
                if (!(PlayerAuthentication.PlayerStatus == AUTHSTATUS.OK))
                {
                    Exitcount -= gameTime.ElapsedGameTime.TotalSeconds;
                    if (Exitcount < 1)
                    {
                        Exit();
                    }
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    scores = PlayerAuthentication.getScores(5, "Battle Call");
                    if (scores != null)
                    {
                        _scoreboard = true;
                    }
                }
            }

            newState = Keyboard.GetState(); //set the current keyboardState



            if (currentState == currentDisplay.Selection)
            {
                menu.CheckMouse();

                player = createPlayer(clientID, menu.MenuAction, playerColor);

                if (player != null)
                {
                    proxy.Invoke("SendPlayer", menu.MenuAction);

                    sendBarriers(Barriers);
                }

                menu.MenuAction = null; //reset the selection
            }



            if (currentState == currentDisplay.Game) //if the game is running
            {
                if (gameStarted)
                {
                    if (newState.IsKeyDown(Keys.Escape) && oldState != newState && gameStarted)
                    {
                        currentState = currentDisplay.LeaderBoard;
                    }


                    player.Move(newState); //check for the player movement
                    proxy.Invoke("UpdatePosition", player._position);


                    foreach (var item in Bullets) //check if bullet hit a barrier and destroy it
                    {
                        foreach (var bar in Barriers)
                        {
                            if (item.CollisiionDetection(bar.Rectangle))
                            {
                                if (item.createdPlayerID != bar.createdClientID)
                                {
                                    bar.GotHit(item);
                                    item.IsVisible = false;
                                    destroyBullets.Add(item);
                                    if (!bar.IsVisible)
                                    {
                                        destroyBarrier.Add(bar);
                                    }
                                }
                            }
                        }
                        if (item.CollisiionDetection(Enemy.Rectangle))
                        {
                            Enemy.PlayerChar.GotShoot(item);
                        }

                        if (item.CollisiionDetection(player.Rectangle))
                        {
                            player.PlayerChar.GotShoot(item);
                        }
                    }

                    foreach (var item in Collectables)
                    {
                        if (player.CollisiionDetection(item.Rectangle))
                        {
                            pickUp.Add(item);
                            ammo          += 100;
                            item.IsVisible = false;
                            player.Collect(item);
                        }

                        if (Enemy.CollisiionDetection(item.Rectangle))
                        {
                            pickUp.Add(item);
                            item.IsVisible = false;
                            Enemy.Collect(item);
                        }
                    }



                    if (newState.IsKeyDown(Keys.Space) && oldState != newState && gameStarted)
                    {
                        if (ammo > 0)
                        {
                            newBullet = player.PlayerChar.Shoot(player._position, player.FireDirection, playerColor); //create a bullet
                            if (newBullet != null)
                            {
                                Bullets.Add(newBullet); //add the new bullet to the list
                                proxy.Invoke("NewBullet", newBullet._position, newBullet.flyDirection);
                                ammo -= 100;
                            }
                        }
                    }
                    //Bullets.Add(new Bullet(player.PlayerChar._texture, player.PlayerChar.strength, player.Position, player.FireDirection));

                    foreach (var item in Bullets)
                    {
                        item.Update(); //update the Bullets
                        if (OutsideScreen(item))
                        {
                            destroyBullets.Add(item);
                        }
                    }

                    foreach (var item in destroyBarrier)
                    {
                        Barriers.Remove(item);
                    }
                    foreach (var item in pickUp)
                    {
                        Collectables.Remove(item);
                    }
                    foreach (var item in destroyBullets)
                    {
                        Bullets.Remove(item);
                    }

                    destroyBarrier.Clear();
                    pickUp.Clear();
                    destroyBullets.Clear();

                    if (Collectables.Count == 0)
                    {
                        currentState = currentDisplay.Score;
                    }
                    if (Enemy.PlayerChar.Health <= 0)
                    {
                        currentState = currentDisplay.Score;
                    }
                    if (player.PlayerChar.Health <= 0)
                    {
                        currentState = currentDisplay.Score;
                    }

                    if (currentState == currentDisplay.Score)
                    {
                        gameStarted = false;
                        proxy.Invoke("StartGame", gameStarted);
                        if (player.score > Enemy.score)
                        {
                            gameOutcome = endGameStatuses.Win;
                        }
                        if (player.score < Enemy.score)
                        {
                            gameOutcome = endGameStatuses.Lose;
                        }
                        if (player.score == Enemy.score)
                        {
                            gameOutcome = endGameStatuses.Draw;
                        }
                    }
                }
            }



            if (newState.IsKeyDown(Keys.Escape) && oldState != newState) // go back to the character selection
            {
                Exit();
            }

            // TODO: Add your update logic here
            base.Update(gameTime);
        }