- Timestamp:
- 2013-07-26 12:21:45 (10 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4713 r4728 104 104 input.RegisterKeyboardKey(Keys.Right); 105 105 input.RegisterKeyboardKey(Keys.Enter); 106 input.RegisterKeyboardKey(Keys.X); 106 107 107 108 input.RegisterMouseKey(MouseButtons.Middle); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Resources.cs
r4703 r4728 20 20 public static Texture2D SPRITE_GUI_LOGO { get; private set; } 21 21 public static Texture2D SPRITE_GUI_BACKGROUND_INGAME { get; private set; } 22 public static Texture2D SPRITE_GUI_INSCTRUCTIONS { get; private set; } 22 23 23 24 public static void LoadResources(ContentManager cm, RenderHelper renderer) … … 37 38 SPRITE_GUI_LOGO = cm.Load<Texture2D>("gui/logo"); 38 39 SPRITE_GUI_BACKGROUND_INGAME = cm.Load<Texture2D>("gui/inGameBackGround"); 40 SPRITE_GUI_INSCTRUCTIONS = cm.Load<Texture2D>("gui/instructions"); 39 41 } 40 42 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Guis/GuiMainScreen.cs
r4703 r4728 17 17 private const string HELP1 = "<UP,DOWN> SCROLL"; 18 18 private const string HELP2 = "<ENTER> SELECT"; 19 private const string HELP3 = "<X> Main menu"; 19 20 private const string AUTHOR = "Game by Denis Zhidkikh"; 20 21 … … 71 72 public override void Update() 72 73 { 73 if ( InputHandler.HasKeyBeenPressed(Keys.Up))74 if (!showInstructions) 74 75 { 75 currentOption--; 76 if (currentOption < 0) currentOption = 2; 76 if (InputHandler.HasKeyBeenPressed(Keys.Up)) 77 { 78 currentOption--; 79 if (currentOption < 0) currentOption = 2; 80 } 81 else if (InputHandler.HasKeyBeenPressed(Keys.Down)) 82 { 83 currentOption++; 84 if (currentOption > 2) currentOption = 0; 85 } 86 else if (InputHandler.HasKeyBeenPressed(Keys.Enter)) 87 { 88 if (game.IsGameRunning) 89 actionsInGame[currentOption].Invoke(); 90 else 91 actionsStart[currentOption].Invoke(); 92 } 77 93 } 78 else if (InputHandler.HasKeyBeenPressed(Keys.Down))94 else 79 95 { 80 currentOption++; 81 if (currentOption > 2) currentOption = 0; 82 } 83 else if (InputHandler.HasKeyBeenPressed(Keys.Enter)) 84 { 85 if (game.IsGameRunning) 86 actionsInGame[currentOption].Invoke(); 87 else 88 actionsStart[currentOption].Invoke(); 96 if (InputHandler.HasKeyBeenPressed(Keys.X)) 97 showInstructions = false; 89 98 } 90 99 } … … 94 103 if (!game.IsGameRunning) 95 104 { 96 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_BACKGROUND, backgroundRect, Color.White); 97 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_LOGO, logoPos, Color.White); 98 renderer.SpriteBatch.DrawString(Resources.FONT, infoText, infoPos, Color.White); 99 renderer.SpriteBatch.DrawString(Resources.FONT, helpText, helpPos, Color.White); 105 if (!showInstructions) 106 { 107 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_BACKGROUND, backgroundRect, Color.White); 108 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_LOGO, logoPos, Color.White); 109 renderer.SpriteBatch.DrawString(Resources.FONT, infoText, infoPos, Color.White); 110 renderer.SpriteBatch.DrawString(Resources.FONT, helpText, helpPos, Color.White); 100 111 101 for (int i = 0; i < optionsStart.Length; i++) 112 for (int i = 0; i < optionsStart.Length; i++) 113 { 114 if (i == currentOption) 115 renderer.SpriteBatch.DrawString(Resources.FONT, ARROW, optionPos + optionOffset * i + arrowOffset, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 116 renderer.SpriteBatch.DrawString(Resources.FONT, optionsStart[i], optionPos + optionOffset * i, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 117 } 118 } 119 else 102 120 { 103 if (i == currentOption) 104 renderer.SpriteBatch.DrawString(Resources.FONT, ARROW, optionPos + optionOffset * i + arrowOffset, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 105 renderer.SpriteBatch.DrawString(Resources.FONT, optionsStart[i], optionPos + optionOffset * i, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 121 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_INSCTRUCTIONS, backgroundRect, Color.White); 122 renderer.SpriteBatch.DrawString(Resources.FONT, HELP3, helpPos, Color.White); 106 123 } 107 124 } 108 125 else 109 126 { 110 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_BACKGROUND_INGAME, backgroundRect, Color.White); 111 renderer.SpriteBatch.DrawString(Resources.FONT, helpText, helpPos, Color.White); 112 for (int i = 0; i < optionsInGame.Length; i++) 113 { 114 if (i == currentOption) 115 renderer.SpriteBatch.DrawString(Resources.FONT, ARROW, optionPos + optionOffset * i + arrowOffset, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 116 renderer.SpriteBatch.DrawString(Resources.FONT, optionsInGame[i], optionPos + optionOffset * i, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 117 } 127 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_BACKGROUND_INGAME, backgroundRect, Color.White); 128 renderer.SpriteBatch.DrawString(Resources.FONT, helpText, helpPos, Color.White); 129 for (int i = 0; i < optionsInGame.Length; i++) 130 { 131 if (i == currentOption) 132 renderer.SpriteBatch.DrawString(Resources.FONT, ARROW, optionPos + optionOffset * i + arrowOffset, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 133 renderer.SpriteBatch.DrawString(Resources.FONT, optionsInGame[i], optionPos + optionOffset * i, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 134 } 135 118 136 } 119 137 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Guis/GuiPlayer.cs
r4694 r4728 7 7 using CastleMaster.Graphics; 8 8 using Microsoft.Xna.Framework.Graphics; 9 using CastleMaster.Units; 9 10 10 11 namespace CastleMaster.Guis … … 12 13 public class GuiPlayer : Gui 13 14 { 15 private class HealthMeter 16 { 17 private Unit unit; 18 19 private Rectangle unitHealthGreenRectangle, unitHealthRedRectangle; 20 private Vector2 unitHealthPos, unitRedHealthPos, unitTextPos; 21 private int oldUnitHealthBarWidth = HEALTH_BAR_WIDTH; 22 private string text; 23 24 public HealthMeter(Unit unit, Vector2 renderPos, string text) 25 { 26 this.text = text; 27 this.unit = unit; 28 unitHealthGreenRectangle = new Rectangle(0, 0, HEALTH_BAR_WIDTH, 4); 29 unitHealthRedRectangle = new Rectangle(HEALTH_BAR_WIDTH, 4, 0, 4); 30 unitHealthPos = renderPos; 31 unitRedHealthPos = new Vector2(unitHealthPos.X + HEALTH_BAR_WIDTH, unitHealthPos.Y); 32 unitTextPos = new Vector2(unitHealthPos.X - text.Length * 13, unitHealthPos.Y - 5); 33 } 34 35 public void Update() 36 { 37 unitHealthGreenRectangle.Width = (int)((unit.Health / (float)unit.MaxHealth) * HEALTH_BAR_WIDTH); 38 if (unitHealthGreenRectangle.Width != oldUnitHealthBarWidth) 39 { 40 oldUnitHealthBarWidth = unitHealthGreenRectangle.Width; 41 unitRedHealthPos.X = unitHealthPos.X + unitHealthGreenRectangle.Width * SCALE; 42 unitHealthRedRectangle.X = unitHealthGreenRectangle.Width; 43 unitHealthRedRectangle.Width = HEALTH_BAR_WIDTH - unitHealthGreenRectangle.Width; 44 } 45 } 46 47 public void Render(RenderHelper renderer) 48 { 49 renderer.SpriteBatch.DrawString(Resources.FONT, text, unitTextPos, Color.White); 50 if (unitHealthGreenRectangle.Width > 0) 51 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, unitHealthPos, unitHealthGreenRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 52 if (unitHealthRedRectangle.Width > 0) 53 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, unitRedHealthPos, unitHealthRedRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 54 } 55 } 56 14 57 private const string NEWLINE = "\n"; 15 58 private const string ICON_COINS = "&"; … … 28 71 private Vector2 itemStatsPos; 29 72 30 private Rectangle kingHealthGreenRectangle, kingHealthRedRectangle; 31 private Vector2 kingHealthPos, kingRedHealthPos, kingTextPos; 32 private int oldKingHealthBarWidth = HEALTH_BAR_WIDTH; 33 34 private Rectangle storeGreenHealthRectangle, storeRedHealthRectangle; 35 private Vector2 storeHealthPos, storeRedHealthPos, storeTextPos; 36 private int oldStoreHealthBarWidth = HEALTH_BAR_WIDTH; 37 38 private Rectangle armoryGreenHealthRectangle, armoryRedHealthRectangle; 39 private Vector2 armoryHealthPos, armoryRedHealthPos, armoryTextPos; 40 private int oldArmoryHealthBarWidth = HEALTH_BAR_WIDTH; 73 private HealthMeter kingHealthMeter, storeHealthMeter, armoryHealthMeter; 41 74 42 75 public GuiPlayer(GuiManager manager, Player player) … … 49 82 itemStatsPos = new Vector2(0, Game.HEIGHT - GUI_BAR_HEIGHT + 5); 50 83 51 kingHealthGreenRectangle = new Rectangle(0, 0, HEALTH_BAR_WIDTH, 4); 52 kingHealthRedRectangle = new Rectangle(HEALTH_BAR_WIDTH, 4, 0, 4); 53 kingHealthPos = new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 20); 54 kingRedHealthPos = new Vector2(kingHealthPos.X + HEALTH_BAR_WIDTH, kingHealthPos.Y); 55 kingTextPos = new Vector2(kingHealthPos.X - KING_TEXT.Length * 13, kingHealthPos.Y - 5); 56 57 storeGreenHealthRectangle = new Rectangle(0, 0, HEALTH_BAR_WIDTH, 4); 58 storeRedHealthRectangle = new Rectangle(HEALTH_BAR_WIDTH, 4, 0, 4); 59 storeHealthPos = new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 40); 60 storeRedHealthPos = new Vector2(storeHealthPos.X + HEALTH_BAR_WIDTH, storeHealthPos.Y); 61 storeTextPos = new Vector2(storeHealthPos.X - STORE_TEXT.Length * 13, storeHealthPos.Y - 5); 62 63 armoryGreenHealthRectangle = new Rectangle(0, 0, HEALTH_BAR_WIDTH, 4); 64 armoryRedHealthRectangle = new Rectangle(HEALTH_BAR_WIDTH, 4, 0, 4); 65 armoryHealthPos = new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 60); 66 armoryRedHealthPos = new Vector2(armoryHealthPos.X + HEALTH_BAR_WIDTH, armoryHealthPos.Y); 67 armoryTextPos = new Vector2(armoryHealthPos.X - ARMORY_TEXT.Length * 13, armoryHealthPos.Y - 5); 84 kingHealthMeter = new HealthMeter(player.King, new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 20), KING_TEXT); 85 storeHealthMeter = new HealthMeter(player.Store, new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 40), STORE_TEXT); 86 armoryHealthMeter = new HealthMeter(player.Armory, new Vector2(Game.WIDTH - HEALTH_BAR_WIDTH * SCALE - 10, Game.HEIGHT - GUI_BAR_HEIGHT + 60), ARMORY_TEXT); 68 87 } 69 88 … … 76 95 } 77 96 97 78 98 public override void Update() 79 99 { … … 81 101 itemStats.Append(ICON_COINS).Append(player.CoinsAmount).Append(NEWLINE); 82 102 itemStats.Append(ICON_WOOD).Append(player.LumberAmount); 83 kingHealthGreenRectangle.Width = (int)((player.King.Health / (float)player.King.MaxHealth) * HEALTH_BAR_WIDTH); 84 if (kingHealthGreenRectangle.Width != oldKingHealthBarWidth) 85 { 86 oldKingHealthBarWidth = kingHealthGreenRectangle.Width; 87 kingRedHealthPos.X = kingHealthPos.X + kingHealthGreenRectangle.Width * SCALE; 88 kingHealthRedRectangle.X = kingHealthGreenRectangle.Width; 89 kingHealthRedRectangle.Width = HEALTH_BAR_WIDTH - kingHealthGreenRectangle.Width; 90 } 91 92 storeGreenHealthRectangle.Width = (int)((player.Store.Health / (float)player.Store.MaxHealth) * HEALTH_BAR_WIDTH); 93 if (storeGreenHealthRectangle.Width != oldStoreHealthBarWidth) 94 { 95 oldStoreHealthBarWidth = storeGreenHealthRectangle.Width; 96 storeRedHealthPos.X = storeHealthPos.X + storeGreenHealthRectangle.Width * SCALE; 97 storeRedHealthRectangle.X = storeGreenHealthRectangle.Width; 98 storeRedHealthRectangle.Width = HEALTH_BAR_WIDTH - storeGreenHealthRectangle.Width; 99 } 100 101 armoryGreenHealthRectangle.Width = (int)((player.Armory.Health / (float)player.Armory.MaxHealth) * HEALTH_BAR_WIDTH); 102 if (armoryGreenHealthRectangle.Width != oldArmoryHealthBarWidth) 103 { 104 oldArmoryHealthBarWidth = armoryGreenHealthRectangle.Width; 105 armoryRedHealthPos.X = armoryHealthPos.X + armoryGreenHealthRectangle.Width * SCALE; 106 armoryRedHealthRectangle.X = armoryGreenHealthRectangle.Width; 107 armoryRedHealthRectangle.Width = HEALTH_BAR_WIDTH - armoryGreenHealthRectangle.Width; 108 } 103 kingHealthMeter.Update(); 104 storeHealthMeter.Update(); 105 armoryHealthMeter.Update(); 109 106 } 110 107 … … 113 110 renderer.SpriteBatch.Draw(RenderHelper.EmptyTexture, screenRect, guiCol); 114 111 renderer.SpriteBatch.DrawString(Resources.FONT, itemStats, itemStatsPos, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0); 115 116 renderer.SpriteBatch.DrawString(Resources.FONT, KING_TEXT, kingTextPos, Color.White);117 if (kingHealthGreenRectangle.Width > 0)118 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, kingHealthPos, kingHealthGreenRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0);119 if (kingHealthRedRectangle.Width > 0)120 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, kingRedHealthPos, kingHealthRedRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0);121 112 122 renderer.SpriteBatch.DrawString(Resources.FONT, STORE_TEXT, storeTextPos, Color.White); 123 if (storeGreenHealthRectangle.Width > 0) 124 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, storeHealthPos, storeGreenHealthRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 125 if (storeRedHealthRectangle.Width > 0) 126 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, storeRedHealthPos, storeRedHealthRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 113 kingHealthMeter.Render(renderer); 127 114 128 renderer.SpriteBatch.DrawString(Resources.FONT, ARMORY_TEXT, armoryTextPos, Color.White); 129 if (armoryGreenHealthRectangle.Width > 0) 130 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, armoryHealthPos, armoryGreenHealthRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 131 if (armoryRedHealthRectangle.Width > 0) 132 renderer.SpriteBatch.Draw(renderer.RegisteredSpriteSheets[Resources.SPRITESHEET_HEALTH].SheetTexture, armoryRedHealthPos, armoryRedHealthRectangle, Color.White, 0.0F, Vector2.Zero, SCALE, SpriteEffects.None, 0); 115 storeHealthMeter.Render(renderer); 116 117 armoryHealthMeter.Render(renderer); 133 118 } 134 119 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj
r4716 r4728 126 126 </Compile> 127 127 </ItemGroup> 128 <ItemGroup> 129 <Compile Include="gui\instructions.png"> 130 <Name>instructions</Name> 131 <Importer>TextureImporter</Importer> 132 <Processor>TextureProcessor</Processor> 133 </Compile> 134 </ItemGroup> 128 135 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 129 136 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.