Ejemplo n.º 1
0
        protected void ProcessPlayerButton(int playerId, int button)
        {
            var player = players[playerId];

            // Button 0 comes in as 10, so this will force it to be
            // interpreted as a 0 input.
            player.Answer = button % 10;

            animator.PropertyTo(player, "HighlightOpacity", 0, 0.2, 0, 0, AfterDarkAnimation);
        }
Ejemplo n.º 2
0
        protected void ProcessPlayerButton(int playerId, int button)
        {
            var timeStamp = inputTimer.ElapsedMilliseconds;

            // Find the first pixel with a matching player id and button
            var matchingPixel = pixels.FirstOrDefault(p =>
                                                      (p.PlayerId == playerId) && (p.Button == button));

            if ((matchingPixel != null) && (matchingPixel.State != PixelState.Fixed))
            {
                // Flip the pixel
                matchingPixel.State = (matchingPixel.State == PixelState.On) ?
                                      PixelState.Off : PixelState.On;

                if (dataWriter != null)
                {
                    // Record input
                    dataWriter.WriteText(string.Format("{0} {1}, {2}, {3}, {4}",
                                                       timeStamp, playerId, matchingPixel.TileLeft,
                                                       matchingPixel.TileTop, matchingPixel.State));
                }

                lock (animator)
                {
                    animator.PropertyTo(matchingPixel, "AllColors",
                                        (matchingPixel.State == PixelState.On) ? 1 : 0, 0.3f);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void OnUpdateFrame(OpenTK.FrameEventArgs e)
        {
            animator.Update(e.Time);

            if (gameState == GameState.Running)
            {
                // Move players
                foreach (var player in players)
                {
                    if (player.State == PlayerState.ReadyToTravel)
                    {
                        player.Position       = FindOpenPosition(PlayerState.Traveling);
                        player.State          = PlayerState.Traveling;
                        player.TravelTimeLeft = Settings.TravelTime;
                        player.Opacity        = 0;

                        animator.PropertyTo(player, "TravelTimeLeft", 0,
                                            player.TravelTimeLeft, 0, 0, OnPlayerFinishTravel);

                        // Set up fade
                        animator.PropertyTo(player, "Opacity", 1, playerTeleportTime);

                        var shadow = playerShadows[player.Id];
                        shadow.Left    = player.Left;
                        shadow.Top     = player.Top;
                        shadow.Opacity = 1;
                        shadow.IsGray  = false;

                        animator.PropertyTo(shadow, "Opacity", 0, playerTeleportTime);

                        // Record player movement
                        if (dataWriter != null)
                        {
                            dataWriter.WriteText(string.Format("{0}, {1}, {2}",
                                                               inputTimer.ElapsedMilliseconds, "Travel", player.Id, player.PlotNumber + 1));
                        }
                    }
                    else if (player.State == PlayerState.FinishedTraveling)
                    {
                        player.Position = FindOpenPosition(PlayerState.WaitingForInput, player.PlotNumber);
                        player.State    = PlayerState.WaitingForInput;
                        player.Opacity  = 0;

                        // Set up fade
                        animator.PropertyTo(player, "Opacity", 1, playerTeleportTime);

                        var shadow = playerShadows[player.Id];
                        shadow.Left    = player.Left;
                        shadow.Top     = player.Top;
                        shadow.Opacity = 1;
                        shadow.IsGray  = true;

                        animator.PropertyTo(shadow, "Opacity", 0, playerTeleportTime);

                        // Record player movement
                        if (dataWriter != null)
                        {
                            dataWriter.WriteText(string.Format("{0}, {1}, {2}, {3}",
                                                               inputTimer.ElapsedMilliseconds, "Move", player.Id, player.PlotNumber + 1));
                        }
                    }
                }

                // Give players food
                if (isFoodReady)
                {
                    isFoodReady = false;

                    foreach (var player in players)
                    {
                        player.FoodFound = 0;
                    }

                    foreach (var emptyFood in emptyPlotFood)
                    {
                        emptyFood.Count = 0;
                    }

                    for (int foodNumber = 0; foodNumber < Settings.FoodRate; foodNumber++)
                    {
                        var randomNumber    = rand.NextDouble();
                        var luckyPlotNumber = 0;

                        for (int plotIndex = 0;
                             plotIndex < Settings.PlotProbabilities[plotProbabilityIndex].Count;
                             plotIndex++)
                        {
                            if (randomNumber <= Settings.PlotProbabilities[plotProbabilityIndex][plotIndex])
                            {
                                luckyPlotNumber = plotIndex;
                                break;
                            }
                        }

                        var luckyPlayer = players.Where(p => (p.PlotNumber == luckyPlotNumber) &&
                                                        (p.State == PlayerState.WaitingForInput))
                                          .OrderBy(p => rand.Next()).FirstOrDefault();

                        if (luckyPlayer == null)
                        {
                            var emptyFood = emptyPlotFood[luckyPlotNumber];

                            emptyFood.FoodTextureId = foodTextureIds[rand.Next(0, foodTextureIds.Length)];
                            emptyFood.Opacity       = 1;
                            emptyFood.Count++;

                            animator.PropertyTo(emptyFood, "Opacity", 0, 0.2, 0, 0.8, null);

                            emptyFood.IsPresent = true;

                            // No one was on the plot. Too bad!
                            continue;
                        }

                        luckyPlayer.Score++;
                        luckyPlayer.FoodFound++;
                        luckyPlayer.FoodOpacity   = 1;
                        luckyPlayer.FoodTextureId = foodTextureIds[rand.Next(foodTextureIds.Length)];

                        animator.PropertyTo(luckyPlayer, "TopOffset", playerSize * 0.3, 0.1, 1, 0, null);
                        animator.PropertyTo(luckyPlayer, "FoodOpacity", 0, 0.2, 0, 0.8, null);

                        // Record food disbursment
                        if (dataWriter != null)
                        {
                            dataWriter.WriteText(string.Format("{0}, {1}, {2}, {3}",
                                                               inputTimer.ElapsedMilliseconds, "Food", luckyPlayer.Id,
                                                               luckyPlayer.PlotNumber + 1));
                        }
                    }
                } // if (isFoodReady)
            }
            else if (gameState == GameState.Finished)
            {
                endGameState.TextureId = Textures.Load(new Bitmap(this.Width, this.Height,
                                                                  System.Drawing.Imaging.PixelFormat.Format32bppArgb));

                GL.BindTexture(TextureTarget.Texture2D, endGameState.TextureId);
                GL.CopyTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                                  0, 0, this.Width, this.Height, 0);

                gameState = GameState.Blurring;
            }
            else if (gameState == GameState.BlurFinished)
            {
                double scoreBoardWidth = (this.Width * 0.85), scoreBoardHeight = (this.Height * 0.85);

                endGameState.ScoreBoardLeft = (this.Width - scoreBoardWidth) / 2.0;
                endGameState.ScoreBoardTop  = (this.Height - scoreBoardHeight) / 2.0;

                int    playersPerColumn = (int)(scoreBoardHeight / playerSlotSize) - 1;
                double columnOffset     = scoreBoardWidth / Math.Ceiling((double)Settings.Players / (double)playersPerColumn);

                int scoreRow = 0, scoreColumn = 0;
                var playerScoreOrder = players.OrderByDescending(p => p.Score).Select(p => p.Id).ToList();

                // Position players
                foreach (var playerIndex in playerScoreOrder)
                {
                    var player = players[playerIndex];

                    var slotLeft = endGameState.ScoreBoardLeft + (scoreColumn * columnOffset);
                    var slotTop  = endGameState.ScoreBoardTop + (scoreRow * playerSlotSize);

                    player.Left = slotLeft + ((playerSlotSize - playerSize) / 2.0);
                    player.Top  = slotTop + ((playerSlotSize - playerSize) / 2.0);

                    scoreRow++;

                    if (scoreRow > playersPerColumn)
                    {
                        scoreRow = 0;
                        scoreColumn++;
                    }
                }

                animator.PropertyTo(endGameState, "ScoreBoardOpacity", 0.9, 0.5);
                animator.PropertyTo(endGameState, "PlayerScoreBoardOpacity", 1, 1.0);

                gameState = GameState.ShowingScoreBoard;
            } // BlurFinished
        }