Changeset 4694 for 2013


Ignore:
Timestamp:
2013-07-26 01:17:25 (6 years ago)
Author:
dezhidki
Message:

Guit lisätty, AIn viimestely.

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  
    3232        public virtual void OnStateChange() { } 
    3333 
     34        public virtual void OnStateReChosen() { } 
     35 
    3436        public virtual Unit SelectUnit(Team team) { return null; } 
    3537    } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/AgressiveState.cs

    r4671 r4694  
    2828                List<MobWarrior> mobUnits = AI.GetUnitsByType<MobWarrior>(); 
    2929 
    30                 if (AI.CoinsAmount >= 200 || mobUnits.Count > 10) 
     30                if (AI.CoinsAmount >= 200) 
    3131                    return IMPORTANCE_HIGH; 
    3232                else if (mobUnits.Count > 5 && AI.CoinsAmount >= 100) 
     
    6969        } 
    7070 
     71        public override void OnStateReChosen() 
     72        { 
     73            warriors = AI.GetUnitsByType<MobWarrior>(); 
     74            rangers = AI.GetUnitsByType<MobRanger>(); 
     75        } 
     76 
    7177        public override void ApplyState() 
    7278        { 
    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) 
    7480            { 
    7581                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]; 
    7784 
    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]; 
    8087 
    8188                bool solid = true; 
     
    93100                { 
    94101                    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); 
    96103                } 
    97104                else 
    98105                { 
    99106                    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); 
    101108                } 
    102109 
     
    107114            { 
    108115                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); 
    110117                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); 
    112119                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                } 
    113135            } 
    114136        } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/CollectiveState.cs

    r4671 r4694  
    2828            get 
    2929            { 
     30                if (AI.Store.IsDestroyed) return IMPORTANCE_LOW; 
     31 
    3032                if (AI.CoinsAmount <= Player.START_MONEY || AI.LumberAmount <= Player.START_LUMBER) 
    3133                    return IMPORTANCE_HIGH; 
     
    5254                MobWoodcutter mw = woodCutters[0]; 
    5355                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); 
    5557            } 
    5658        } 
     
    5860        public override void ApplyState() 
    5961        { 
    60             if (!AI.Store.IsDestroyed && AI.CoinsAmount >= UnitStore.PRICE_WOODCUTTER) 
     62            if (!AI.Armory.IsDestroyed && AI.CoinsAmount >= UnitArmory.PRICE_WOODCUTTER) 
    6163            { 
    6264                if (woodCutters.Count <= 5) 
    6365                { 
    64                     MobWoodcutter m = AI.Store.BuyUnit<MobWoodcutter>(); 
     66                    MobWoodcutter m = AI.Armory.BuyUnit<MobWoodcutter>(); 
    6567                    bool solid = true; 
    6668                    int xTile = 0, zTile = 0; 
    6769                    while (solid) 
    6870                    { 
    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); 
    7173                        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; 
    7375                    } 
    7476 
     
    7880                    return; 
    7981                } 
    80                 else if (warriors.Count + rangers.Count <= 5 && AI.CoinsAmount >= UnitStore.PRICE_WARRIOR) 
     82                else if (warriors.Count + rangers.Count <= 5 && AI.CoinsAmount >= UnitArmory.PRICE_WARRIOR) 
    8183                { 
    8284                    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]; 
    8487 
    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]; 
    8790 
    8891                    bool solid = true; 
     
    9093                    while (solid) 
    9194                    { 
    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); 
    9497                        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; 
    9699                    } 
    97100 
     
    120123                } 
    121124 
    122                 while (AI.LumberAmount > Player.START_LUMBER + 1) 
     125                if (!AI.Store.IsDestroyed) 
    123126                { 
    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                    } 
    126132                } 
    127133            } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AIStates/DefensiveState.cs

    r4671 r4694  
    4242            rangers = AI.GetUnitsByType<MobRanger>(); 
    4343 
    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) 
    4545            { 
    4646                Type typeToBuy = null; 
    4747                typeToBuy = AI.AttackerTypes[Game.Random.Next(AI.AttackerTypes.Count)]; 
    4848 
    49                 Mob m = AI.Store.BuyUnit<Mob>(typeToBuy); 
     49                Mob m = AI.Armory.BuyUnit<Mob>(typeToBuy); 
    5050 
    5151                bool solid = true; 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj

    r4671 r4694  
    9393    <Compile Include="Graphics\SpriteSheet.cs" /> 
    9494    <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" /> 
    95101    <Compile Include="Input\InputHandler.cs" /> 
    96102    <Compile Include="MathHelpers\FastFunctions.cs" /> 
     
    110116    <Compile Include="Units\Mobs\MobWoodcutter.cs" /> 
    111117    <Compile Include="Units\Unit.cs" /> 
     118    <Compile Include="Units\UnitArmory.cs" /> 
    112119    <Compile Include="Units\UnitKing.cs" /> 
    113120    <Compile Include="Units\UnitStore.cs" /> 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs

    r4671 r4694  
    1111using Viewport = CastleMaster.Graphics.Viewport; 
    1212using CastleMaster.Players; 
     13using CastleMaster.Guis; 
    1314 
    1415namespace CastleMaster 
     
    2122        public const int WIDTH = 800; 
    2223        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"; 
    2726 
    2827        private GraphicsDeviceManager graphics; 
     
    3332        private LevelForest level; 
    3433        private Player[] players; 
     34        private static GuiManager guiManager; 
     35        private GuiDebug debugScreen; 
     36        private GuiPlayer ingame; 
    3537 
    3638        #region Counter 
    3739        private readonly TimeSpan ONE_SECOND = TimeSpan.FromSeconds(1.0); 
    3840        private TimeSpan currentTime = TimeSpan.Zero; 
    39         private int frames = 0, updates = 0; 
     41        private int frames = 0, updates = 0, fps = 0, ups = 0; 
    4042        #endregion 
    4143 
     
    5254            Random = new FastRandom(); 
    5355            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 
    6265        protected override void Initialize() 
    6366        { 
    6467            graphics.PreferredBackBufferWidth = WIDTH; 
    6568            graphics.PreferredBackBufferHeight = HEIGHT; 
    66             graphics.SynchronizeWithVerticalRetrace = true; 
     69            graphics.SynchronizeWithVerticalRetrace = false; 
    6770            graphics.ApplyChanges(); 
    6871            Window.Title = TITLE; 
     
    8184            input.RegisterKeyboardKey(Keys.D); 
    8285            input.RegisterKeyboardKey(Keys.F4); 
     86            input.RegisterKeyboardKey(Keys.F1); 
    8387            input.RegisterKeyboardKey(Keys.ShiftKey); 
    8488            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); 
    8594 
    8695            input.RegisterMouseKey(MouseButtons.Middle); 
     
    100109        } 
    101110 
    102         /// <summary> 
    103         /// LoadContent will be called once per game and is the place to load 
    104         /// all of your content. 
    105         /// </summary> 
    106111        protected override void LoadContent() 
    107112        { 
     
    112117        } 
    113118 
    114         /// <summary> 
    115         /// UnloadContent will be called once per game and is the place to unload 
    116         /// all content. 
    117         /// </summary> 
    118119        protected override void UnloadContent() 
    119120        { 
    120             // TODO: Unload any non ContentManager content here 
    121121        } 
    122122 
     
    128128            camera = new Camera(level); 
    129129            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])); 
    131131            level.InitLevel(); 
    132132            foreach (Player p in players) 
    133133                if (p != null) p.OnLevelLoaded(); 
    134134            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 
    142144        protected override void Update(GameTime gameTime) 
    143145        { 
    144146            input.Update(); 
    145147 
     148            if (InputHandler.HasKeyBeenPressed(Keys.F1)) 
     149            { 
     150                debugScreen.IsActive = !debugScreen.IsActive; 
     151            } 
    146152            if (InputHandler.HasKeyBeenPressed(Keys.F4)) 
    147153                IsFixedTimeStep = !IsFixedTimeStep; 
     
    157163                if (p != null) 
    158164                    p.Update(); 
     165            //players[0].Update(); 
    159166 
    160167            camera.Update(); 
    161168 
    162169            level.Update(); 
     170 
     171            guiManager.Update(); 
    163172 
    164173            updates++; 
     
    167176            { 
    168177                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; 
    170180                frames = updates = 0; 
    171181            } 
     
    174184        } 
    175185 
    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> 
    180186        protected override void Draw(GameTime gameTime) 
    181187        { 
     
    188194            level.RenderEntities(camera, renderer); 
    189195 
     196            guiManager.Render(renderer); 
    190197            camera.RenderCursor(renderer); 
    191198            renderer.EndRender(); 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/RenderHelper.cs

    r4535 r4694  
    1111        private bool isRendering = false; 
    1212        private Point renderOffset = Point.Zero; 
     13        private static Texture2D empty; 
    1314 
    1415        public RenderHelper(SpriteBatch batch) 
     
    1617            registeredSpriteSheets = new List<SpriteSheet>(); 
    1718            renderer = batch; 
     19            empty = new Texture2D(batch.GraphicsDevice, 1, 1); 
     20            uint[] c = { 0xFFFFFFFF }; 
     21            empty.SetData(c); 
    1822        } 
     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; } } 
    1929 
    2030        public int RegisterSpriteSheet(SpriteSheet spriteSheet) 
     
    93103            renderer.Draw(sp.SheetTexture, new Rectangle((int)(texturePos.X * scale), (int)(texturePos.Y * scale), width, height), sp[spriteX, spriteY], Color.White); 
    94104        } 
    95  
    96105    } 
    97106} 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Resources.cs

    r4635 r4694  
    1313        public static int SPRITE_KING { get; private set; } 
    1414        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; } 
    1519 
    1620        public static void LoadResources(ContentManager cm, RenderHelper renderer) 
     
    2226            SPRITESHEET_RANGER = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/archer"), 32, 32)); 
    2327            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)); 
    2429            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"); 
    2533        } 
    2634    } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/Player.cs

    r4671 r4694  
    1212    public abstract class Player 
    1313    { 
    14         public const int LUMBER_WORTH = 2; 
    1514        public const int START_MONEY = 20; 
    1615        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; 
    1720 
    1821        protected Team team; 
     
    2124        protected UnitKing king; 
    2225        protected UnitStore store; 
     26        protected UnitArmory armory; 
     27        protected Point[] spawnPoints; 
    2328 
    2429        public Player(Team team, Level level, Camera camera) 
     
    2934            LumberAmount = START_LUMBER; 
    3035            CoinsAmount = 20; 
     36             
     37            spawnPoints = new Point[3]; 
    3138 
    3239            king = new UnitKing(level, this); 
    3340            store = new UnitStore(level, this); 
     41            armory = new UnitArmory(level, this); 
    3442        } 
    3543 
    3644        public Point HomePoint { get; set; } 
    3745 
    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; } } 
    4347 
    4448        public UnitKing King { get { return king; } } 
    4549 
    4650        public UnitStore Store { get { return store; } } 
     51 
     52        public UnitArmory Armory { get { return armory; } } 
    4753 
    4854        public List<Unit> AvailableUnits { get { return level.Units[Team.ID]; } } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerAI.cs

    r4671 r4694  
    3535 
    3636            unitTypes = new List<Type>(); 
     37            unitTypes.Add(typeof(MobWarrior)); 
    3738            unitTypes.Add(typeof(MobRanger)); 
    38             unitTypes.Add(typeof(MobWarrior)); 
    3939 
    4040            currentBrain = availableStates[0]; 
     
    5353        public override void OnLevelLoaded() 
    5454        { 
    55             ReThinkBestState(); 
    5655        } 
    5756 
     
    7877                Console.WriteLine("New state:" + currentBrain); 
    7978            } 
     79            else 
     80                currentBrain.OnStateReChosen(); 
    8081        } 
    8182 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerReal.cs

    r4646 r4694  
    7171                    if (selectedUnit != null) 
    7272                    { 
     73                        selectedUnit.OnFocusLost(); 
    7374                        selectedUnit.IsSelected = false; 
    7475                        selectedUnit = null; 
     
    7677                    selectedMobUnits.Add((Mob)u); 
    7778                    u.IsSelected = true; 
     79                    u.OnFocus(); 
    7880                } 
    7981                else 
    8082                { 
    81                     selectedMobUnits.ForEach(m => m.IsSelected = false); 
     83                    selectedMobUnits.ForEach(delegate(Mob m) 
     84                    { 
     85                        m.OnFocusLost(); 
     86                        m.IsSelected = false; 
     87                    }); 
     88 
    8289                    selectedMobUnits.Clear(); 
    8390 
    8491                    if (selectedUnit != null) 
     92                    { 
     93                        selectedUnit.OnFocusLost(); 
    8594                        selectedUnit.IsSelected = false; 
     95                    } 
    8696                    selectedUnit = null; 
    8797                    if (u != null) 
     
    93103 
    94104                        u.IsSelected = true; 
     105                        u.OnFocus(); 
    95106                    } 
    96107                } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs

    r4671 r4694  
    6565            if (te == null) 
    6666                return; 
    67             isChopping = true; 
    6867            currentOrderType = OrderType.CHOP; 
    6968            currentTarget = te; 
     
    119118            if (isChopping) 
    120119            { 
     120                if (currentTarget == null) 
     121                { 
     122                    StopChopping(); 
     123                    OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false); 
     124                } 
    121125                TurnTowards(currentTarget.X, currentTarget.Z); 
    122126                choppingAnimation.UpdateStep(); 
     
    127131                { 
    128132                    StopChopping(); 
    129                     StopCurrentOrder(); 
     133                    OrderChop(level.GetNearestEntity<TileEntityTree>(this, 5), 1, false); 
    130134                } 
    131135            } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Unit.cs

    r4671 r4694  
    5959            Health = maxHealth; 
    6060        } 
     61 
     62        public virtual void OnFocus() { } 
     63 
     64        public virtual void OnFocusLost() { } 
    6165 
    6266        public virtual bool CanBeHurtBy(Unit u) 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitKing.cs

    r4671 r4694  
    2020            depth = 5 * Viewport.TILESIZE; 
    2121            HasHealth = true; 
    22             maxHealth = 500; 
     22            maxHealth = 400; 
    2323 
    2424            isSolid = true; 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitStore.cs

    r4671 r4694  
    77using CastleMaster.Graphics; 
    88using CastleMaster.Units.Mobs; 
     9using CastleMaster.Guis; 
    910 
    1011namespace CastleMaster.Units 
     
    1213    public class UnitStore : Unit 
    1314    { 
    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; 
    1816        private bool isDestroyed = false; 
     17        private GuiStoreMenu menu; 
    1918 
    2019        public UnitStore(Level level, Player owner) 
     
    2423            depth = 8 * Viewport.TILESIZE; 
    2524            HasHealth = true; 
    26             maxHealth = 200; 
     25            maxHealth = 400; 
    2726            immunityTime = 20; 
    2827 
     
    4039            rectOffset.Update(-4 * Viewport.TILESIZE, -4 * Viewport.TILESIZE, 4 * Viewport.TILESIZE, 4 * Viewport.TILESIZE); 
    4140 
    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); 
    4642        } 
    4743 
    48         public T BuyUnit<T>(Type toBuy = null) where T : Mob 
     44        public void SellWood() 
    4945        { 
    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            } 
    5651        } 
    5752 
    5853        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        } 
    5964 
    6065        public override void OnRemoved() 
     
    7580            } 
    7681 
     82            menu.Remove(); 
    7783            level.RemoveUnit(this); 
    7884        } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs

    r4671 r4694  
    1313using System; 
    1414using System.Diagnostics; 
     15using CastleMaster.Guis; 
    1516 
    1617namespace CastleMaster.World 
     
    113114        { 
    114115            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; 
    116117 
    117118            int x0 = (int)((camera.XLeft / Viewport.FLOOR_TILE_WIDTH) / Viewport.ZOOM) - 3; 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/LevelForest.cs

    r4671 r4694  
    1313    public class LevelForest : Level 
    1414    { 
    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; 
    1616         
    1717        public LevelForest(Texture2D tileMap) 
     
    3131            TILE_STORE2_HINT = new TileRenderHint(this, Players[1].Store, true, true).ID; 
    3232            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; 
    3335        } 
    3436 
     
    4244            lb.AddTile(0xFF606060, TILE_KING1_HINT2); 
    4345            lb.AddTile(0xFF505050, TILE_STORE1_HINT); 
     46            lb.AddTile(0xFF50505B, TILE_ARMORY1_HINT); 
    4447 
    4548            lb.AddTile(0xFF707071, TILE_KING2_HINT); 
    4649            lb.AddTile(0xFF606061, TILE_KING2_HINT2); 
    4750            lb.AddTile(0xFF505051, TILE_STORE2_HINT); 
     51            lb.AddTile(0xFF60606B, TILE_ARMORY2_HINT); 
    4852 
    4953            lb.AddTile(0xFF808080, TILE_FLOOR_SOLID); 
     
    8589            lb.AddCustom(0xFF00FF20, delegate(Level level, int xTile, int zTile) 
    8690            { 
    87                 Players[1].WoodcutterSpawnPoint = new Point(xTile, zTile); 
     91                Players[1].SpawnPoints[Player.SPAWN_WOODCUTTER] = new Point(xTile, zTile); 
    8892            }); 
    8993 
    9094            lb.AddCustom(0xFF00FF30, delegate(Level level, int xTile, int zTile) 
    9195            { 
    92                 Players[1].WarriorSpawnPoint = new Point(xTile, zTile); 
     96                Players[1].SpawnPoints[Player.SPAWN_WARRIOR] = new Point(xTile, zTile); 
    9397            }); 
    9498 
    9599            lb.AddCustom(0xFF00FF40, delegate(Level level, int xTile, int zTile) 
    96100            { 
    97                 Players[1].RangerSpawnPoint = new Point(xTile, zTile); 
     101                Players[1].SpawnPoints[Player.SPAWN_RANGER] = new Point(xTile, zTile); 
    98102            }); 
    99103 
     
    115119            lb.AddCustom(0xFF00FF11, delegate(Level level, int xTile, int zTile) 
    116120            { 
    117                 Players[0].WoodcutterSpawnPoint = new Point(xTile, zTile); 
     121                Players[0].SpawnPoints[Player.SPAWN_WOODCUTTER] = new Point(xTile, zTile); 
    118122            }); 
    119123 
    120124            lb.AddCustom(0xFF00FF21, delegate(Level level, int xTile, int zTile) 
    121125            { 
    122                 Players[0].WarriorSpawnPoint = new Point(xTile, zTile); 
     126                Players[0].SpawnPoints[Player.SPAWN_WARRIOR] = new Point(xTile, zTile); 
    123127            }); 
    124128 
    125129            lb.AddCustom(0xFF00FF31, delegate(Level level, int xTile, int zTile) 
    126130            { 
    127                 Players[0].RangerSpawnPoint = new Point(xTile, zTile); 
     131                Players[0].SpawnPoints[Player.SPAWN_RANGER] = new Point(xTile, zTile); 
    128132            }); 
    129133 
     
    136140                level.AddEntity(Players[1].Store, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 
    137141            }); 
     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            }); 
    138146 
    139147            lb.AddCustom(0xFFFF6A00, delegate(Level level, int xTile, int zTile) 
     
    144152            { 
    145153                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); 
    146158            }); 
    147159 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj

    r4646 r4694  
    154154    </Compile> 
    155155  </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> 
    156184  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    157185  <!--  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.