コード例 #1
0
    private void OnCollisionEnter(Collision collision)
    {
        GameObject     player = collision.gameObject;
        PlayerActivity pa     = player.GetComponent <PlayerActivity>();

        //Player is holding more than 1 vegetable so they cannot use plate
        if (vegetablesToHold.Count == 1 && pa.vegetables.Count == 1)
        {
            return;
        }

        //There is already a vegetable on this plate
        if (vegetablesToHold.Count == 1 && pa.vegetables.Count == 1)
        {
            return;
        }

        //Add vegetable to plate
        if (vegetablesToHold.Count == 0 && pa.vegetables.Count == 1)
        {
            vegetablesToHold.Add(pa.vegetables[0]);
            pa.vegetables  = new List <string>();
            pa.veg1.sprite = Resources.Load <Sprite>("Sprites/emptySprite");
            veg1.sprite    = AssignVegetable(vegetablesToHold[0]);
        }
        //Give vegetable back to player
        else if (vegetablesToHold.Count == 1 && pa.vegetables.Count == 0)
        {
            pa.vegetables.Add(vegetablesToHold[0]);
            vegetablesToHold = new List <string>();
            pa.veg1.sprite   = AssignVegetable(pa.vegetables[0]);
            veg1.sprite      = Resources.Load <Sprite>("Sprites/emptySprite");
        }
    }
コード例 #2
0
    private void SubtractPoints(GameObject player, int points)
    {
        PlayerActivity pa = player.gameObject.GetComponent <PlayerActivity>();

        pa.score -= points;
        NotificationCenter.DefaultCenter.PostNotification(this, "UpdateScore");
    }
コード例 #3
0
    private void OnCollisionEnter(Collision collision)
    {
        GameObject     player = collision.gameObject;
        PlayerActivity pa     = player.GetComponent <PlayerActivity>();
        string         bonus  = gameObject.name;

        if (pa.name == playerName)
        {
            //Apply spawned bonus
            switch (bonus)
            {
            case "Score":
                pa.score += 10;
                NotificationCenter.DefaultCenter.PostNotification(this, "UpdateScore");
                break;

            case "Speed":
                PlayerMovement pm = player.GetComponent <PlayerMovement>();
                pm.bonusActive   = true;
                pm.movementSpeed = 6;
                break;

            case "Time":
                pa.time += 25;
                break;
            }
            Destroy(gameObject);
        }
    }
コード例 #4
0
ファイル: PlayerNode.cs プロジェクト: redbaty/CSGSI
 internal PlayerNode(string JSON)
     : base(JSON)
 {
     _SteamID   = GetString("steamid");
     Name       = GetString("name");
     Team       = GetEnum <PlayerTeam>("team");
     Clan       = GetString("clan");
     State      = new PlayerStateNode(_Data?.SelectToken("state")?.ToString() ?? "{}");
     Weapons    = new WeaponsNode(_Data?.SelectToken("weapons")?.ToString() ?? "{}");
     MatchStats = new MatchStatsNode(_Data?.SelectToken("match_stats")?.ToString() ?? "{}");
     Activity   = GetEnum <PlayerActivity>("activity");
 }
コード例 #5
0
ファイル: PlayerNode.cs プロジェクト: antonpup/CSGSI
 internal PlayerNode(string JSON)
     : base(JSON)
 {
     _SteamID = GetString("steamid");
     Name = GetString("name");
     Team = GetEnum<PlayerTeam>("team");
     Clan = GetString("clan");
     State = new PlayerStateNode(_Data?.SelectToken("state")?.ToString() ?? "{}");
     Weapons = new WeaponsNode(_Data?.SelectToken("weapons")?.ToString() ?? "{}");
     MatchStats = new MatchStatsNode(_Data?.SelectToken("match_stats")?.ToString() ?? "{}");
     Activity = GetEnum<PlayerActivity>("activity");
 }
コード例 #6
0
    private void OnCollisionEnter(Collision collision)
    {
        GameObject     player = collision.gameObject;
        PlayerActivity pa     = player.GetComponent <PlayerActivity>();

        vegetablesToDispose = pa.vegetables;
        pa.vegetables       = new List <string>();
        pa.veg1.sprite      = Resources.Load <Sprite>("Sprites/emptySprite");
        pa.veg2.sprite      = Resources.Load <Sprite>("Sprites/emptySprite");

        pa.score -= 10;
        NotificationCenter.DefaultCenter.PostNotification(this, "UpdateScore");
    }
コード例 #7
0
        private static void PopulateGames(
            Repository <string, Game <string> > gameRepository,
            Repository <string, Player <string> > playerRepository,
            Repository <CompositeId <string>, PlayerActivity <string> > playerActivityRepository)
        {
            gameRepository.Clear();
            playerActivityRepository.Clear();

            for (var gameId = 0; gameId < NumberOfGames; gameId++)
            {
                var firstTeamId  = GetRandomTeamId(null);
                var secondTeamId = GetRandomTeamId(firstTeamId);
                var date         = GetRandomDate();
                var game         = new Game <string>(gameId.ToString(), firstTeamId, secondTeamId, date);
                gameRepository.Add(game);

                var firstTeamPlayers = playerRepository
                                       .Get()
                                       .Where(p => p.TeamId == firstTeamId)
                                       .ToList();

                var secondTeamPlayers = playerRepository
                                        .Get()
                                        .Where(p => p.TeamId == secondTeamId)
                                        .ToList();

                var players = firstTeamPlayers.Concat(secondTeamPlayers);

                foreach (var player in players)
                {
                    var points       = 0;
                    var activityType = GetRandomActivityType();
                    switch (activityType)
                    {
                    case PlayerActivity <string> .ActivityType.Playing:
                        points = GetRandomPoints();
                        break;

                    case PlayerActivity <string> .ActivityType.Reserve:
                        break;

                    case PlayerActivity <string> .ActivityType.Unused:
                        continue;
                    }

                    var playerActivity = new PlayerActivity <string>(player.Id, game.Id, points, activityType);
                    playerActivityRepository.Add(playerActivity);
                }
            }
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: drewdz/FieldDataTest
        private async Task SendScan(FieldActivity activity)
        {
            if ((activity == null) || (activity.State != ActivityState.Waiting))
            {
                return;
            }
            try
            {
                if (_PauseOnly)
                {
                    MessageBox.Show(this, "Click ok after scanning a lanyard.", "Scan Pause", MessageBoxButtons.OK);
                    activity.ReadyUp(DateTimeOffset.Now.ToUnixTimeMilliseconds());
                    return;
                }

                var frm = new InputForm("Barcode", "Scan/Enter Barcode", string.Empty);
                if (frm.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }
                //  create player activity object
                var player = new PlayerActivity
                {
                    ActivityId = activity.Id,
                    LanyardId  = frm.Result,
                    Scanned    = DateTimeOffset.UtcNow,
                    StartTime  = DateTime.UtcNow,
                    State      = 1
                };
                var s = Serializer.Serialize(player);
                //  create new player activity record
                using (var restService = new RestService())
                {
                    restService.EchoOn = true;
                    var result = await restService.PostAsync <ServiceResult <PlayerActivity>, PlayerActivity>(string.Format($"{_BaseUrl}playeractivity/set", "activity"), player);

                    if (result.Status != ServiceResultStatus.Success)
                    {
                        throw new Exception(result.Message);
                    }
                    activity.CurrentPlayer = result.Payload;
                    activity.ReadyUp(DateTimeOffset.Now.ToUnixTimeMilliseconds());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception: {ex}");
            }
        }
コード例 #9
0
ファイル: PlayerNode.cs プロジェクト: HAWGT7/CSPlusPlus
 internal PlayerNode(string JSON)
     : base(JSON)
 {
     SteamID      = GetString("steamid");
     Name         = GetString("name");
     ObserverSlot = GetInt32("observer_slot");
     Team         = GetEnum <PlayerTeam>("team");
     Clan         = GetString("clan");
     State        = new PlayerStateNode(_data?.SelectToken("state")?.ToString() ?? "{}");
     Weapons      = new WeaponsNode(_data?.SelectToken("weapons")?.ToString() ?? "{}");
     MatchStats   = new MatchStatsNode(_data?.SelectToken("match_stats")?.ToString() ?? "{}");
     Activity     = GetEnum <PlayerActivity>("activity");
     Position     = ParseVector(GetString("position"));
     Forward      = ParseVector(GetString("forward"));
 }
コード例 #10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            StringBuilder rules = new StringBuilder();

            rules.Append("Правила игры:\n1) Пройти от точки S до E за выделенное количество очков" +
                         "\n2) Переходы между точками отнимают у игрока определенное количество очков" +
                         "\n3) Нельзя сразу перейти от S к E" +
                         "\n4) При повторном прохождении карта перестраивается" +
                         "\n5) Если стало легко можно увеличить сложность" +
                         "\n6) Красным подсвечивается вершина, на которой сейчас игрок" +
                         "\nУдачи!");

            MessageBox.Show(rules.ToString());
            difficult.SelectedIndex = 0;
            playerActivity          = new PlayerActivity();
            SetUp();
        }
コード例 #11
0
        internal Player(string json_data) : base(json_data)
        {
            SteamID    = GetString("steamid");
            Name       = GetString("name");
            ProName    = GetString("pro_name");
            Activity   = GetEnum <PlayerActivity>("activity");
            Kills      = GetInt("kills");
            Deaths     = GetInt("deaths");
            Assists    = GetInt("assists");
            LastHits   = GetInt("last_hits");
            Denies     = GetInt("denies");
            KillStreak = GetInt("kill_streak");

            this.KillList = new Dictionary <int, int>();
            foreach (JValue kill in GetArray("kill_list"))
            {
                int id;
                if (int.TryParse(kill.Path.Replace("kill_list.victimid_", ""), out id))
                {
                    this.KillList.Add(id, kill.Value <int>());
                }
            }

            CommandsIssued      = GetInt("commands_issued");
            Team                = GetEnum <PlayerTeam>("team_name");
            Gold                = GetInt("gold");
            GoldReliable        = GetInt("gold_reliable");
            GoldUnreliable      = GetInt("gold_unreliable");
            GoldFromHeroKills   = GetInt("gold_from_hero_kills");
            GoldFromCreepKills  = GetInt("gold_from_creep_kills");
            GoldFromIncome      = GetInt("gold_from_income");
            GoldFromShared      = GetInt("gold_from_shared");
            GoldPerMinute       = GetInt("gpm");
            ExperiencePerMinute = GetInt("xpm");
            NetWorth            = GetInt("net_worth");
            HeroDamage          = GetInt("hero_damage");
            WardsPurchased      = GetInt("wards_purchased");
            WardsPlaced         = GetInt("wards_placed");
            WardsDestroyed      = GetInt("wards_destroyed");
            RunesActivated      = GetInt("runes_activated");
            CampsStacked        = GetInt("camps_stacked");
            SupportGoldSpent    = GetInt("support_gold_spent");
            GoldLostToDeath     = GetInt("gold_lost_to_death");
            GoldSpentOnBuybacks = GetInt("gold_spent_on_buybacks");
        }
コード例 #12
0
    void Savep2Data()
    {
        PlayerActivity go2 = GameObject.Find("Player2").GetComponent <PlayerActivity>();

        if (go2.score > 0)
        {
            p2Score = go2.score;
        }
        else
        {
            p2Score = 0;
        }
        p2ReadyToSave = true;
        if (p1ReadyToSave)
        {
            saveEverything();
        }
    }
コード例 #13
0
ファイル: Player.cs プロジェクト: TylerStewart/Dota2GSI
 internal Player(string json_data) : base(json_data)
 {
     SteamID = GetString("steamid");
     Name = GetString("name");
     Activity = GetEnum<PlayerActivity>("activity");
     Kills = GetInt("kills");
     Deaths = GetInt("deaths");
     Assists = GetInt("assists");
     LastHits = GetInt("last_hits");
     Denies = GetInt("denies");
     KillStreak = GetInt("kill_streak");
     Team = GetEnum<PlayerTeam>("team_name");
     Gold = GetInt("gold");
     GoldReliable = GetInt("gold_reliable");
     GoldUnreliable = GetInt("gold_unreliable");
     GoldPerMinute = GetInt("gpm");
     ExperiencePerMinute = GetInt("xpm");
 }
コード例 #14
0
ファイル: Player.cs プロジェクト: ajmwagar/Aurora
 internal Player_Dota2(string json_data) : base(json_data)
 {
     SteamID             = GetString("steamid");
     Name                = GetString("name");
     Activity            = GetEnum <PlayerActivity>("activity");
     Kills               = GetInt("kills");
     Deaths              = GetInt("deaths");
     Assists             = GetInt("assists");
     LastHits            = GetInt("last_hits");
     Denies              = GetInt("denies");
     KillStreak          = GetInt("kill_streak");
     Team                = GetEnum <PlayerTeam>("team_name");
     Gold                = GetInt("gold");
     GoldReliable        = GetInt("gold_reliable");
     GoldUnreliable      = GetInt("gold_unreliable");
     GoldPerMinute       = GetInt("gpm");
     ExperiencePerMinute = GetInt("xpm");
 }
コード例 #15
0
ファイル: Player.cs プロジェクト: e1ektr0/Dota2GSI
        internal Player(string json_data) : base(json_data)
        {
            SteamID    = GetString("steamid");
            Name       = GetString("name");
            ProName    = GetString("pro_name");
            Activity   = GetEnum <PlayerActivity>("activity");
            Kills      = GetInt("kills");
            Deaths     = GetInt("deaths");
            Assists    = GetInt("assists");
            LastHits   = GetInt("last_hits");
            Denies     = GetInt("denies");
            KillStreak = GetInt("kill_streak");

            this.KillList = new Dictionary <int, int>();
            foreach (JValue kill in GetArray("kill_list"))
            {
                int id;
                if (int.TryParse(kill.Path.Replace("kill_list.victimid_", ""), out id))
                {
                    this.KillList.Add(id, kill.Value <int>());
                }
                else
                {
                    System.Console.WriteLine("[DOTA2GSI] Warning, could not get victim ID! ID: " + kill.Path);
                }
            }

            Team                = GetEnum <PlayerTeam>("team_name");
            Gold                = GetInt("gold");
            GoldReliable        = GetInt("gold_reliable");
            GoldUnreliable      = GetInt("gold_unreliable");
            GoldPerMinute       = GetInt("gpm");
            ExperiencePerMinute = GetInt("xpm");

            NetWorth         = GetInt("net_worth");
            HeroDamage       = GetInt("hero_damage");
            SupportGoldSpent = GetInt("support_gold_spent");
            WardsPurchased   = GetInt("wards_purchased");
            WardsPlaced      = GetInt("wards_placed");
            WardsDestroyed   = GetInt("wards_destroyed");
            RunesActivated   = GetInt("runes_activated");
            CampsStacked     = GetInt("camps_stacked");
        }
コード例 #16
0
ファイル: MainForm.cs プロジェクト: drewdz/FieldDataTest
 private async Task DoneAction(PlayerActivity player)
 {
     try
     {
         if (_PauseOnly)
         {
             return;
         }
         //  update the player
         player.EndTime = DateTimeOffset.UtcNow;
         player.State   = 4;
         //  update it
         using (var restService = new RestService())
         {
             restService.EchoOn = true;
             await restService.PostAsync <PlayerActivity, PlayerActivity>(string.Format($"{_BaseUrl}playeractivity/set", "activity"), player);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Exception: {ex}");
     }
 }
コード例 #17
0
    private void OnCollisionEnter(Collision collision)
    {
        GameObject     player = collision.gameObject;
        PlayerActivity pa     = player.GetComponent <PlayerActivity>();

        vegetablesToChop = pa.vegetables;
        pa.vegetables    = new List <string>();
        pa.veg1.sprite   = Resources.Load <Sprite>("Sprites/emptySprite");
        pa.veg2.sprite   = Resources.Load <Sprite>("Sprites/emptySprite");
        string rString = "";

        //Give player veggies to deliver
        if (vegetablesToChop.Count == 0 && vegetablesChopped.Count > 0)
        {
            if (player.name == "Player1")
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "PickedUpIngredientsP1");
            }
            else
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "PickedUpIngredientsP2");
            }
            veg1.sprite       = Resources.Load <Sprite>("Sprites/emptySprite");
            veg2.sprite       = Resources.Load <Sprite>("Sprites/emptySprite");
            vegetablesChopped = new List <string>();
            rString           = "";
            updateUI(rString);
            return;
        }
        //Chop 1 vegetable
        if (vegetablesToChop.Count == 1)
        {
            veg1.sprite = AssignVegetable(vegetablesToChop[0]);
        }
        //Chop 2 vegetables
        if (vegetablesToChop.Count == 2)
        {
            veg1.sprite = AssignVegetable(vegetablesToChop[0]);
            veg2.sprite = AssignVegetable(vegetablesToChop[1]);
        }

        //Manage stored vegetables
        foreach (string s in vegetablesToChop)
        {
            vegetablesChopped.Add(s);
        }
        for (int i = 0; i < vegetablesChopped.Count; i++)
        {
            string s = vegetablesChopped[i];

            if (i == vegetablesChopped.Count - 1)
            {
                rString += s;
            }
            else
            {
                rString += s + ", ";
            }
        }

        if (gameObject.name == "CuttingBoard1" && vegetablesToChop.Count > 0)
        {
            if (player.name == "Player1")
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "ChopTimer1Start");
                updateUI(rString);
            }
            else
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "UIMustUseOwnP1");
            }
        }
        if (gameObject.name == "CuttingBoard2" && vegetablesToChop.Count > 0)
        {
            if (player.name == "Player2")
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "ChopTimer2Start");
                updateUI(rString);
            }
            else
            {
                NotificationCenter.DefaultCenter.PostNotification(this, "UIMustUseOwnP2");
            }
        }
        //So we know to run the timer twice
        if (vegetablesToChop.Count == 2)
        {
            NotificationCenter.DefaultCenter.PostNotification(this, "IsTwo");
        }
    }
コード例 #18
0
        private static async void MatchedLobby_DeltaUpdated(object sender, bool closed)
        {
            if (sender == null || !(sender is Lobby lobby))
            {
                Logger.Warn("Abnormal behavoir detected in Lobby's DeltaUpdated event handler: sender is either not a lobby or is null.");
                return;
            }

            // Temporary fix for Lobby class clearing this too early.
            List <SdlPlayer> players = lobby.Players.Select(x => x).ToList();

            if (closed)
            {
                try
                {
                    await(await Program.Client.GetChannelAsync(572536965833162753)).SendMessageAsync(
                        $"{string.Join(" ", players.Select(f => f.DiscordId.ToUserMention()))}\n" +
                        $"Closing the lobby because not enough players have joined the battle. Please try again by using %join.");

                    string activityDirectory = Directory.CreateDirectory(Path.Combine(Globals.AppPath, "Player Activity")).FullName;

                    foreach (SdlPlayer lobbyPlayer in players)
                    {
                        PlayerActivity playerActivity;
                        string         playerFile = Path.Combine(activityDirectory, $"{lobbyPlayer.DiscordId}.json");

                        if (File.Exists(playerFile))
                        {
                            playerActivity =
                                JsonConvert.DeserializeObject <PlayerActivity>(await File.ReadAllTextAsync(playerFile));
                        }
                        else
                        {
                            playerActivity = new PlayerActivity
                            {
                                PlayedSets = new List <DateTime>(),
                                Timeouts   = new List <DateTime>()
                            };
                        }

                        if (!playerActivity.Timeouts.Any() || playerActivity.Timeouts.All(e => e.Date != DateTime.UtcNow.Date))
                        {
                            playerActivity.Timeouts.Add(DateTime.UtcNow);
                        }

                        await File.WriteAllTextAsync(playerFile, JsonConvert.SerializeObject(playerActivity));
                    }

                    Logger.Info($"Recorded {players.Count} players timed out in lobby #{lobby.LobbyNumber}.");
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }

                return;
            }

            string message =
                $"{(lobby.CurrentDelta - 75) / 25 * 5} minutes have passed for lobby #{lobby.LobbyNumber}. The threshold has been increased by 25 to {lobby.CurrentDelta}.";

            DiscordEmbedBuilder builder = lobby.GetEmbedBuilder();

            await(await Program.Client.GetChannelAsync(572536965833162753)).SendMessageAsync(message, false, builder.Build());
        }
コード例 #19
0
 public List <string> GetFieldsToRequest(PlayerActivity activity)
 {
     return(nameOnly);
 }
コード例 #20
0
 public void SetPlayerActivity(PlayerActivity activity)
 {
     this.current_activity = activity;
 }
コード例 #21
0
ファイル: GameEvent_CSGO.cs プロジェクト: twigglius/Aurora
 public static void SetPlayerActivity(PlayerActivity activity)
 {
     GameEvent_CSGO.current_activity = activity;
 }
コード例 #22
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            //Handles animation
            player.UpdateAnimation(gameTime);

            //Get User input
            KeyboardState kbState = Keyboard.GetState();

            #region Current Game State FSM - also see corresponding FSM in Draw()
            switch (gameState)
            {
            // Start screen
            case (GameStates.StartScreen):
            {
                // If Enter is pressed (once), show Schwartz's dialogue intro.
                if (kbState.IsKeyDown(Keys.Enter) && prevKBState.IsKeyUp(Keys.Enter))
                {
                    gameState = GameStates.SchwartzIntroScreen;
                }

                break;
            }

            // Intro screen
            case (GameStates.SchwartzIntroScreen):
            {
                // If Enter is pressed (once), start the game.
                if (kbState.IsKeyDown(Keys.Enter) && prevKBState.IsKeyUp(Keys.Enter))
                {
                    gameState = GameStates.Playing;
                }

                break;
            }

            // Game screen
            case (GameStates.Playing):
            {
                // "Activate" the player FSM
                playerActivity = PlayerActivity.Active;
                break;
            }

            // First final selection screem
            case (GameStates.FinalSelectionScreen1):
            {
                // "Dectivate" the player FSM
                playerActivity = PlayerActivity.Idle;

                // If Y is pressed (once), go to the second final selection screen.
                if (kbState.IsKeyDown(Keys.Y) && prevKBState.IsKeyUp(Keys.Y))
                {
                    gameState = GameStates.FinalSelectionScreen2;
                }
                // If N is pressed (once), return to the game.
                else if (kbState.IsKeyDown(Keys.N) && prevKBState.IsKeyUp(Keys.N))
                {
                    // Nudge the player away from Schwartz's tile so
                    //		FinalSelectionScreen1 doesn't continuously trigger.
                    player.X += 50;
                    gameState = GameStates.Playing;
                }

                break;
            }

            // Second final selection screen
            case (GameStates.FinalSelectionScreen2):
            {
                // If E is pressed (once), the player loses.
                if (kbState.IsKeyDown(Keys.E) && prevKBState.IsKeyUp(Keys.E))
                {
                    gameState = GameStates.LoseScreen;
                }
                // If B is pressed (once), the player wins.
                else if (kbState.IsKeyDown(Keys.B) && prevKBState.IsKeyUp(Keys.B))
                {
                    gameState = GameStates.WinScreen;
                }
                // If H is pressed (once), the player loses.
                else if (kbState.IsKeyDown(Keys.H) && prevKBState.IsKeyUp(Keys.H))
                {
                    gameState = GameStates.LoseScreen;
                }
                // If C is pressed (once), the player loses.
                else if (kbState.IsKeyDown(Keys.C) && prevKBState.IsKeyUp(Keys.C))
                {
                    gameState = GameStates.LoseScreen;
                }

                break;
            }

            // Win screen
            case (GameStates.WinScreen):
            {
                // If Enter is pressed (once), the game exits.
                if (kbState.IsKeyDown(Keys.Enter) && prevKBState.IsKeyUp(Keys.Enter))
                {
                    Exit();
                }
                // If R is pressed (once), return to the start screen
                else if (kbState.IsKeyDown(Keys.R) && prevKBState.IsKeyUp(Keys.R))
                {
                    // Move player into starting position. Useful if
                    //		game is restarted from win/lose screens.
                    player.X  = playerLoc.X;
                    player.Y  = playerLoc.Y;
                    gameState = GameStates.StartScreen;
                }
                break;
            }

            // Lose screen
            case (GameStates.LoseScreen):
            {
                // If Enter is pressed (once), the game exits.
                if (kbState.IsKeyDown(Keys.Enter) && prevKBState.IsKeyUp(Keys.Enter))
                {
                    Exit();
                }
                // If R is pressed (once), return to the start screen
                else if (kbState.IsKeyDown(Keys.R) && prevKBState.IsKeyUp(Keys.R))
                {
                    // Move player into starting position. Useful if
                    //		game is restarted from win/lose screens.
                    player.X  = playerLoc.X;
                    player.Y  = playerLoc.Y;
                    gameState = GameStates.StartScreen;
                }
                break;
            }
            }
            #endregion

            #region Fail safe for if the player ends up outside the window screen
            if (playerTracker.X < 0)
            {
                player.X = 50;
                player.Y = 50;
            }
            if (playerTracker.Y < 0)
            {
                player.X = 50;
                player.Y = 50;
            }
            if (playerTracker.X > windowWidth)
            {
                player.X = 50;
                player.Y = 50;
            }
            if (playerTracker.Y > windowHeight)
            {
                player.X = 50;
                player.Y = 50;
            }
            #endregion

            #region Walk States FSM
            //Switch statement for Walking states
            switch (playerActivity)
            {
            case (PlayerActivity.Idle):
            {
                // Do nothing - player character is idle.
                // This prevents the player from moving their character
                //		while the start screen is showing.
                break;
            }

            case (PlayerActivity.Active):
            {
                // Player is now active and has access to movement.
                switch (player.State)
                {
                //Case for facing Down
                case PlayerStates.FaceDown:
                    //-----Transition to standing states--------
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }
                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }
                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }
                    //-----Transition to walking state---------
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.WalkDown;
                    }
                    break;

                //Case for facing right
                case PlayerStates.FaceRight:
                    //-----Transition to standing states--------
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }
                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }
                    //-----Transition to walking state---------
                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.WalkRight;
                    }
                    break;

                //Case for facing Left
                case PlayerStates.FaceLeft:
                    //-----Transition to standing states--------
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }
                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }
                    //-----Transition to walking state---------
                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.WalkLeft;
                    }
                    break;

                //Case for Facing Up
                case PlayerStates.FaceUp:
                    //-----Transition to standing states--------
                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }
                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }
                    //-----Transition to walking state---------
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.WalkUp;
                    }
                    break;


                //Case for walking Down
                case PlayerStates.WalkDown:
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.WalkDown;                                                        //Keeps Walking down
                    }
                    if (kbState.IsKeyUp(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;                                                        //Changes to facing down state
                    }
                    break;

                //Case for walking right
                case PlayerStates.WalkRight:
                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.WalkRight;                                                          //Keeps walking right
                    }
                    if (kbState.IsKeyUp(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;                                                          //Changes to facing right state
                    }
                    break;

                //Case for walking left
                case PlayerStates.WalkLeft:
                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.WalkLeft;                                                           //Keeps walking left
                    }
                    if (kbState.IsKeyUp(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;                                                           //Changes to left facing state
                    }
                    break;

                //Case for walking up
                case PlayerStates.WalkUp:
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.WalkUp;                                                             //Keeps walking up
                    }
                    if (kbState.IsKeyUp(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;                                                             //Changes to facing up
                    }
                    break;

                // Collision cases are similar to standing cases, but the
                //		player cannot walk in direction of the boundary.
                // Case for downwards border collision
                case (PlayerStates.BorderCollisionDown):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for upwards border collision
                case (PlayerStates.BorderCollisionUp):
                {
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for left border collision
                case (PlayerStates.BorderCollisionLeft):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for right border collision
                case (PlayerStates.BorderCollisionRight):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    break;
                }

                // Case for downwards wall collision
                case (PlayerStates.WallCollisionDown):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for upwards wall collision
                case (PlayerStates.WallCollisionUp):
                {
                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for left wall collision
                case (PlayerStates.WallCollisionLeft):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    if (kbState.IsKeyDown(Keys.D))
                    {
                        player.State = PlayerStates.FaceRight;
                    }

                    break;
                }

                // Case for right wall collision
                case (PlayerStates.WallCollisionRight):
                {
                    if (kbState.IsKeyDown(Keys.W))
                    {
                        player.State = PlayerStates.FaceUp;
                    }

                    if (kbState.IsKeyDown(Keys.A))
                    {
                        player.State = PlayerStates.FaceLeft;
                    }

                    if (kbState.IsKeyDown(Keys.S))
                    {
                        player.State = PlayerStates.FaceDown;
                    }

                    break;
                }
                }
                break;
            }
            }


            #endregion

            #region Collision FSM
            //Logic for determining if hitting a wall in the list of walls
            bool WallCollided = false;

            // Refresh this variable each time so previous frames do not
            //		interfere with the current.
            professorInteraction = false;


            //Switching on player.States to check for movement of walking and
            //		collisions
            switch (player.State)
            {
            //Walking down = moving in the positive direction of the y-axis.
            case (PlayerStates.WalkDown):
            {
                //Checks for player collision with window boundary
                if (player.Y >= windowHeight - player.PlayerHeight)
                {
                    player.State = PlayerStates.BorderCollisionDown;
                }
                //Checks for player collision with wall boundaries and professor tiles
                else
                {
                    foreach (Rectangle wall in wallBoundaries)
                    {
                        //If player is intersecting with wall, set to wall collision state so player can't move
                        if (playerTracker.Intersects(wall))
                        {
                            player.State = PlayerStates.WallCollisionDown;
                            player.Y     = wall.Y - player.PlayerHeight - BounceFactor;     //Bounces player out of the wall collision
                            WallCollided = true;
                            break;
                        }
                    }

                    //if not colliding then player can walk
                    if (WallCollided == false)
                    {
                        player.Y += PlayerSpeed;
                    }
                }
                break;
            }

            //Walking up = moving in the negative direction of the y-axis.
            case (PlayerStates.WalkUp):
            {
                //Checks for player collision with wall boundaries and professor tiles
                if (player.Y <= 0)
                {
                    player.State = PlayerStates.BorderCollisionUp;
                }
                //Checks for player collision with window boundary
                else
                {
                    foreach (Rectangle wall in wallBoundaries)
                    {
                        //If player is intersecting with wall, set to wall collision state so player can't move
                        if (playerTracker.Intersects(wall))
                        {
                            player.State = PlayerStates.WallCollisionUp;
                            player.Y     = wall.Y + wall.Height + BounceFactor;                                         //Bounces player out of the wall collision
                            WallCollided = true;
                            break;
                        }
                    }

                    //if not colliding then player can walk
                    if (WallCollided == false)
                    {
                        player.Y -= PlayerSpeed;
                    }
                }
                break;
            }

            //Positive X integer for walking right
            case (PlayerStates.WalkRight):
            {
                //Checks for player collision with window boundary
                if (player.X >= windowWidth - player.PlayerWidth)
                {
                    player.State = PlayerStates.BorderCollisionRight;
                }
                //Checks for player collision with wall boundaries and professor tiles
                else
                {
                    foreach (Rectangle wall in wallBoundaries)
                    {
                        //If player is intersecting with wall, set to wall collision state so player can't move
                        if (playerTracker.Intersects(wall))
                        {
                            player.State = PlayerStates.WallCollisionRight;
                            player.X     = wall.X - player.PlayerWidth - BounceFactor;     //Bounces the player out of the collision
                            WallCollided = true;
                        }
                    }

                    if (WallCollided == false)
                    {
                        player.X += PlayerSpeed;
                    }
                }
                break;
            }

            //Negative X integer for walking left
            case (PlayerStates.WalkLeft):
            {
                //Checks for player collision with window boundary
                if (player.X <= 0)
                {
                    player.State = PlayerStates.BorderCollisionLeft;
                }
                //Checks for player collision with wall boundaries and professor tiles
                else
                {
                    foreach (Rectangle wall in wallBoundaries)
                    {
                        //If player is intersecting with wall, set to wall collision state so player can't move
                        if (playerTracker.Intersects(wall))
                        {
                            player.State = PlayerStates.WallCollisionLeft;
                            player.X     = wall.X + wall.Width + BounceFactor;     //Bounces player out of collision
                            WallCollided = true;
                        }
                    }

                    if (WallCollided == false)
                    {
                        player.X -= PlayerSpeed;
                    }
                }
                break;
            }
            }
            // Rectangle to track player's current position
            playerTracker = new Rectangle((int)player.X, (int)player.Y, player.PlayerWidth, player.PlayerHeight);
            #endregion

            #region Code to check for when professors are being interacted with
            // This loops and checks to see if the player Rectangle contains a
            //		professor Rectangle. If it does, the corresponding professor
            //		is set as "active" and the Draw portion of the code will
            //		draw the corresponding dialogue box to the screen.
            for (int i = 0; i < professorTileRectangles.Count; i++)
            {
                // If player Rectangle contains a professor tile...
                if (playerTracker.Contains(professorTileRectangles[i].Location))
                {
                    // Set professorInteraction to true to acknowledge the interaction.
                    // This triggers Draw() to draw the dialogue to the screen.
                    professorInteraction = true;

                    // Because the indices of entries in professorTileRectangles
                    //		correspond to those in enum Professors, parse the respective
                    //		Professor's name from the index using Enum.TryParse.
                    activeProfessor = (Professors)Enum.Parse(typeof(Professors), i.ToString());
                }
            }
            #endregion

            // Keyboard state at the end of this frame becomes the previous keyboard state for the next.
            prevKBState = kbState;

            base.Update(gameTime);
        }
コード例 #23
0
 public void SetPlayerActivity(PlayerActivity activity)
 {
     this.current_activity = activity;
 }