public void Render(GraphicsDevice graphicsDevice) { // If we don't have _P, grab it from the current gameInstance. // We can't do this in the constructor because we are created in the property bag's constructor! if (_P == null) { _P = gameInstance.propertyBag; } // Draw the UI. spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); // Draw the crosshair. spriteBatch.Draw(texCrosshairs, new Rectangle(graphicsDevice.Viewport.Width / 2 - texCrosshairs.Width / 2, graphicsDevice.Viewport.Height / 2 - texCrosshairs.Height / 2, texCrosshairs.Width, texCrosshairs.Height), Color.White); // If equipped, draw the tool. switch (_P.playerTools[_P.playerToolSelected]) { case PlayerTools.Detonator: RenderDetonator(graphicsDevice, spriteBatch); break; case PlayerTools.ProspectingRadar: RenderProspectron(graphicsDevice, spriteBatch); break; case PlayerTools.ConstructionGun: RenderConstructionGun(graphicsDevice, spriteBatch, _P.playerBlocks[_P.playerBlockSelected]); break; case PlayerTools.DeconstructionGun: RenderConstructionGun(graphicsDevice, spriteBatch, BlockType.None); break; default: { // Draw info about what we have equipped. PlayerTools currentTool = _P.playerTools[_P.playerToolSelected]; BlockType currentBlock = _P.playerBlocks[_P.playerBlockSelected]; string equipment = currentTool.ToString(); if (currentTool == PlayerTools.ConstructionGun) { equipment += " - " + currentBlock.ToString() + " (" + BlockInformation.GetCost(currentBlock) + ")"; } RenderMessageCenter(spriteBatch, equipment, new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height - 20), Color.White, Color.Black); } break; } if (gameInstance.DrawFrameRate) { RenderMessageCenter(spriteBatch, String.Format("FPS: {0:000}", gameInstance.FrameRate), new Vector2(60, graphicsDevice.Viewport.Height - 20), Color.Gray, Color.Black); } // Show the altimeter. int altitude = (int)(_P.playerPosition.Y - 64 + Defines.GROUND_LEVEL); RenderMessageCenter(spriteBatch, String.Format("ALTITUDE: {0:00}", altitude), new Vector2(graphicsDevice.Viewport.Width - 90, graphicsDevice.Viewport.Height - 20), altitude >= 0 ? Color.Gray : Defines.IM_RED, Color.Black); // Draw bank instructions. if (_P.AtBankTerminal()) { RenderMessageCenter(spriteBatch, "8: DEPOSIT 50 ORE 9: WITHDRAW 50 ORE", new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2 + 60), Color.White, Color.Black); } // Are they trying to change class when they cannot? //if (Keyboard.GetState().IsKeyDown(Keys.M) && _P.playerPosition.Y <= 64 - Defines.GROUND_LEVEL && _P.chatMode == ChatMessageType.None) // RenderMessageCenter(spriteBatch, "YOU CANNOT CHANGE YOUR CLASS BELOW THE SURFACE", new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2 + 90), Color.White, Color.Black); // Draw the text-based information panel. int textStart = (graphicsDevice.Viewport.Width - 1024) / 2; spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, 20), Color.Black); spriteBatch.DrawString(uiFont, "ORE: " + _P.playerOre + "/" + _P.playerOreMax, new Vector2(textStart + 3, 2), Color.White); spriteBatch.DrawString(uiFont, "LOOT: $" + _P.playerCash, new Vector2(textStart + 170, 2), Color.White); spriteBatch.DrawString(uiFont, "WEIGHT: " + _P.playerWeight + "/" + _P.playerWeightMax, new Vector2(textStart + 340, 2), Color.White); spriteBatch.DrawString(uiFont, "TEAM ORE: " + _P.teamOre, new Vector2(textStart + 515, 2), Color.White); spriteBatch.DrawString(uiFont, _P.redName + ": $" + _P.teamRedCash, new Vector2(textStart + 700, 2), _P.red); // Defines.IM_RED); spriteBatch.DrawString(uiFont, _P.blueName + ": $" + _P.teamBlueCash, new Vector2(textStart + 860, 2), _P.blue); // Defines.IM_BLUE); // Draw player information. if ((Keyboard.GetState().IsKeyDown(Keys.Tab) && _P.screenEffect == ScreenEffect.None) || _P.teamWinners != PlayerTeam.None) { spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), new Color(Color.Black, 0.7f)); //Server name RenderMessageCenter(spriteBatch, _P.serverName, new Vector2(graphicsDevice.Viewport.Width / 2, 32), _P.playerTeam == PlayerTeam.Blue ? _P.blue : _P.red, Color.Black);//Defines.IM_BLUE : Defines.IM_RED, Color.Black); if (_P.teamWinners != PlayerTeam.None) { string teamName = _P.teamWinners == PlayerTeam.Red ? "RED" : "BLUE"; Color teamColor = _P.teamWinners == PlayerTeam.Red ? _P.red : _P.blue;//Defines.IM_RED : Defines.IM_BLUE; string gameOverMessage = "GAME OVER - " + teamName + " TEAM WINS!"; RenderMessageCenter(spriteBatch, gameOverMessage, new Vector2(graphicsDevice.Viewport.Width / 2, 150), teamColor, new Color(0, 0, 0, 0)); } int drawY = 200; foreach (Player p in _P.playerList.Values) { if (p.Team != PlayerTeam.Red) { continue; } RenderMessageCenter(spriteBatch, p.Handle + " ( $" + p.Score + " )", new Vector2(graphicsDevice.Viewport.Width / 4, drawY), _P.red, new Color(0, 0, 0, 0));//Defines.IM_RED drawY += 35; } drawY = 200; foreach (Player p in _P.playerList.Values) { if (p.Team != PlayerTeam.Blue) { continue; } RenderMessageCenter(spriteBatch, p.Handle + " ( $" + p.Score + " )", new Vector2(graphicsDevice.Viewport.Width * 3 / 4, drawY), _P.blue, new Color(0, 0, 0, 0)); //Defines.IM_BLUE drawY += 35; } } // Draw the chat buffer. if (_P.chatMode == ChatMessageType.SayAll) { spriteBatch.DrawString(uiFont, "ALL> " + _P.chatEntryBuffer, new Vector2(22, graphicsDevice.Viewport.Height - 98), Color.Black); spriteBatch.DrawString(uiFont, "ALL> " + _P.chatEntryBuffer, new Vector2(20, graphicsDevice.Viewport.Height - 100), Color.White); } else if (_P.chatMode == ChatMessageType.SayBlueTeam || _P.chatMode == ChatMessageType.SayRedTeam) { spriteBatch.DrawString(uiFont, "TEAM> " + _P.chatEntryBuffer, new Vector2(22, graphicsDevice.Viewport.Height - 98), Color.Black); spriteBatch.DrawString(uiFont, "TEAM> " + _P.chatEntryBuffer, new Vector2(20, graphicsDevice.Viewport.Height - 100), Color.White); } if (_P.chatMode != ChatMessageType.None) { drawChat(_P.chatFullBuffer, graphicsDevice); /*for (int i = 0; i < _P.chatFullBuffer.Count; i++) * { * Color chatColor = Color.White; * chatColor = _P.chatFullBuffer[i].type == ChatMessageType.SayAll ? Color.White : _P.chatFullBuffer[i].type == ChatMessageType.SayRedTeam ? InfiniminerGame.IM_RED : InfiniminerGame.IM_BLUE; * * spriteBatch.DrawString(uiFont, _P.chatFullBuffer[i].message, new Vector2(22, graphicsDevice.Viewport.Height - 114 - 16 * i), Color.Black); * spriteBatch.DrawString(uiFont, _P.chatFullBuffer[i].message, new Vector2(20, graphicsDevice.Viewport.Height - 116 - 16 * i), chatColor); * }*/ } else { drawChat(_P.chatBuffer, graphicsDevice); } // Draw the player radar. spriteBatch.Draw(texRadarBackground, new Vector2(10, 30), Color.White); foreach (Player p in _P.playerList.Values) { if (p.Team == _P.playerTeam && p.Alive) { RenderRadarBlip(spriteBatch, p.ID == _P.playerMyId ? _P.playerPosition : p.Position, p.Team == PlayerTeam.Red ? _P.red : _P.blue, p.Ping > 0, ""); //Defines.IM_RED : Defines.IM_BLUE, p.Ping > 0, ""); } } foreach (KeyValuePair <Vector3, Beacon> bPair in _P.beaconList) { if (bPair.Value.Team == _P.playerTeam) { RenderRadarBlip(spriteBatch, bPair.Key, Color.White, false, bPair.Value.ID); } } RenderRadarBlip(spriteBatch, new Vector3(100000, 0, 32), Color.White, false, "NORTH"); spriteBatch.Draw(texRadarForeground, new Vector2(10, 30), Color.White); // Draw escape message. if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { RenderMessageCenter(spriteBatch, "PRESS Y TO CONFIRM THAT YOU WANT TO QUIT.", new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2 + 30), Color.White, Color.Black); RenderMessageCenter(spriteBatch, "PRESS K TO COMMIT PIXELCIDE.", new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2 + 80), Color.White, Color.Black); } // Draw the current screen effect. if (_P.screenEffect == ScreenEffect.Death) { Color drawColor = new Color(1 - (float)_P.screenEffectCounter * 0.5f, 0f, 0f); spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), drawColor); if (_P.screenEffectCounter >= 2) { RenderMessageCenter(spriteBatch, "You have died. Click to respawn.", new Vector2(graphicsDevice.Viewport.Width / 2, graphicsDevice.Viewport.Height / 2), Color.White, Color.Black); } } if (_P.screenEffect == ScreenEffect.Teleport || _P.screenEffect == ScreenEffect.Explosion) { Color drawColor = new Color(1, 1, 1, 1 - (float)_P.screenEffectCounter * 0.5f); spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), drawColor); if (_P.screenEffectCounter > 2) { _P.screenEffect = ScreenEffect.None; } } if (_P.screenEffect == ScreenEffect.Fall) { Color drawColor = new Color(1, 0, 0, 1 - (float)_P.screenEffectCounter * 0.5f); spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), drawColor); if (_P.screenEffectCounter > 2) { _P.screenEffect = ScreenEffect.None; } } // Draw the help screen. if (Keyboard.GetState().IsKeyDown(Keys.F1)) { spriteBatch.Draw(texBlank, new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), Color.Black); spriteBatch.Draw(texHelp, drawRect, Color.White); } spriteBatch.End(); }
public BlockEngine(InfiniminerGame gameInstance) { this.gameInstance = gameInstance; // Initialize the block list. downloadList = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE]; blockList = new BlockType[MAPSIZE, MAPSIZE, MAPSIZE]; for (ushort i = 0; i < MAPSIZE; i++) { for (ushort j = 0; j < MAPSIZE; j++) { for (ushort k = 0; k < MAPSIZE; k++) { downloadList[i, j, k] = BlockType.None; blockList[i, j, k] = BlockType.None; } } } // Initialize the face lists. faceMap = new Dictionary <uint, bool> [(byte)BlockTexture.MAXIMUM, NUMREGIONS]; for (BlockTexture blockTexture = BlockTexture.None; blockTexture < BlockTexture.MAXIMUM; blockTexture++) { for (int r = 0; r < NUMREGIONS; r++) { faceMap[(byte)blockTexture, r] = new Dictionary <uint, bool>(); } } // Initialize the texture map. blockTextureMap = new BlockTexture[(byte)BlockType.MAXIMUM, 6]; for (BlockType blockType = BlockType.None; blockType < BlockType.MAXIMUM; blockType++) { for (BlockFaceDirection faceDir = BlockFaceDirection.XIncreasing; faceDir < BlockFaceDirection.MAXIMUM; faceDir++) { blockTextureMap[(byte)blockType, (byte)faceDir] = BlockInformation.GetTexture(blockType, faceDir); } } // Load the textures we'll use. blockTextures = new IMTexture[(byte)BlockTexture.MAXIMUM]; blockTextures[(byte)BlockTexture.None] = new IMTexture(null); blockTextures[(byte)BlockTexture.Dirt] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_dirt")); blockTextures[(byte)BlockTexture.Rock] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_rock")); blockTextures[(byte)BlockTexture.Ore] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ore")); blockTextures[(byte)BlockTexture.Gold] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_silver")); blockTextures[(byte)BlockTexture.Diamond] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_diamond")); blockTextures[(byte)BlockTexture.HomeRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_home_red")); blockTextures[(byte)BlockTexture.HomeBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_home_blue")); blockTextures[(byte)BlockTexture.SolidRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_red")); blockTextures[(byte)BlockTexture.SolidBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_blue")); blockTextures[(byte)BlockTexture.Ladder] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ladder")); blockTextures[(byte)BlockTexture.LadderTop] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_ladder_top")); blockTextures[(byte)BlockTexture.Spikes] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_spikes")); blockTextures[(byte)BlockTexture.Jump] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_jump")); blockTextures[(byte)BlockTexture.JumpTop] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_jump_top")); blockTextures[(byte)BlockTexture.Explosive] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_explosive")); blockTextures[(byte)BlockTexture.Metal] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_metal")); blockTextures[(byte)BlockTexture.DirtSign] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_dirt_sign")); blockTextures[(byte)BlockTexture.BankTopRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_top_red")); blockTextures[(byte)BlockTexture.BankLeftRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_left_red")); blockTextures[(byte)BlockTexture.BankFrontRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_front_red")); blockTextures[(byte)BlockTexture.BankRightRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_right_red")); blockTextures[(byte)BlockTexture.BankBackRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_back_red")); blockTextures[(byte)BlockTexture.BankTopBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_top_blue")); blockTextures[(byte)BlockTexture.BankLeftBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_left_blue")); blockTextures[(byte)BlockTexture.BankFrontBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_front_blue")); blockTextures[(byte)BlockTexture.BankRightBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_right_blue")); blockTextures[(byte)BlockTexture.BankBackBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_bank_back_blue")); blockTextures[(byte)BlockTexture.TeleSideA] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_a")); blockTextures[(byte)BlockTexture.TeleSideB] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_b")); blockTextures[(byte)BlockTexture.TeleTop] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_top")); blockTextures[(byte)BlockTexture.TeleBottom] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_teleporter_bottom")); blockTextures[(byte)BlockTexture.Lava] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_lava")); blockTextures[(byte)BlockTexture.Road] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road")); blockTextures[(byte)BlockTexture.RoadTop] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road_top")); blockTextures[(byte)BlockTexture.RoadBottom] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_road_bottom")); blockTextures[(byte)BlockTexture.BeaconRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_beacon_top_red")); blockTextures[(byte)BlockTexture.BeaconBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_beacon_top_blue")); blockTextures[(byte)BlockTexture.TransRed] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_trans_red")); blockTextures[(byte)BlockTexture.TransBlue] = new IMTexture(gameInstance.Content.Load <Texture2D>("blocks/tex_block_trans_blue")); // Load our effects. basicEffect = gameInstance.Content.Load <Effect>("effect_basic"); // Build vertex lists. vertexBuffers = new DynamicVertexBuffer[(byte)BlockTexture.MAXIMUM, NUMREGIONS]; vertexListDirty = new bool[(byte)BlockTexture.MAXIMUM, NUMREGIONS]; for (int i = 0; i < (byte)BlockTexture.MAXIMUM; i++) { for (int j = 0; j < NUMREGIONS; j++) { vertexListDirty[i, j] = true; } } // Initialize any graphics stuff. vertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements()); // Initialize the bloom engine. if (gameInstance.RenderPretty) { bloomPosteffect = new BloomComponent(); bloomPosteffect.Load(gameInstance.GraphicsDevice, gameInstance.Content); } else { bloomPosteffect = null; } }