- Timestamp:
- 2013-09-01 18:40:38 (8 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster
- Files:
-
- 7 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/AgressiveState.cs
r4740 r4753 26 26 get 27 27 { 28 List<MobWarrior> mobUnits = AI.GetUnits ByType<MobWarrior>();28 List<MobWarrior> mobUnits = AI.GetUnits<MobWarrior>(); 29 29 30 30 if (AI.CoinsAmount >= 200) … … 65 65 public override void OnStateChosen() 66 66 { 67 warriors = AI.GetUnits ByType<MobWarrior>();68 rangers = AI.GetUnits ByType<MobRanger>();67 warriors = AI.GetUnits<MobWarrior>(); 68 rangers = AI.GetUnits<MobRanger>(); 69 69 } 70 70 71 71 public override void OnStateReChosen() 72 72 { 73 warriors = AI.GetUnits ByType<MobWarrior>();74 rangers = AI.GetUnits ByType<MobRanger>();73 warriors = AI.GetUnits<MobWarrior>(); 74 rangers = AI.GetUnits<MobRanger>(); 75 75 } 76 76 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/CollectiveState.cs
r4694 r4753 41 41 public override void OnStateChosen() 42 42 { 43 woodCutters = AI.GetUnits ByType<MobWoodcutter>();44 warriors = AI.GetUnits ByType<MobWarrior>();45 rangers = AI.GetUnits ByType<MobRanger>();43 woodCutters = AI.GetUnits<MobWoodcutter>(); 44 warriors = AI.GetUnits<MobWarrior>(); 45 rangers = AI.GetUnits<MobRanger>(); 46 46 } 47 47 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/DefensiveState.cs
r4694 r4753 26 26 get 27 27 { 28 List<Mob> mobUnits = AI.GetUnits ByType<Mob>();28 List<Mob> mobUnits = AI.GetUnits<Mob>(); 29 29 int importance = IMPORTANCE_LOW; 30 30 … … 39 39 public override void OnStateChosen() 40 40 { 41 warriors = AI.GetUnits ByType<MobWarrior>();42 rangers = AI.GetUnits ByType<MobRanger>();41 warriors = AI.GetUnits<MobWarrior>(); 42 rangers = AI.GetUnits<MobRanger>(); 43 43 44 44 while (!AI.Armory.IsDestroyed && warriors.Count + rangers.Count < 30 && AI.CoinsAmount >= UnitArmory.PRICE_WARRIOR) -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4752 r4753 1 #region Information2 /* Castle Master by Denis Zhidkikh3 *4 * Controls:5 * Use W, A, S, D to move around the map6 * Hold Shift while moving to move faster7 * Hold middle mouse button and drag to move the map8 * Scroll to zoom in/out9 * Click on unit with right mouse button to select it10 * Hold Ctrl while clicking to choose multiple units11 * Give orders to your units by clicking left mouse button (ordering button) on other units/entities12 *13 * Classes:14 * Woodcutter:15 * - Costs 5 gold16 * - Has 20 health17 * - Really fast18 * - Order to cut by clicking on the tree with the ordering button19 * - Order to walk by clicking on the empty tile with the ordering button20 * - After cutting first tree woodcutter will begin looking for nearby trees to cut21 *22 * Warrior:23 * - Costs 20 gold24 * - Has 50 health25 * - Slow26 * - Order to attack enemy units by clicking on them with the ordering button27 * - After killing will stay in place until he either gets another order or gets attacked by the enemy28 *29 * Ranger:30 * - Costs 15 gold31 * - Has 30 health32 * - Medium speed33 * - Attacks the same way the warrior does34 *35 * Units:36 * King (and the castle):37 * - Has 400 health38 * - Doesn't do anything39 * - The game ends after being destroyed40 *41 * Store (large wooden building):42 * - Has 400 health43 * - Can exchange wood to gold44 * - Selecting it will open the exchange window45 * - Cannot exchange wood to gold after being destroyed46 *47 * Armory (small stone building):48 * - Has 400 health49 * - Uses money to buy woodcutters, warriors and rangers50 * - Selecting it will open the armory window51 * - Cannot buy more units after being destroyed52 *53 * Objective:54 * Win game by destroying enemy's castle. Make it easier by killing enemy's woodcutters and destroying the store and/or armory.55 *56 */57 58 #endregion59 60 1 using CastleMaster.Graphics; 61 2 using CastleMaster.Input; … … 72 13 using CastleMaster.Guis; 73 14 74 // NOTES:75 // If VSYNC problems/Lag problems go to line 73 to enable/disable VSYNC76 15 namespace CastleMaster 77 16 { … … 319 258 camera.RenderSelelctor(renderer); 320 259 level.RenderEntities(camera, renderer); 260 foreach (Player p in players) 261 if (p != null) p.Render(renderer); 321 262 } 322 263 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Resources.cs
r4752 r4753 24 24 public static Texture2D SPRITE_GUI_BACKGROUND_INGAME { get; private set; } 25 25 public static Texture2D SPRITE_GUI_INSCTRUCTIONS { get; private set; } 26 public static Texture2D SPRITE_HIGHTLIGHT { get; private set; } 27 28 public static Texture2D SPRITE_PAGE_WELCOME { get; private set; } 29 public static Texture2D SPRITE_PAGE_CONTROLS { get; private set; } 30 public static Texture2D SPRITE_PAGE_GUI { get; private set; } 31 public static Texture2D SPRITE_PAGE_BUILDINGS { get; private set; } 32 public static Texture2D SPRITE_PAGE_UNITS { get; private set; } 26 33 27 34 public static void LoadResources(ContentManager cm, RenderHelper renderer) … … 45 52 SPRITE_GUI_BACKGROUND_INGAME = cm.Load<Texture2D>("gui/inGameBackGround"); 46 53 SPRITE_GUI_INSCTRUCTIONS = cm.Load<Texture2D>("gui/instructions"); 54 SPRITE_HIGHTLIGHT = cm.Load<Texture2D>("gui/highLightBox"); 55 56 SPRITE_PAGE_WELCOME = cm.Load<Texture2D>("gui/howto/page_welcome"); 57 SPRITE_PAGE_CONTROLS = cm.Load<Texture2D>("gui/howto/page_controls"); 58 SPRITE_PAGE_GUI = cm.Load<Texture2D>("gui/howto/page_gui"); 59 SPRITE_PAGE_BUILDINGS = cm.Load<Texture2D>("gui/howto/page_buildings"); 60 SPRITE_PAGE_UNITS = cm.Load<Texture2D>("gui/howto/page_units"); 47 61 } 48 62 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Guis/GuiInstructions.cs
r4752 r4753 1 using System; 1 using CastleMaster.Graphics; 2 using CastleMaster.Input; 3 using Microsoft.Xna.Framework; 4 using System; 2 5 using System.Collections.Generic; 3 6 using System.Linq; 4 7 using System.Text; 8 using System.Windows.Forms; 9 using Microsoft.Xna.Framework.Graphics; 5 10 6 11 namespace CastleMaster.Guis … … 8 13 public class GuiInstructions : Gui 9 14 { 10 public GuiInstructions(GuiManager manager) 15 private const String HELP_MOVE = "<LEFT, RIGHT> Switch Pages"; 16 private const String HELP_CLOSE = "<X> Main menu"; 17 private const String NAME = "Instructions"; 18 private const String PAGE = "Page"; 19 private const char AST = '/'; 20 21 private GuiMainScreen mainMenu; 22 private Rectangle backGroundRect; 23 private Vector2 helpPos, pageNumPos, helpPos2; 24 private StringBuilder pageNumText; 25 private int currentPage = 0; 26 private Texture2D[] pages; 27 28 public GuiInstructions(GuiMainScreen mainMenu, GuiManager manager) 11 29 : base(manager) 12 30 { 31 this.mainMenu = mainMenu; 32 backGroundRect = new Rectangle(0, 0, Game.WIDTH, Game.HEIGHT); 33 helpPos = new Vector2(10, Game.HEIGHT - 50); 13 34 35 pages = new Texture2D[] { Resources.SPRITE_PAGE_WELCOME, Resources.SPRITE_PAGE_CONTROLS, Resources.SPRITE_PAGE_GUI, Resources.SPRITE_PAGE_BUILDINGS, Resources.SPRITE_PAGE_UNITS }; 36 pageNumText = new StringBuilder(PAGE).Append(" 1/").Append(pages.Length); 37 pageNumPos = new Vector2(Game.WIDTH - 150, Game.HEIGHT - 50); 38 39 helpPos2 = new Vector2(helpPos.X, helpPos.Y + 16); 40 } 41 42 public override int Importance 43 { 44 get 45 { 46 return Gui.IMPORTANCE_HIGH; 47 } 48 } 49 50 private void ShowMainMenu() 51 { 52 Remove(); 53 manager.AddGui(mainMenu, true, true); 54 } 55 56 public override void Update() 57 { 58 if (InputHandler.HasKeyBeenPressed(Keys.X)) 59 ShowMainMenu(); 60 61 if (InputHandler.HasKeyBeenPressed(Keys.Right)) 62 { 63 currentPage++; 64 if (currentPage >= pages.Length) 65 currentPage = 0; 66 67 pageNumText.Clear().Append(PAGE).Append(' ').Append(currentPage + 1).Append(AST).Append(pages.Length); 68 } 69 else if (InputHandler.HasKeyBeenPressed(Keys.Left)) 70 { 71 currentPage--; 72 if (currentPage < 0) 73 currentPage = pages.Length - 1; 74 pageNumText.Clear().Append(PAGE).Append(' ').Append(currentPage + 1).Append(AST).Append(pages.Length); 75 } 76 77 } 78 79 public override void Render(RenderHelper renderer) 80 { 81 renderer.SpriteBatch.Draw(pages[currentPage], backGroundRect, Color.White); 82 83 renderer.SpriteBatch.DrawString(Resources.FONT, HELP_CLOSE, helpPos, Color.White); 84 renderer.SpriteBatch.DrawString(Resources.FONT, pageNumText, pageNumPos, Color.White); 85 renderer.SpriteBatch.DrawString(Resources.FONT, HELP_MOVE, helpPos2, Color.White); 86 } 87 } 88 89 internal class Page 90 { 91 public virtual void Render(RenderHelper renderer) { } 92 } 93 94 internal class Page1 : Page 95 { 96 private const string TEST = "Hello, world!"; 97 98 public override void Render(RenderHelper renderer) 99 { 100 renderer.SpriteBatch.DrawString(Resources.FONT, TEST, new Vector2(10, 100), Color.White); 14 101 } 15 102 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Guis/GuiMainScreen.cs
r4752 r4753 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";20 19 private const string AUTHOR = "Game by Denis Zhidkikh"; 21 20 … … 28 27 private Vector2 logoPos, infoPos, helpPos, optionPos, optionOffset, arrowOffset; 29 28 private StringBuilder infoText, helpText; 30 private bool showInstructions = false;29 private GuiInstructions guiInstructions; 31 30 32 31 public GuiMainScreen(GuiManager manager, Game game) … … 34 33 { 35 34 this.game = game; 35 36 guiInstructions = new GuiInstructions(this, manager); 37 36 38 actionsStart = new Action[] { game.StartGame, ShowInstructions, game.Exit }; 37 actionsInGame = new Action[] { Re move, ReturnToMain, game.Exit };39 actionsInGame = new Action[] { ReturnToGame, ReturnToMain, game.Exit }; 38 40 backgroundRect = new Rectangle(0, 0, Game.WIDTH, Game.HEIGHT); 39 41 logoPos = new Vector2(Game.WIDTH / 2 - 225, 10); … … 61 63 public void ShowInstructions() 62 64 { 63 showInstructions = true; 65 Remove(); 66 manager.AddGui(guiInstructions, true, true); 64 67 } 65 68 … … 70 73 } 71 74 75 public void ReturnToGame() 76 { 77 Remove(); 78 game.IsGamePaused = false; 79 } 80 72 81 public override void Update() 73 82 { 74 if (!showInstructions)75 {76 83 if (InputHandler.HasKeyBeenPressed(Keys.Up)) 77 84 { … … 91 98 actionsStart[currentOption].Invoke(); 92 99 } 93 }94 else95 {96 if (InputHandler.HasKeyBeenPressed(Keys.X))97 showInstructions = false;98 }99 100 } 100 101 … … 103 104 if (!game.IsGameRunning) 104 105 { 105 if (!showInstructions)106 {107 106 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_BACKGROUND, backgroundRect, Color.White); 108 107 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_LOGO, logoPos, Color.White); … … 116 115 renderer.SpriteBatch.DrawString(Resources.FONT, optionsStart[i], optionPos + optionOffset * i, Color.White, 0.0F, Vector2.Zero, 1.5F, SpriteEffects.None, 0.0F); 117 116 } 118 }119 else120 {121 renderer.SpriteBatch.Draw(Resources.SPRITE_GUI_INSCTRUCTIONS, backgroundRect, Color.White);122 renderer.SpriteBatch.DrawString(Resources.FONT, HELP3, helpPos, Color.White);123 }124 117 } 125 118 else -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/MathHelpers/FastFunctions.cs
r4535 r4753 1 1 2 using Microsoft.Xna.Framework; 3 using System; 2 4 namespace CastleMaster.MathHelpers 3 5 { … … 12 14 return ag | r | b; 13 15 } 16 17 public static Rectangle RectangleFromPoints(Point p0, Point p1) 18 { 19 int width = Math.Abs(p1.X - p0.X); 20 int height = Math.Abs(p1.Y - p0.Y); 21 22 int x = p0.X; 23 int y = p0.Y; 24 25 if (p1.X < p0.X) 26 x = p1.X; 27 if (p1.Y < p0.Y) 28 y = p1.Y; 29 30 return new Rectangle(x, y, width, height); 31 } 14 32 } 15 33 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Physics/BoundingRectangle.cs
r4581 r4753 15 15 this.x1 = x1; 16 16 this.z1 = z1; 17 } 18 19 public BoundingRectangle(Point p0, Point p1, BoundingRectangleOwner owner) 20 { 21 this.owner = owner; 22 this.x0 = p1.X < p0.X ? p1.X : p0.X; 23 this.z0 = p1.Y < p0.Y ? p1.Y : p0.Y; 24 this.x1 = p1.X > p0.X ? p1.X : p0.X; 25 this.z1 = p1.Y > p0.Y ? p1.Y : p0.Y; 17 26 } 18 27 … … 68 77 } 69 78 79 public BoundingRectangle Translate(Vector2 vec) 80 { 81 this.x0 += vec.X; 82 this.z0 += vec.Y; 83 this.x1 += vec.X; 84 this.z1 += vec.Y; 85 86 return this; 87 } 88 70 89 public static BoundingRectangle operator +(BoundingRectangle br, Vector2 vec) 71 90 { -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/Player.cs
r4694 r4753 16 16 17 17 public const int SPAWN_WOODCUTTER = 0; 18 public const int SPAWN_WARRIOR = 1;18 public const int SPAWN_WARRIOR = 1; 19 19 public const int SPAWN_RANGER = 2; 20 20 … … 34 34 LumberAmount = START_LUMBER; 35 35 CoinsAmount = 20; 36 36 37 37 spawnPoints = new Point[3]; 38 38 … … 66 66 public virtual void OnLevelLoaded() { } 67 67 68 public List<T> GetUnits ByType<T>() where T : Unit68 public List<T> GetUnits<T>() where T : Unit 69 69 { 70 70 List<T> result = new List<T>(); 71 71 72 72 foreach (Unit u in AvailableUnits) 73 if (typeof(T).IsAssignableFrom(u.GetType())) 74 result.Add((T)u); 73 { 74 T unit = u as T; 75 if (unit != null) 76 result.Add(unit); 77 } 75 78 76 79 return result; 77 80 } 78 81 79 public virtual void Update() 80 { 81 }82 public virtual void Update() { } 83 84 public virtual void Render(RenderHelper renderer) { } 82 85 83 86 public abstract Unit SelectUnit(Team team); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerReal.cs
r4694 r4753 11 11 using CastleMaster.Units.Mobs; 12 12 using System.Diagnostics; 13 using CastleMaster.Physics; 14 using CastleMaster.MathHelpers; 13 15 14 16 namespace CastleMaster.Players … … 32 34 } 33 35 36 private bool trackBox = false; 37 private Point oldPoint, newPoint; 34 38 public override void Update() 35 39 { … … 63 67 } 64 68 69 65 70 if (InputHandler.HasMouseButtonBeenPressed(MouseButtons.Right)) 66 71 { 67 Unit u = SelectUnit(Team); 68 69 if (InputHandler.IsKeyDown(Keys.ControlKey) && u != null && u is Mob) 72 if (InputHandler.IsKeyDown(Keys.ControlKey)) 70 73 { 71 if ( selectedUnit != null)74 if (!trackBox) 72 75 { 73 selectedUnit.OnFocusLost(); 74 selectedUnit.IsSelected = false; 75 selectedUnit = null; 76 trackBox = true; 77 oldPoint = InputHandler.MousePos; 76 78 } 77 selectedMobUnits.Add((Mob)u);78 u.IsSelected = true;79 u.OnFocus();80 79 } 81 80 else 82 81 { 82 Unit u = SelectUnit(Team); 83 83 84 selectedMobUnits.ForEach(delegate(Mob m) 84 85 { … … 105 106 u.OnFocus(); 106 107 } 108 } 109 } 110 111 if (trackBox && InputHandler.IsMouseButtonDown(MouseButtons.Right) && InputHandler.IsKeyDown(Keys.ControlKey)) 112 { 113 newPoint = InputHandler.MousePos; 114 } 115 else if (trackBox && (!InputHandler.IsMouseButtonDown(MouseButtons.Right) || !InputHandler.IsKeyDown(Keys.ControlKey))) 116 { 117 trackBox = false; 118 List<Mob> selectedMobs = SelectMobs(new BoundingRectangle(oldPoint, newPoint, null)); 119 120 if (selectedMobs.Count > 0) 121 { 122 if (selectedUnit != null) 123 { 124 selectedUnit.OnFocusLost(); 125 selectedUnit.IsSelected = false; 126 selectedUnit = null; 127 } 128 129 selectedMobUnits.ForEach(delegate(Mob m) 130 { 131 m.OnFocusLost(); 132 m.IsSelected = false; 133 }); 134 selectedMobUnits.Clear(); 135 136 selectedMobs.ForEach(delegate(Mob m) 137 { 138 selectedMobUnits.Add(m); 139 m.IsSelected = true; 140 m.OnFocus(); 141 }); 107 142 } 108 143 } … … 139 174 return current; 140 175 } 176 177 private List<Mob> SelectMobs(BoundingRectangle rect) 178 { 179 rect.Translate(new Vector2(camera.XLeft, camera.YTop)); 180 181 List<Mob> mobs = level.GetUnitsWithinScreenSpace<Mob>(rect, Team); 182 183 return mobs; 184 } 185 186 public override void Render(RenderHelper renderer) 187 { 188 if (trackBox) 189 { 190 renderer.SpriteBatch.Draw(Resources.SPRITE_HIGHTLIGHT, FastFunctions.RectangleFromPoints(oldPoint, newPoint), Color.White); 191 } 192 } 141 193 } 142 194 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs
r4752 r4753 112 112 } 113 113 114 private void TryChopNearestTree(int radius) 115 { 116 TileEntityTree nearestTree = level.GetNearestEntity<TileEntityTree>(this, radius); 117 if (nearestTree != null) 118 OrderChop(nearestTree, 1, false); 119 else return; 120 } 121 114 122 public override void Update() 115 123 { … … 121 129 { 122 130 StopChopping(); 123 OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false);131 TryChopNearestTree(5); 124 132 } 125 TurnTowards(currentTarget.X, currentTarget.Z); 126 choppingAnimation.UpdateStep(); 133 else 134 { 135 TurnTowards(currentTarget.X, currentTarget.Z); 136 choppingAnimation.UpdateStep(); 137 } 127 138 } 128 139 else if (!isChopping && currentOrderType == OrderType.CHOP) … … 131 142 { 132 143 StopChopping(); 133 OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false);144 TryChopNearestTree(5); 134 145 } 135 146 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs
r4694 r4753 338 338 } 339 339 340 public List<T> GetUnitsWithinScreenSpace<T>(BoundingRectangle rect, Team team) where T : Unit 341 { 342 List<T> result = new List<T>(); 343 344 foreach (Unit u in units[team.ID]) 345 { 346 T unit = u as T; 347 if (unit != null && unit.IsSelectable && unit.IntersectsWithScreenSpace(rect.XLeft, rect.ZFar, rect.XRight, rect.ZNear)) 348 result.Add(unit); 349 } 350 351 return result; 352 } 353 340 354 public List<BoundingRectangle> GetCollidables(Entity ent, BoundingRectangle br = null) 341 355 { -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj
r4752 r4753 167 167 </Compile> 168 168 </ItemGroup> 169 <ItemGroup> 170 <Compile Include="gui\highLightBox.png"> 171 <Name>highLightBox</Name> 172 <Importer>TextureImporter</Importer> 173 <Processor>TextureProcessor</Processor> 174 </Compile> 175 </ItemGroup> 176 <ItemGroup> 177 <Compile Include="gui\howto\page_buildings.png"> 178 <Name>page_buildings</Name> 179 <Importer>TextureImporter</Importer> 180 <Processor>TextureProcessor</Processor> 181 </Compile> 182 <Compile Include="gui\howto\page_controls.png"> 183 <Name>page_controls</Name> 184 <Importer>TextureImporter</Importer> 185 <Processor>TextureProcessor</Processor> 186 </Compile> 187 <Compile Include="gui\howto\page_gui.png"> 188 <Name>page_gui</Name> 189 <Importer>TextureImporter</Importer> 190 <Processor>TextureProcessor</Processor> 191 </Compile> 192 <Compile Include="gui\howto\page_units.png"> 193 <Name>page_units</Name> 194 <Importer>TextureImporter</Importer> 195 <Processor>TextureProcessor</Processor> 196 </Compile> 197 <Compile Include="gui\howto\page_welcome.png"> 198 <Name>page_welcome</Name> 199 <Importer>TextureImporter</Importer> 200 <Processor>TextureProcessor</Processor> 201 </Compile> 202 </ItemGroup> 169 203 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 170 204 <!-- 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.