- Timestamp:
- 2013-07-26 01:17:25 (9 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster
- Files:
-
- 14 added
- 2 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/AIState.cs
r4671 r4694 32 32 public virtual void OnStateChange() { } 33 33 34 public virtual void OnStateReChosen() { } 35 34 36 public virtual Unit SelectUnit(Team team) { return null; } 35 37 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/AgressiveState.cs
r4671 r4694 28 28 List<MobWarrior> mobUnits = AI.GetUnitsByType<MobWarrior>(); 29 29 30 if (AI.CoinsAmount >= 200 || mobUnits.Count > 10)30 if (AI.CoinsAmount >= 200) 31 31 return IMPORTANCE_HIGH; 32 32 else if (mobUnits.Count > 5 && AI.CoinsAmount >= 100) … … 69 69 } 70 70 71 public override void OnStateReChosen() 72 { 73 warriors = AI.GetUnitsByType<MobWarrior>(); 74 rangers = AI.GetUnitsByType<MobRanger>(); 75 } 76 71 77 public override void ApplyState() 72 78 { 73 if (!AI. Store.IsDestroyed && warriors.Count + rangers.Count <= 5 && AI.CoinsAmount >= UnitStore.PRICE_WARRIOR)79 if (!AI.Armory.IsDestroyed && warriors.Count + rangers.Count <= 10 && AI.CoinsAmount >= UnitArmory.PRICE_WARRIOR) 74 80 { 75 81 Type typeToBuy = null; 76 typeToBuy = AI.AttackerTypes[Game.Random.Next(AI.AttackerTypes.Count)]; 82 int buyID = Game.Random.Next(AI.AttackerTypes.Count); 83 typeToBuy = AI.AttackerTypes[buyID]; 77 84 78 Mob m = AI. Store.BuyUnit<Mob>(typeToBuy);79 Point spawnPoint = typeToBuy == typeof(MobWarrior) ? AI.WarriorSpawnPoint : AI.RangerSpawnPoint;85 Mob m = AI.Armory.BuyUnit<Mob>(typeToBuy); 86 Point spawnPoint = AI.SpawnPoints[buyID + 1]; 80 87 81 88 bool solid = true; … … 93 100 { 94 101 warriors.Add((MobWarrior)m); 95 ((MobWarrior)m).OnFunctionClick(AI. RangerSpawnPoint.X * Viewport.TILESIZE, AI.RangerSpawnPoint.Y * Viewport.TILESIZE, 1, false);102 ((MobWarrior)m).OnFunctionClick(AI.SpawnPoints[Player.SPAWN_WARRIOR].X * Viewport.TILESIZE, AI.SpawnPoints[Player.SPAWN_WARRIOR].Y * Viewport.TILESIZE, 1, false); 96 103 } 97 104 else 98 105 { 99 106 rangers.Add((MobRanger)m); 100 ((MobRanger)m).OnFunctionClick(AI. RangerSpawnPoint.X * Viewport.TILESIZE, AI.RangerSpawnPoint.Y * Viewport.TILESIZE, 1, false);107 ((MobRanger)m).OnFunctionClick(AI.SpawnPoints[Player.SPAWN_RANGER].X * Viewport.TILESIZE, AI.SpawnPoints[Player.SPAWN_RANGER].Y * Viewport.TILESIZE, 1, false); 101 108 } 102 109 … … 107 114 { 108 115 if (warriors.Count > 0) 109 warriors[0].OnGroupOrder(warriors, AI. WarriorSpawnPoint.X * Viewport.TILESIZE, AI.WarriorSpawnPoint.Y * Viewport.TILESIZE);116 warriors[0].OnGroupOrder(warriors, AI.SpawnPoints[Player.SPAWN_WARRIOR].X * Viewport.TILESIZE, AI.SpawnPoints[Player.SPAWN_WARRIOR].Y * Viewport.TILESIZE); 110 117 if (rangers.Count > 0) 111 rangers[0].OnGroupOrder(rangers, AI. RangerSpawnPoint.X * Viewport.TILESIZE, AI.RangerSpawnPoint.Y * Viewport.TILESIZE);118 rangers[0].OnGroupOrder(rangers, AI.SpawnPoints[Player.SPAWN_RANGER].X * Viewport.TILESIZE, AI.SpawnPoints[Player.SPAWN_RANGER].Y * Viewport.TILESIZE); 112 119 isAttacking = true; 120 } 121 else 122 { 123 124 for (int i = 0; i < warriors.Count; i++) 125 { 126 if (warriors[i].Removed) 127 warriors.Remove(warriors[i]); 128 } 129 130 for (int i = 0; i < rangers.Count; i++) 131 { 132 if (rangers[i].Removed) 133 rangers.Remove(rangers[i]); 134 } 113 135 } 114 136 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/CollectiveState.cs
r4671 r4694 28 28 get 29 29 { 30 if (AI.Store.IsDestroyed) return IMPORTANCE_LOW; 31 30 32 if (AI.CoinsAmount <= Player.START_MONEY || AI.LumberAmount <= Player.START_LUMBER) 31 33 return IMPORTANCE_HIGH; … … 52 54 MobWoodcutter mw = woodCutters[0]; 53 55 AI.ForestPoint = new Point((int)(mw.X / Viewport.TILESIZE), (int)(mw.Z / Viewport.TILESIZE)); 54 woodCutters[0].OnGroupOrder<MobWoodcutter>(woodCutters, AI. WoodcutterSpawnPoint.X * Viewport.TILESIZE, AI.WoodcutterSpawnPoint.Y * Viewport.TILESIZE);56 woodCutters[0].OnGroupOrder<MobWoodcutter>(woodCutters, AI.SpawnPoints[Player.SPAWN_WOODCUTTER].X * Viewport.TILESIZE, AI.SpawnPoints[Player.SPAWN_WOODCUTTER].Y * Viewport.TILESIZE); 55 57 } 56 58 } … … 58 60 public override void ApplyState() 59 61 { 60 if (!AI. Store.IsDestroyed && AI.CoinsAmount >= UnitStore.PRICE_WOODCUTTER)62 if (!AI.Armory.IsDestroyed && AI.CoinsAmount >= UnitArmory.PRICE_WOODCUTTER) 61 63 { 62 64 if (woodCutters.Count <= 5) 63 65 { 64 MobWoodcutter m = AI. Store.BuyUnit<MobWoodcutter>();66 MobWoodcutter m = AI.Armory.BuyUnit<MobWoodcutter>(); 65 67 bool solid = true; 66 68 int xTile = 0, zTile = 0; 67 69 while (solid) 68 70 { 69 xTile = AI. WoodcutterSpawnPoint.X + (int)(Math.Sin(Game.Random.NextDouble() * MathHelper.TwoPi) * 2.0F);70 zTile = AI. WoodcutterSpawnPoint.Y + (int)(Math.Cos(Game.Random.NextDouble() * MathHelper.TwoPi) * 2.0F);71 xTile = AI.SpawnPoints[Player.SPAWN_WOODCUTTER].X + (int)(Math.Sin(Game.Random.NextDouble() * MathHelper.TwoPi) * Game.Random.NextDouble() * 4.0F); 72 zTile = AI.SpawnPoints[Player.SPAWN_WOODCUTTER].Y + (int)(Math.Cos(Game.Random.NextDouble() * MathHelper.TwoPi) * Game.Random.NextDouble() * 4.0F); 71 73 if (xTile < 0 || xTile >= AI.Level.Width || zTile < 0 || zTile >= AI.Level.Height) continue; 72 if (!AI.Level. RegisteredTiles[AI.Level.Tiles[xTile + zTile * AI.Level.Width]].IsSolidTo(m)) solid = false;74 if (!AI.Level.SolidTo(m, xTile, zTile)) solid = false; 73 75 } 74 76 … … 78 80 return; 79 81 } 80 else if (warriors.Count + rangers.Count <= 5 && AI.CoinsAmount >= Unit Store.PRICE_WARRIOR)82 else if (warriors.Count + rangers.Count <= 5 && AI.CoinsAmount >= UnitArmory.PRICE_WARRIOR) 81 83 { 82 84 Type typeToBuy = null; 83 typeToBuy = AI.AttackerTypes[Game.Random.Next(AI.AttackerTypes.Count)]; 85 int buyID = Game.Random.Next(AI.AttackerTypes.Count); 86 typeToBuy = AI.AttackerTypes[buyID]; 84 87 85 Mob m = AI. Store.BuyUnit<Mob>(typeToBuy);86 Point spawnPoint = typeToBuy == typeof(MobWarrior) ? AI.WarriorSpawnPoint : AI.RangerSpawnPoint;88 Mob m = AI.Armory.BuyUnit<Mob>(typeToBuy); 89 Point spawnPoint = AI.SpawnPoints[buyID + 1]; 87 90 88 91 bool solid = true; … … 90 93 while (solid) 91 94 { 92 xTile = spawnPoint.X + (int)(Math.Sin(Game.Random.NextDouble() * MathHelper.TwoPi) * 4.0F);93 zTile = spawnPoint.Y + (int)(Math.Cos(Game.Random.NextDouble() * MathHelper.TwoPi) * 4.0F);95 xTile = spawnPoint.X + (int)(Math.Sin(Game.Random.NextDouble() * MathHelper.TwoPi) * Game.Random.NextDouble() * 4.0F); 96 zTile = spawnPoint.Y + (int)(Math.Cos(Game.Random.NextDouble() * MathHelper.TwoPi) * Game.Random.NextDouble() * 4.0F); 94 97 if (xTile < 0 || xTile >= AI.Level.Width || zTile < 0 || zTile >= AI.Level.Height) continue; 95 if (!AI.Level. RegisteredTiles[AI.Level.Tiles[xTile + zTile * AI.Level.Width]].IsSolidTo(m)) solid = false;98 if (!AI.Level.SolidTo(m, xTile, zTile)) solid = false; 96 99 } 97 100 … … 120 123 } 121 124 122 while (AI.LumberAmount > Player.START_LUMBER + 1)125 if (!AI.Store.IsDestroyed) 123 126 { 124 AI.LumberAmount--; 125 AI.CoinsAmount += Player.LUMBER_WORTH; 127 while (AI.LumberAmount > Player.START_LUMBER + 1) 128 { 129 AI.LumberAmount--; 130 AI.CoinsAmount += UnitStore.COINS_FOR_LUMBER; 131 } 126 132 } 127 133 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/DefensiveState.cs
r4671 r4694 42 42 rangers = AI.GetUnitsByType<MobRanger>(); 43 43 44 while (!AI. Store.IsDestroyed && warriors.Count + rangers.Count < 30 && AI.CoinsAmount >= UnitStore.PRICE_WARRIOR)44 while (!AI.Armory.IsDestroyed && warriors.Count + rangers.Count < 30 && AI.CoinsAmount >= UnitArmory.PRICE_WARRIOR) 45 45 { 46 46 Type typeToBuy = null; 47 47 typeToBuy = AI.AttackerTypes[Game.Random.Next(AI.AttackerTypes.Count)]; 48 48 49 Mob m = AI. Store.BuyUnit<Mob>(typeToBuy);49 Mob m = AI.Armory.BuyUnit<Mob>(typeToBuy); 50 50 51 51 bool solid = true; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj
r4671 r4694 93 93 <Compile Include="Graphics\SpriteSheet.cs" /> 94 94 <Compile Include="Graphics\Viewport.cs" /> 95 <Compile Include="Guis\Gui.cs" /> 96 <Compile Include="Guis\GuiArmoryMenu.cs" /> 97 <Compile Include="Guis\GuiDebug.cs" /> 98 <Compile Include="Guis\GuiPlayer.cs" /> 99 <Compile Include="Guis\GuiManager.cs" /> 100 <Compile Include="Guis\GuiStoreMenu.cs" /> 95 101 <Compile Include="Input\InputHandler.cs" /> 96 102 <Compile Include="MathHelpers\FastFunctions.cs" /> … … 110 116 <Compile Include="Units\Mobs\MobWoodcutter.cs" /> 111 117 <Compile Include="Units\Unit.cs" /> 118 <Compile Include="Units\UnitArmory.cs" /> 112 119 <Compile Include="Units\UnitKing.cs" /> 113 120 <Compile Include="Units\UnitStore.cs" /> -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4671 r4694 11 11 using Viewport = CastleMaster.Graphics.Viewport; 12 12 using CastleMaster.Players; 13 using CastleMaster.Guis; 13 14 14 15 namespace CastleMaster … … 21 22 public const int WIDTH = 800; 22 23 public const int HEIGHT = 600; 23 public const string TITLE = "Castle Master Alpha 0.2"; 24 25 private const string UPS_TEXT = " UPS: "; 26 private const string FPS_TEXT = " | FPS: "; 24 public const string TITLE = "Castle Master"; 25 public const string VERSION = " Alpha 1.5"; 27 26 28 27 private GraphicsDeviceManager graphics; … … 33 32 private LevelForest level; 34 33 private Player[] players; 34 private static GuiManager guiManager; 35 private GuiDebug debugScreen; 36 private GuiPlayer ingame; 35 37 36 38 #region Counter 37 39 private readonly TimeSpan ONE_SECOND = TimeSpan.FromSeconds(1.0); 38 40 private TimeSpan currentTime = TimeSpan.Zero; 39 private int frames = 0, updates = 0 ;41 private int frames = 0, updates = 0, fps = 0, ups = 0; 40 42 #endregion 41 43 … … 52 54 Random = new FastRandom(); 53 55 players = new Player[2]; 54 } 55 56 /// <summary> 57 /// Allows the game to perform any initialization it needs to before starting to run. 58 /// This is where it can query for any required services and load any non-graphic 59 /// related content. Calling base.Initialize will enumerate through any components 60 /// and initialize them as well. 61 /// </summary> 56 guiManager = new GuiManager(); 57 } 58 59 public static GuiManager GuiManager { get { return guiManager; } } 60 61 public int FPS { get { return fps; } } 62 63 public int UPS { get { return ups; } } 64 62 65 protected override void Initialize() 63 66 { 64 67 graphics.PreferredBackBufferWidth = WIDTH; 65 68 graphics.PreferredBackBufferHeight = HEIGHT; 66 graphics.SynchronizeWithVerticalRetrace = true;69 graphics.SynchronizeWithVerticalRetrace = false; 67 70 graphics.ApplyChanges(); 68 71 Window.Title = TITLE; … … 81 84 input.RegisterKeyboardKey(Keys.D); 82 85 input.RegisterKeyboardKey(Keys.F4); 86 input.RegisterKeyboardKey(Keys.F1); 83 87 input.RegisterKeyboardKey(Keys.ShiftKey); 84 88 input.RegisterKeyboardKey(Keys.ControlKey); 89 input.RegisterKeyboardKey(Keys.Up); 90 input.RegisterKeyboardKey(Keys.Down); 91 input.RegisterKeyboardKey(Keys.Left); 92 input.RegisterKeyboardKey(Keys.Right); 93 input.RegisterKeyboardKey(Keys.Enter); 85 94 86 95 input.RegisterMouseKey(MouseButtons.Middle); … … 100 109 } 101 110 102 /// <summary>103 /// LoadContent will be called once per game and is the place to load104 /// all of your content.105 /// </summary>106 111 protected override void LoadContent() 107 112 { … … 112 117 } 113 118 114 /// <summary>115 /// UnloadContent will be called once per game and is the place to unload116 /// all content.117 /// </summary>118 119 protected override void UnloadContent() 119 120 { 120 // TODO: Unload any non ContentManager content here121 121 } 122 122 … … 128 128 camera = new Camera(level); 129 129 AddPlayer(new PlayerReal(TEAM1, level, camera)); 130 AddPlayer(new PlayerAI(TEAM2, level, camera, PlayerAI.DIFFICULTY_ HARD, players[0]));130 AddPlayer(new PlayerAI(TEAM2, level, camera, PlayerAI.DIFFICULTY_NORMAL, players[0])); 131 131 level.InitLevel(); 132 132 foreach (Player p in players) 133 133 if (p != null) p.OnLevelLoaded(); 134 134 camera.CenterOn(level.Width / 2 * Viewport.TILESIZE, level.Height / 2 * Viewport.TILESIZE); 135 } 136 137 /// <summary> 138 /// Allows the game to run logic such as updating the world, 139 /// checking for collisions, gathering input, and playing audio. 140 /// </summary> 141 /// <param name="gameTime">Provides a snapshot of timing values.</param> 135 136 137 ingame = new GuiPlayer(guiManager, players[0]); 138 guiManager.AddGui(ingame, true); 139 140 debugScreen = new GuiDebug(guiManager, this); 141 guiManager.AddGui(debugScreen, false); 142 } 143 142 144 protected override void Update(GameTime gameTime) 143 145 { 144 146 input.Update(); 145 147 148 if (InputHandler.HasKeyBeenPressed(Keys.F1)) 149 { 150 debugScreen.IsActive = !debugScreen.IsActive; 151 } 146 152 if (InputHandler.HasKeyBeenPressed(Keys.F4)) 147 153 IsFixedTimeStep = !IsFixedTimeStep; … … 157 163 if (p != null) 158 164 p.Update(); 165 //players[0].Update(); 159 166 160 167 camera.Update(); 161 168 162 169 level.Update(); 170 171 guiManager.Update(); 163 172 164 173 updates++; … … 167 176 { 168 177 currentTime = TimeSpan.Zero; 169 Window.Title = new StringBuilder(TITLE).Append(FPS_TEXT).Append(frames).Append(UPS_TEXT).Append(updates).ToString(); 178 fps = frames; 179 ups = updates; 170 180 frames = updates = 0; 171 181 } … … 174 184 } 175 185 176 /// <summary>177 /// This is called when the game should draw itself.178 /// </summary>179 /// <param name="gameTime">Provides a snapshot of timing values.</param>180 186 protected override void Draw(GameTime gameTime) 181 187 { … … 188 194 level.RenderEntities(camera, renderer); 189 195 196 guiManager.Render(renderer); 190 197 camera.RenderCursor(renderer); 191 198 renderer.EndRender(); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/RenderHelper.cs
r4535 r4694 11 11 private bool isRendering = false; 12 12 private Point renderOffset = Point.Zero; 13 private static Texture2D empty; 13 14 14 15 public RenderHelper(SpriteBatch batch) … … 16 17 registeredSpriteSheets = new List<SpriteSheet>(); 17 18 renderer = batch; 19 empty = new Texture2D(batch.GraphicsDevice, 1, 1); 20 uint[] c = { 0xFFFFFFFF }; 21 empty.SetData(c); 18 22 } 23 24 public static Texture2D EmptyTexture { get { return empty; } } 25 26 public SpriteBatch SpriteBatch { get { return renderer; } } 27 28 public List<SpriteSheet> RegisteredSpriteSheets { get { return registeredSpriteSheets; } } 19 29 20 30 public int RegisterSpriteSheet(SpriteSheet spriteSheet) … … 93 103 renderer.Draw(sp.SheetTexture, new Rectangle((int)(texturePos.X * scale), (int)(texturePos.Y * scale), width, height), sp[spriteX, spriteY], Color.White); 94 104 } 95 96 105 } 97 106 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Resources.cs
r4635 r4694 13 13 public static int SPRITE_KING { get; private set; } 14 14 public static int SPRITE_STORE { get; private set; } 15 public static int SPRITE_ARMORY { get; private set; } 16 public static int SPRITESHEET_HEALTH { get; private set; } 17 public static SpriteFont FONT { get; private set; } 18 public static Texture2D SPRITE_GUI_UNITMENU { get; private set; } 15 19 16 20 public static void LoadResources(ContentManager cm, RenderHelper renderer) … … 22 26 SPRITESHEET_RANGER = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/archer"), 32, 32)); 23 27 SPRITE_KING = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/king"), 160, 128)); 28 SPRITE_ARMORY = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/armory"), 160, 98)); 24 29 SPRITE_STORE = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/store"), 240, 147)); 30 FONT = cm.Load<SpriteFont>("gui/font"); 31 SPRITESHEET_HEALTH = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("gui/guiHealth"), 100, 4)); 32 SPRITE_GUI_UNITMENU = cm.Load<Texture2D>("gui/guiUnitMenu"); 25 33 } 26 34 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/Player.cs
r4671 r4694 12 12 public abstract class Player 13 13 { 14 public const int LUMBER_WORTH = 2;15 14 public const int START_MONEY = 20; 16 15 public const int START_LUMBER = 10; 16 17 public const int SPAWN_WOODCUTTER = 0; 18 public const int SPAWN_WARRIOR= 1; 19 public const int SPAWN_RANGER = 2; 17 20 18 21 protected Team team; … … 21 24 protected UnitKing king; 22 25 protected UnitStore store; 26 protected UnitArmory armory; 27 protected Point[] spawnPoints; 23 28 24 29 public Player(Team team, Level level, Camera camera) … … 29 34 LumberAmount = START_LUMBER; 30 35 CoinsAmount = 20; 36 37 spawnPoints = new Point[3]; 31 38 32 39 king = new UnitKing(level, this); 33 40 store = new UnitStore(level, this); 41 armory = new UnitArmory(level, this); 34 42 } 35 43 36 44 public Point HomePoint { get; set; } 37 45 38 public Point WoodcutterSpawnPoint { get; set; } 39 40 public Point WarriorSpawnPoint { get; set; } 41 42 public Point RangerSpawnPoint { get; set; } 46 public Point[] SpawnPoints { get { return spawnPoints; } } 43 47 44 48 public UnitKing King { get { return king; } } 45 49 46 50 public UnitStore Store { get { return store; } } 51 52 public UnitArmory Armory { get { return armory; } } 47 53 48 54 public List<Unit> AvailableUnits { get { return level.Units[Team.ID]; } } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerAI.cs
r4671 r4694 35 35 36 36 unitTypes = new List<Type>(); 37 unitTypes.Add(typeof(MobWarrior)); 37 38 unitTypes.Add(typeof(MobRanger)); 38 unitTypes.Add(typeof(MobWarrior));39 39 40 40 currentBrain = availableStates[0]; … … 53 53 public override void OnLevelLoaded() 54 54 { 55 ReThinkBestState();56 55 } 57 56 … … 78 77 Console.WriteLine("New state:" + currentBrain); 79 78 } 79 else 80 currentBrain.OnStateReChosen(); 80 81 } 81 82 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerReal.cs
r4646 r4694 71 71 if (selectedUnit != null) 72 72 { 73 selectedUnit.OnFocusLost(); 73 74 selectedUnit.IsSelected = false; 74 75 selectedUnit = null; … … 76 77 selectedMobUnits.Add((Mob)u); 77 78 u.IsSelected = true; 79 u.OnFocus(); 78 80 } 79 81 else 80 82 { 81 selectedMobUnits.ForEach(m => m.IsSelected = false); 83 selectedMobUnits.ForEach(delegate(Mob m) 84 { 85 m.OnFocusLost(); 86 m.IsSelected = false; 87 }); 88 82 89 selectedMobUnits.Clear(); 83 90 84 91 if (selectedUnit != null) 92 { 93 selectedUnit.OnFocusLost(); 85 94 selectedUnit.IsSelected = false; 95 } 86 96 selectedUnit = null; 87 97 if (u != null) … … 93 103 94 104 u.IsSelected = true; 105 u.OnFocus(); 95 106 } 96 107 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs
r4671 r4694 65 65 if (te == null) 66 66 return; 67 isChopping = true;68 67 currentOrderType = OrderType.CHOP; 69 68 currentTarget = te; … … 119 118 if (isChopping) 120 119 { 120 if (currentTarget == null) 121 { 122 StopChopping(); 123 OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false); 124 } 121 125 TurnTowards(currentTarget.X, currentTarget.Z); 122 126 choppingAnimation.UpdateStep(); … … 127 131 { 128 132 StopChopping(); 129 StopCurrentOrder();133 OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false); 130 134 } 131 135 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Unit.cs
r4671 r4694 59 59 Health = maxHealth; 60 60 } 61 62 public virtual void OnFocus() { } 63 64 public virtual void OnFocusLost() { } 61 65 62 66 public virtual bool CanBeHurtBy(Unit u) -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitKing.cs
r4671 r4694 20 20 depth = 5 * Viewport.TILESIZE; 21 21 HasHealth = true; 22 maxHealth = 500;22 maxHealth = 400; 23 23 24 24 isSolid = true; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitStore.cs
r4671 r4694 7 7 using CastleMaster.Graphics; 8 8 using CastleMaster.Units.Mobs; 9 using CastleMaster.Guis; 9 10 10 11 namespace CastleMaster.Units … … 12 13 public class UnitStore : Unit 13 14 { 14 public const int PRICE_WOODCUTTER = 10; 15 public const int PRICE_WARRIOR = 20; 16 public const int PRICE_RANGER = 10; 17 private Dictionary<Type, int> prices; 15 public const int COINS_FOR_LUMBER = 2; 18 16 private bool isDestroyed = false; 17 private GuiStoreMenu menu; 19 18 20 19 public UnitStore(Level level, Player owner) … … 24 23 depth = 8 * Viewport.TILESIZE; 25 24 HasHealth = true; 26 maxHealth = 200;25 maxHealth = 400; 27 26 immunityTime = 20; 28 27 … … 40 39 rectOffset.Update(-4 * Viewport.TILESIZE, -4 * Viewport.TILESIZE, 4 * Viewport.TILESIZE, 4 * Viewport.TILESIZE); 41 40 42 prices = new Dictionary<Type, int>(); 43 prices.Add(typeof(MobWoodcutter), PRICE_WOODCUTTER); 44 prices.Add(typeof(MobWarrior), PRICE_WARRIOR); 45 prices.Add(typeof(MobRanger), PRICE_RANGER); 41 menu = new GuiStoreMenu(Game.GuiManager, this); 46 42 } 47 43 48 public T BuyUnit<T>(Type toBuy = null) where T : Mob44 public void SellWood() 49 45 { 50 Type unitType = toBuy == null ? typeof(T) : toBuy; 51 int cost = prices[unitType]; 52 if (Owner.CoinsAmount - cost < 0) return null; 53 T m = (T)Activator.CreateInstance(unitType, level, Owner); 54 Owner.CoinsAmount -= cost; 55 return m; 46 if (Owner.LumberAmount >= 1) 47 { 48 Owner.LumberAmount--; 49 Owner.CoinsAmount += COINS_FOR_LUMBER; 50 } 56 51 } 57 52 58 53 public bool IsDestroyed { get { return isDestroyed; } } 54 55 public override void OnFocus() 56 { 57 Game.GuiManager.AddGui(menu, true); 58 } 59 60 public override void OnFocusLost() 61 { 62 Game.GuiManager.RemoveGui(menu); 63 } 59 64 60 65 public override void OnRemoved() … … 75 80 } 76 81 82 menu.Remove(); 77 83 level.RemoveUnit(this); 78 84 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs
r4671 r4694 13 13 using System; 14 14 using System.Diagnostics; 15 using CastleMaster.Guis; 15 16 16 17 namespace CastleMaster.World … … 113 114 { 114 115 float w = (Game.WIDTH / Viewport.FLOOR_TILE_WIDTH) / Viewport.ZOOM; 115 float h = ( Game.HEIGHT/ Viewport.Y_STEP) / Viewport.ZOOM;116 float h = ((Game.HEIGHT - GuiPlayer.GUI_BAR_HEIGHT) / Viewport.Y_STEP) / Viewport.ZOOM; 116 117 117 118 int x0 = (int)((camera.XLeft / Viewport.FLOOR_TILE_WIDTH) / Viewport.ZOOM) - 3; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/LevelForest.cs
r4671 r4694 13 13 public class LevelForest : Level 14 14 { 15 private int TILE_FLOOR, TILE_WATER, TILE_FLOOR_SOLID, TILE_KING1_HINT, TILE_KING1_HINT2, TILE_STORE1_HINT, TILE_KING2_HINT, TILE_KING2_HINT2, TILE_STORE2_HINT ;15 private int TILE_FLOOR, TILE_WATER, TILE_FLOOR_SOLID, TILE_KING1_HINT, TILE_KING1_HINT2, TILE_STORE1_HINT, TILE_KING2_HINT, TILE_KING2_HINT2, TILE_STORE2_HINT, TILE_ARMORY1_HINT, TILE_ARMORY2_HINT; 16 16 17 17 public LevelForest(Texture2D tileMap) … … 31 31 TILE_STORE2_HINT = new TileRenderHint(this, Players[1].Store, true, true).ID; 32 32 TILE_KING2_HINT2 = new TileRenderHint(this, Players[1].King, false, false).ID; 33 TILE_ARMORY1_HINT = new TileRenderHint(this, Players[0].Armory, true, true).ID; 34 TILE_ARMORY2_HINT = new TileRenderHint(this, Players[1].Armory, true, true).ID; 33 35 } 34 36 … … 42 44 lb.AddTile(0xFF606060, TILE_KING1_HINT2); 43 45 lb.AddTile(0xFF505050, TILE_STORE1_HINT); 46 lb.AddTile(0xFF50505B, TILE_ARMORY1_HINT); 44 47 45 48 lb.AddTile(0xFF707071, TILE_KING2_HINT); 46 49 lb.AddTile(0xFF606061, TILE_KING2_HINT2); 47 50 lb.AddTile(0xFF505051, TILE_STORE2_HINT); 51 lb.AddTile(0xFF60606B, TILE_ARMORY2_HINT); 48 52 49 53 lb.AddTile(0xFF808080, TILE_FLOOR_SOLID); … … 85 89 lb.AddCustom(0xFF00FF20, delegate(Level level, int xTile, int zTile) 86 90 { 87 Players[1]. WoodcutterSpawnPoint= new Point(xTile, zTile);91 Players[1].SpawnPoints[Player.SPAWN_WOODCUTTER] = new Point(xTile, zTile); 88 92 }); 89 93 90 94 lb.AddCustom(0xFF00FF30, delegate(Level level, int xTile, int zTile) 91 95 { 92 Players[1]. WarriorSpawnPoint= new Point(xTile, zTile);96 Players[1].SpawnPoints[Player.SPAWN_WARRIOR] = new Point(xTile, zTile); 93 97 }); 94 98 95 99 lb.AddCustom(0xFF00FF40, delegate(Level level, int xTile, int zTile) 96 100 { 97 Players[1]. RangerSpawnPoint= new Point(xTile, zTile);101 Players[1].SpawnPoints[Player.SPAWN_RANGER] = new Point(xTile, zTile); 98 102 }); 99 103 … … 115 119 lb.AddCustom(0xFF00FF11, delegate(Level level, int xTile, int zTile) 116 120 { 117 Players[0]. WoodcutterSpawnPoint= new Point(xTile, zTile);121 Players[0].SpawnPoints[Player.SPAWN_WOODCUTTER] = new Point(xTile, zTile); 118 122 }); 119 123 120 124 lb.AddCustom(0xFF00FF21, delegate(Level level, int xTile, int zTile) 121 125 { 122 Players[0]. WarriorSpawnPoint= new Point(xTile, zTile);126 Players[0].SpawnPoints[Player.SPAWN_WARRIOR] = new Point(xTile, zTile); 123 127 }); 124 128 125 129 lb.AddCustom(0xFF00FF31, delegate(Level level, int xTile, int zTile) 126 130 { 127 Players[0]. RangerSpawnPoint= new Point(xTile, zTile);131 Players[0].SpawnPoints[Player.SPAWN_RANGER] = new Point(xTile, zTile); 128 132 }); 129 133 … … 136 140 level.AddEntity(Players[1].Store, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 137 141 }); 142 lb.AddCustom(0xFFFF6C11, delegate(Level level, int xTile, int zTile) 143 { 144 level.AddEntity(Players[1].Armory, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 145 }); 138 146 139 147 lb.AddCustom(0xFFFF6A00, delegate(Level level, int xTile, int zTile) … … 144 152 { 145 153 level.AddEntity(Players[0].Store, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 154 }); 155 lb.AddCustom(0xFFFF6B11, delegate(Level level, int xTile, int zTile) 156 { 157 level.AddEntity(Players[0].Armory, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 146 158 }); 147 159 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj
r4646 r4694 154 154 </Compile> 155 155 </ItemGroup> 156 <ItemGroup> 157 <Compile Include="gui\font.tga"> 158 <Name>font</Name> 159 <Importer>TextureImporter</Importer> 160 <Processor>FontTextureProcessor</Processor> 161 </Compile> 162 </ItemGroup> 163 <ItemGroup> 164 <Compile Include="gui\guiHealth.png"> 165 <Name>guiHealth</Name> 166 <Importer>TextureImporter</Importer> 167 <Processor>TextureProcessor</Processor> 168 </Compile> 169 </ItemGroup> 170 <ItemGroup> 171 <Compile Include="gui\guiUnitMenu.png"> 172 <Name>guiUnitMenu</Name> 173 <Importer>TextureImporter</Importer> 174 <Processor>TextureProcessor</Processor> 175 </Compile> 176 </ItemGroup> 177 <ItemGroup> 178 <Compile Include="mobs\armory.png"> 179 <Name>armory</Name> 180 <Importer>TextureImporter</Importer> 181 <Processor>TextureProcessor</Processor> 182 </Compile> 183 </ItemGroup> 156 184 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 157 185 <!-- 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.