- Timestamp:
- 2013-07-23 19:11:27 (10 years ago)
- 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 55 55 } 56 56 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); 60 60 nodeMap = new Node[level.Width * level.Height]; 61 61 open.Clear(); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/Orders/OrderMove.cs
r4581 r4590 13 13 private float x, z; 14 14 private int ppi = 0; 15 private bool excludeEndSolidness; 16 private float stopDistance; 15 17 16 public OrderMove(float x, float z )18 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false) 17 19 { 20 this.stopDistance = stopDistance; 21 this.excludeEndSolidness = excludeEndSolidness; 18 22 this.x = x; 19 23 this.z = z; … … 23 27 { 24 28 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); 26 30 return this; 27 31 } … … 62 66 get 63 67 { 64 return (mob.DistanceTo(x, z) < 2.0F) || !mob.PathFinder.CanFindPath;68 return (mob.DistanceTo(x, z) < stopDistance) || !mob.PathFinder.CanFindPath; 65 69 } 66 70 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj
r4581 r4590 81 81 <Compile Include="Entities\TileEntities\TileEntity.cs" /> 82 82 <Compile Include="Entities\TileEntities\TileEntityBlock.cs" /> 83 <Compile Include="Entities\TileEntities\TileEntityTree.cs" /> 83 84 <Compile Include="Graphics\AnimationHelper.cs" /> 84 85 <Compile Include="Graphics\Camera.cs" /> -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/Entity.cs
r4581 r4590 51 51 52 52 protected Vector2 ScreenPos { get { return screenPos * Viewport.ZOOM; } } 53 54 public virtual void Remove() 55 { 56 Removed = true; 57 } 53 58 54 59 public virtual void Init() -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4581 r4590 61 61 graphics.PreferredBackBufferWidth = WIDTH; 62 62 graphics.PreferredBackBufferHeight = HEIGHT; 63 graphics.SynchronizeWithVerticalRetrace = true;63 graphics.SynchronizeWithVerticalRetrace = false; 64 64 graphics.ApplyChanges(); 65 65 Window.Title = TITLE; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/AnimationHelper.cs
r4535 r4590 1 1 using System; 2 2 3 namespace CastleMaster.Graphics 3 4 { … … 6 7 private int currentFrame, minFrame, maxFrame, currentTicks, ticksPerFrame; 7 8 private bool isRunning = false, runOnce; 9 10 public event Action RoundEnded; 11 public event Action AnimationEnded; 8 12 9 13 public AnimationHelper(int ticksPerFrame, int maxFrame, bool runOnce = false, int minFrame = 0, int currentFrame = 0) … … 46 50 public void UpdateStep() 47 51 { 48 currentTicks++; 52 if (isRunning) 53 { 54 currentTicks++; 49 55 50 if (currentTicks > ticksPerFrame) 51 { 52 currentFrame++; 53 if (currentFrame > maxFrame) 56 if (currentTicks > ticksPerFrame) 54 57 { 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; 57 76 } 58 59 currentTicks = 0;60 77 } 61 78 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Camera.cs
r4581 r4590 48 48 49 49 public Vector2 MouseWorldPos { get { return mouseWorldPos; } } 50 51 public Point MouseTilePos { get { return mouseTilePos; } } 50 52 #endregion 51 53 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/Mob.cs
r4581 r4590 26 26 currentOrder = new Order(); 27 27 pathFinder = new AStar(level, this); 28 walkingAnimation = new AnimationHelper(10, 2).Start(); 28 29 } 29 30 … … 37 38 currentOrder.Update(); 38 39 if (currentOrder.Finished) 39 GetNextOrder(); 40 { 41 StopCurrentOrder(); 42 } 40 43 } 44 } 45 46 protected void StopCurrentOrder() 47 { 48 OnOrderFinished(); 49 SetOrder(GetNextOrder()); 50 } 51 52 protected virtual void OnOrderFinished() 53 { 54 walkingAnimation.Reset(); 41 55 } 42 56 … … 56 70 float moveZ = (float)Math.Sin(dir) * moveSpeed; 57 71 58 return Move(moveX, moveZ); 72 if (Move(moveX, moveZ)) 73 { 74 walkingAnimation.UpdateStep(); 75 return true; 76 } 77 78 return false; 59 79 } 60 80 61 public virtual voidGetNextOrder()81 public virtual Order GetNextOrder() 62 82 { 63 SetOrder(new Order());83 return new Order(); 64 84 } 65 85 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs
r4581 r4590 7 7 using CastleMaster.Graphics; 8 8 using IsometricEngineTest.Ai.Orders; 9 using Microsoft.Xna.Framework; 10 using CastleMaster.Entities.TileEntities; 9 11 10 12 namespace CastleMaster.Units.Mobs … … 12 14 public class MobWoodcutter : Mob 13 15 { 16 private TileEntityTree currentTarget; 17 private bool isChopping = false, isOrderedToChop = false; 18 private AnimationHelper choppingAnimation; 19 private AnimationHelper choppingTimer; 20 private int currentSpriteX; 21 14 22 public MobWoodcutter(Level level, Player owner) 15 23 : base(level, owner) … … 20 28 renderOffset.Y = 20; 21 29 22 highlightOffset.X = 1 0;30 highlightOffset.X = 11; 23 31 24 32 rectOffset.Update(-4.0F, -4.0F, 5.0F, 5.0F); … … 26 34 27 35 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 } 28 49 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(); 30 65 } 31 66 32 67 public override void OnFunctionClick() 33 68 { 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(); 35 92 } 36 93 … … 38 95 { 39 96 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; 41 105 } 42 106 … … 44 108 { 45 109 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); 47 111 } 48 112 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs
r4581 r4590 11 11 using CastleMaster.Units; 12 12 using CastleMaster.Units.Mobs; 13 using System; 13 14 14 15 namespace CastleMaster.World … … 60 61 protected Texture2D tileMap; 61 62 private EntityComprarer comparer = new EntityComprarer(); 62 private AnimationHelper waterAnimation = new AnimationHelper(10, 2) ;63 private AnimationHelper waterAnimation = new AnimationHelper(10, 2).Start(); 63 64 private Player[] players; 64 65 … … 165 166 166 167 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 } 168 177 } 169 178 … … 175 184 ent.Update(); 176 185 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 } 183 192 184 193 int xTile = (int)(ent.X / Viewport.TILESIZE); … … 237 246 entities.Add(ent); 238 247 239 if (typeof(Unit).IsAssignableFrom(ent.GetType()))248 if (typeof(Unit).IsAssignableFrom(ent.GetType())) 240 249 { 241 250 Unit u = (Unit)ent; … … 263 272 264 273 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; 265 308 } 266 309 … … 318 361 } 319 362 320 public bool[] BuildSolidnessTable(Mob mob )363 public bool[] BuildSolidnessTable(Mob mob, bool excludeEndSolidness = false, int xEnd = 0, int zEnd = 0) 321 364 { 322 365 bool[] result = new bool[tiles.Length]; … … 324 367 for (int i = 0; i < tiles.Length; i++) 325 368 { 369 if (excludeEndSolidness && xEnd == i % width && zEnd == i / width) 370 { 371 result[i] = false; 372 continue; 373 } 374 326 375 result[i] = tiles[i] == TILE_VOID || registeredTiles[tiles[i]].IsSolid; 327 376 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/LevelTest.cs
r4581 r4590 47 47 lb.AddEntity(0xFF00FF00, typeof(TileEntityBlock), 8.0F, 8.0F, this, 6, 0); 48 48 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); 49 51 50 52 lb.BuildLevel();
Note: See TracChangeset
for help on using the changeset viewer.