Changeset 4590 for 2013/30


Ignore:
Timestamp:
2013-07-23 19:11:27 (10 years ago)
Author:
dezhidki
Message:

Puut lisätty, woodcutter toimii.

Location:
2013/30/DenisZ/CastleMaster/CastleMaster
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AStar.cs

    r4581 r4590  
    5555        } 
    5656 
    57         public void InitializePathFinder(int xStart, int zStart, int xEnd, int zEnd) 
    58         { 
    59             tiles = level.BuildSolidnessTable(mob); 
     57        public void InitializePathFinder(int xStart, int zStart, int xEnd, int zEnd, bool ignoreSolidnessForEnd) 
     58        { 
     59            tiles = level.BuildSolidnessTable(mob, ignoreSolidnessForEnd, xEnd, zEnd); 
    6060            nodeMap = new Node[level.Width * level.Height]; 
    6161            open.Clear(); 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/Orders/OrderMove.cs

    r4581 r4590  
    1313        private float x, z; 
    1414        private int ppi = 0; 
     15        private bool excludeEndSolidness; 
     16        private float stopDistance; 
    1517 
    16         public OrderMove(float x, float z) 
     18        public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false) 
    1719        { 
     20            this.stopDistance = stopDistance; 
     21            this.excludeEndSolidness = excludeEndSolidness; 
    1822            this.x = x; 
    1923            this.z = z; 
     
    2327        { 
    2428            base.Initialize(mob); 
    25             mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE)); 
     29            mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 
    2630            return this; 
    2731        } 
     
    6266            get 
    6367            { 
    64                 return (mob.DistanceTo(x, z) < 2.0F) || !mob.PathFinder.CanFindPath; 
     68                return (mob.DistanceTo(x, z) < stopDistance) || !mob.PathFinder.CanFindPath; 
    6569            } 
    6670        } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj

    r4581 r4590  
    8181    <Compile Include="Entities\TileEntities\TileEntity.cs" /> 
    8282    <Compile Include="Entities\TileEntities\TileEntityBlock.cs" /> 
     83    <Compile Include="Entities\TileEntities\TileEntityTree.cs" /> 
    8384    <Compile Include="Graphics\AnimationHelper.cs" /> 
    8485    <Compile Include="Graphics\Camera.cs" /> 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/Entity.cs

    r4581 r4590  
    5151 
    5252        protected Vector2 ScreenPos { get { return screenPos * Viewport.ZOOM; } } 
     53 
     54        public virtual void Remove() 
     55        { 
     56            Removed = true; 
     57        } 
    5358 
    5459        public virtual void Init() 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs

    r4581 r4590  
    6161            graphics.PreferredBackBufferWidth = WIDTH; 
    6262            graphics.PreferredBackBufferHeight = HEIGHT; 
    63             graphics.SynchronizeWithVerticalRetrace = true; 
     63            graphics.SynchronizeWithVerticalRetrace = false; 
    6464            graphics.ApplyChanges(); 
    6565            Window.Title = TITLE; 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/AnimationHelper.cs

    r4535 r4590  
    1  
     1using System; 
     2 
    23namespace CastleMaster.Graphics 
    34{ 
     
    67        private int currentFrame, minFrame, maxFrame, currentTicks, ticksPerFrame; 
    78        private bool isRunning = false, runOnce; 
     9 
     10        public event Action RoundEnded; 
     11        public event Action AnimationEnded; 
    812 
    913        public AnimationHelper(int ticksPerFrame, int maxFrame, bool runOnce = false, int minFrame = 0, int currentFrame = 0) 
     
    4650        public void UpdateStep() 
    4751        { 
    48             currentTicks++; 
     52            if (isRunning) 
     53            { 
     54                currentTicks++; 
    4955 
    50             if (currentTicks > ticksPerFrame) 
    51             { 
    52                 currentFrame++; 
    53                 if (currentFrame > maxFrame) 
     56                if (currentTicks > ticksPerFrame) 
    5457                { 
    55                     if (runOnce) Stop(); 
    56                     else currentFrame = 0; 
     58                    currentFrame++; 
     59                    if (currentFrame > maxFrame) 
     60                    { 
     61                        if (runOnce) 
     62                        { 
     63                            Stop(); 
     64                            if (AnimationEnded != null) 
     65                                AnimationEnded(); 
     66                        } 
     67                        else 
     68                        { 
     69                            currentFrame = minFrame; 
     70                            if (RoundEnded != null) 
     71                                RoundEnded(); 
     72                        } 
     73                    } 
     74 
     75                    currentTicks = 0; 
    5776                } 
    58  
    59                 currentTicks = 0; 
    6077            } 
    6178        } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Camera.cs

    r4581 r4590  
    4848 
    4949        public Vector2 MouseWorldPos { get { return mouseWorldPos; } } 
     50 
     51        public Point MouseTilePos { get { return mouseTilePos; } } 
    5052        #endregion 
    5153 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/Mob.cs

    r4581 r4590  
    2626            currentOrder = new Order(); 
    2727            pathFinder = new AStar(level, this); 
     28            walkingAnimation = new AnimationHelper(10, 2).Start(); 
    2829        } 
    2930 
     
    3738                currentOrder.Update(); 
    3839                if (currentOrder.Finished) 
    39                     GetNextOrder(); 
     40                { 
     41                    StopCurrentOrder(); 
     42                } 
    4043            } 
     44        } 
     45 
     46        protected void StopCurrentOrder() 
     47        { 
     48            OnOrderFinished(); 
     49            SetOrder(GetNextOrder()); 
     50        } 
     51 
     52        protected virtual void OnOrderFinished() 
     53        { 
     54            walkingAnimation.Reset(); 
    4155        } 
    4256 
     
    5670            float moveZ = (float)Math.Sin(dir) * moveSpeed; 
    5771 
    58             return Move(moveX, moveZ); 
     72            if (Move(moveX, moveZ)) 
     73            { 
     74                walkingAnimation.UpdateStep(); 
     75                return true; 
     76            } 
     77 
     78            return false; 
    5979        } 
    6080 
    61         public virtual void GetNextOrder() 
     81        public virtual Order GetNextOrder() 
    6282        { 
    63             SetOrder(new Order()); 
     83            return new Order(); 
    6484        } 
    6585 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs

    r4581 r4590  
    77using CastleMaster.Graphics; 
    88using IsometricEngineTest.Ai.Orders; 
     9using Microsoft.Xna.Framework; 
     10using CastleMaster.Entities.TileEntities; 
    911 
    1012namespace CastleMaster.Units.Mobs 
     
    1214    public class MobWoodcutter : Mob 
    1315    { 
     16        private TileEntityTree currentTarget; 
     17        private bool isChopping = false, isOrderedToChop = false; 
     18        private AnimationHelper choppingAnimation; 
     19        private AnimationHelper choppingTimer; 
     20        private int currentSpriteX; 
     21 
    1422        public MobWoodcutter(Level level, Player owner) 
    1523            : base(level, owner) 
     
    2028            renderOffset.Y = 20; 
    2129 
    22             highlightOffset.X = 10; 
     30            highlightOffset.X = 11; 
    2331 
    2432            rectOffset.Update(-4.0F, -4.0F, 5.0F, 5.0F); 
     
    2634 
    2735            moveSpeed = 1.0F; 
     36            choppingAnimation = new AnimationHelper(10, 5, false, 3); 
     37            choppingTimer = new AnimationHelper(30, 1); 
     38            choppingTimer.RoundEnded += delegate() 
     39            { 
     40                currentTarget.AvaliableLogs--; 
     41                if (currentTarget.AvaliableLogs <= 0) 
     42                { 
     43                    StopChopping(); 
     44                    currentTarget.Remove(); 
     45                    currentTarget = null; 
     46                } 
     47            }; 
     48        } 
    2849 
    29             walkingAnimation = new AnimationHelper(10, 5); 
     50        private void StartChopping() 
     51        { 
     52            choppingAnimation.Start(); 
     53            choppingTimer.Start(); 
     54            isChopping = true; 
     55        } 
     56 
     57        private void StopChopping() 
     58        { 
     59            isChopping = false; 
     60            isOrderedToChop = false; 
     61            choppingAnimation.Stop(); 
     62            choppingAnimation.Reset(); 
     63            choppingTimer.Stop(); 
     64            choppingTimer.Reset(); 
    3065        } 
    3166 
    3267        public override void OnFunctionClick() 
    3368        { 
    34             SetOrder(new OrderMove(Owner.Camera.MouseWorldPos.X, Owner.Camera.MouseWorldPos.Y)); 
     69            TileEntity te = level.GetTileEntity(Owner.Camera.MouseTilePos.X, Owner.Camera.MouseTilePos.Y); 
     70            if (te != null && typeof(TileEntityTree).IsAssignableFrom(te.GetType())) 
     71            { 
     72                if (currentTarget != null) StopChopping(); 
     73                isOrderedToChop = true; 
     74                currentTarget = (TileEntityTree)te; 
     75                SetOrder(new OrderMove(te.X, te.Z, 20.0F, true)); 
     76            } 
     77            else 
     78            { 
     79                if (isChopping) 
     80                { 
     81                    StopChopping(); 
     82                    currentTarget = null; 
     83                } 
     84                SetOrder(new OrderMove(Owner.Camera.MouseWorldPos.X, Owner.Camera.MouseWorldPos.Y)); 
     85            } 
     86        } 
     87 
     88        protected override void OnOrderFinished() 
     89        { 
     90            if (isOrderedToChop) 
     91                StartChopping(); 
    3592        } 
    3693 
     
    3895        { 
    3996            base.Update(); 
    40             walkingAnimation.UpdateStep(); 
     97 
     98            if (isChopping) 
     99            { 
     100                choppingAnimation.UpdateStep(); 
     101                choppingTimer.UpdateStep(); 
     102            } 
     103 
     104            currentSpriteX = isChopping ? choppingAnimation.CurrentFrame : walkingAnimation.CurrentFrame; 
    41105        } 
    42106 
     
    44108        { 
    45109            base.Render(renderer); 
    46             renderer.Render(ScreenPos, 0, dirID, Resources.SPRITESHEET_WOODCUTTER, Viewport.ZOOM); 
     110            renderer.Render(ScreenPos, currentSpriteX, dirID, Resources.SPRITESHEET_WOODCUTTER, Viewport.ZOOM); 
    47111        } 
    48112    } 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs

    r4581 r4590  
    1111using CastleMaster.Units; 
    1212using CastleMaster.Units.Mobs; 
     13using System; 
    1314 
    1415namespace CastleMaster.World 
     
    6061        protected Texture2D tileMap; 
    6162        private EntityComprarer comparer = new EntityComprarer(); 
    62         private AnimationHelper waterAnimation = new AnimationHelper(10, 2); 
     63        private AnimationHelper waterAnimation = new AnimationHelper(10, 2).Start(); 
    6364        private Player[] players; 
    6465 
     
    165166 
    166167                if (tileEntities.Count > 0) 
    167                     tileEntities[Game.Random.Next(tileEntities.Count)].Update(); 
     168                { 
     169                    TileEntity te = tileEntities[Game.Random.Next(tileEntities.Count)]; 
     170                    te.Update(); 
     171                    if (te.Removed) 
     172                    { 
     173                        RemoveEntity(te); 
     174                        TakeEntity(te, te.XTile, te.ZTile); 
     175                    } 
     176                } 
    168177            } 
    169178 
     
    175184                ent.Update(); 
    176185 
    177                 //if (ent.Removed) 
    178                 //{ 
    179                 //    RemoveEntity(ent); 
    180                 //    TakeEntity(ent, xTile_old, zTile_old); 
    181                 //    continue; 
    182                 //} 
     186                if (ent.Removed) 
     187                { 
     188                    RemoveEntity(ent); 
     189                    TakeEntity(ent, xTile_old, zTile_old); 
     190                    continue; 
     191                } 
    183192 
    184193                int xTile = (int)(ent.X / Viewport.TILESIZE); 
     
    237246                entities.Add(ent); 
    238247 
    239             if(typeof(Unit).IsAssignableFrom(ent.GetType())) 
     248            if (typeof(Unit).IsAssignableFrom(ent.GetType())) 
    240249            { 
    241250                Unit u = (Unit)ent; 
     
    263272 
    264273            TakeEntity(ent, (int)(ent.X / Viewport.TILESIZE), (int)(ent.Z / Viewport.TILESIZE)); 
     274        } 
     275 
     276        //public Vector2 GetNearestEmptyTileWorldPos(int xTile, int zTile, Entity ent) 
     277        //{ 
     278        //    int xt = 0, zt = 0; 
     279        //    for (int z = zTile - 1; z <= zTile + 1; z++) 
     280        //    { 
     281        //        for (int x = xTile - 1; x <= xTile + 1; x++) 
     282        //        { 
     283        //            if (x == xTile && z == zTile) continue; 
     284        //            int tp = xTile + zTile * width; 
     285 
     286        //            if (registeredTiles[tiles[tp]].IsSolid) continue; 
     287 
     288        //            TileEntity te = GetTileEntity(xTile, zTile); 
     289        //            if (te != null && te.IsSolidTo(ent)) continue; 
     290        //            xt = x; 
     291        //            zt = z; 
     292        //        } 
     293        //    } 
     294 
     295        //    if (xt != 0 || zt != 0) 
     296        //        return new Vector2(xt * Viewport.TILESIZE + 8.0F, zt * Viewport.TILESIZE + 8.0F); 
     297 
     298        //    return new Vector2(-1, -1); 
     299        //} 
     300 
     301        public TileEntity GetTileEntity(int xTile, int zTile) 
     302        { 
     303            List<Entity> ents = entitiesInTiles[xTile + zTile * width]; 
     304            if (ents.Count > 0) 
     305                return ents[0] as TileEntity; 
     306 
     307            return null; 
    265308        } 
    266309 
     
    318361        } 
    319362 
    320         public bool[] BuildSolidnessTable(Mob mob) 
     363        public bool[] BuildSolidnessTable(Mob mob, bool excludeEndSolidness = false, int xEnd = 0, int zEnd = 0) 
    321364        { 
    322365            bool[] result = new bool[tiles.Length]; 
     
    324367            for (int i = 0; i < tiles.Length; i++) 
    325368            { 
     369                if (excludeEndSolidness && xEnd == i % width && zEnd == i / width) 
     370                { 
     371                    result[i] = false; 
     372                    continue; 
     373                } 
     374 
    326375                result[i] = tiles[i] == TILE_VOID || registeredTiles[tiles[i]].IsSolid; 
    327376 
  • 2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/LevelTest.cs

    r4581 r4590  
    4747            lb.AddEntity(0xFF00FF00, typeof(TileEntityBlock), 8.0F, 8.0F, this, 6, 0); 
    4848            lb.AddEntity(0xFFFF0000, typeof(MobWoodcutter), 8.0F, 8.0F, this, Players[0]); 
     49            lb.AddEntity(0xFF7F3300, typeof(TileEntityTree), 8.0F, 8.0F, this, 1); 
     50            lb.AddTile(0xFF7F3300, TILE_FLOOR); 
    4951 
    5052            lb.BuildLevel(); 
Note: See TracChangeset for help on using the changeset viewer.