protected override void OnUpdateFrame(OpenTK.FrameEventArgs e) { animator.Update(e.Time); if (isPlotUpdated) { isPlotUpdated = false; plotSurface.RedrawPlotSurface(); } if (isStatusTextChanged) { isStatusTextChanged = false; PositionStatusText(); } }
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 }
protected override void OnRenderFrame(OpenTK.FrameEventArgs e) { lock (animator) { animator.Update(e.Time); } GL.Clear(ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); // Draw game description text if (!string.IsNullOrEmpty(Settings.GameDescription)) { // Draw box background GL.Color3(Themes.Black.Background); GL.Begin(BeginMode.Quads); GL.Vertex2(0, 0); GL.Vertex2(0, boardTop + 1); GL.Vertex2(this.Width, boardTop + 1); GL.Vertex2(this.Width, 0); GL.End(); // Draw description text GL.PushMatrix(); GL.Translate(descriptionPoint.X, descriptionPoint.Y, 0); printer.Print(Settings.GameDescription, descriptionFont, Themes.Black.Foreground); GL.PopMatrix(); } // Draw entire board for (int pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++) { var currentPixel = pixels[pixelIndex]; double pixelLeft = boardLeft + (currentPixel.TileLeft * pixelSize); double pixelTop = boardTop + (currentPixel.TileTop * pixelSize); // Draw pixel background GL.Color3(currentPixel.Red, currentPixel.Green, currentPixel.Blue); GL.Disable(EnableCap.Texture2D); GL.Begin(BeginMode.Quads); GL.Vertex2(pixelLeft, pixelTop); GL.Vertex2(pixelLeft, pixelTop + pixelSize); GL.Vertex2(pixelLeft + pixelSize, pixelTop + pixelSize); GL.Vertex2(pixelLeft + pixelSize, pixelTop); GL.End(); // Don't draw anything else for fixed pixels if (currentPixel.State == PixelState.Fixed) { continue; } // Draw player GL.Color3(Color.White); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, playerTextureIds[currentPixel.PlayerId]); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 0); GL.Vertex2(pixelLeft + textureOffset, pixelTop + textureOffset); GL.TexCoord2(0, 1); GL.Vertex2(pixelLeft + textureOffset, pixelTop + pixelSize - textureOffset); GL.TexCoord2(1, 1); GL.Vertex2(pixelLeft + pixelSize - textureOffset, pixelTop + pixelSize - textureOffset); GL.TexCoord2(1, 0); GL.Vertex2(pixelLeft + pixelSize - textureOffset, pixelTop + textureOffset); GL.End(); // Draw button box double buttonLeft = pixelLeft + pixelSize - buttonSize; double buttonTop = pixelTop + pixelSize - buttonSize; GL.Disable(EnableCap.Texture2D); GL.Color3(buttonTheme.Background); GL.Begin(BeginMode.Quads); GL.Vertex2(buttonLeft, buttonTop); GL.Vertex2(buttonLeft, buttonTop + buttonSize); GL.Vertex2(buttonLeft + buttonSize, buttonTop + buttonSize); GL.Vertex2(buttonLeft + buttonSize, buttonTop); GL.End(); // Draw box outline GL.Color3(buttonTheme.Border); GL.LineWidth(1); GL.Begin(BeginMode.LineLoop); GL.Vertex2(buttonLeft, buttonTop); GL.Vertex2(buttonLeft, buttonTop + buttonSize); GL.Vertex2(buttonLeft + buttonSize, buttonTop + buttonSize); GL.Vertex2(buttonLeft + buttonSize, buttonTop); GL.End(); // Draw button number var buttonString = currentPixel.GetButtonString(); if (!string.IsNullOrEmpty(buttonString)) { var buttonTextSize = printer.Measure(buttonString, pixelFont)[0]; GL.PushMatrix(); GL.Translate(buttonLeft + ((buttonSize - buttonTextSize.Width) / 2.0f) - 1.0f, buttonTop + ((buttonSize - buttonTextSize.Height) / 2.0f) - 1.0f, 0); printer.Print(buttonString, pixelFont, buttonTheme.Foreground); GL.PopMatrix(); } } // Draw board lines GL.Disable(EnableCap.Texture2D); GL.Color3(Color.DarkBlue); GL.LineWidth(2); for (int tileIndex = 0; tileIndex <= tiles; tileIndex++) { GL.Begin(BeginMode.Lines); // Vertical line GL.Vertex2(boardLeft + (tileIndex * pixelSize), boardTop); GL.Vertex2(boardLeft + (tileIndex * pixelSize), boardTop + boardSize); // Horizontal line GL.Vertex2(boardLeft, boardTop + (tileIndex * pixelSize)); GL.Vertex2(boardLeft + boardSize, boardTop + (tileIndex * pixelSize)); GL.End(); } SwapBuffers(); }