Changeset 4635 for 2013/30/DenisZ
- Timestamp:
- 2013-07-24 15:02:03 (8 years ago)
- Location:
- 2013/30/DenisZ/CastleMaster/CastleMaster
- Files:
-
- 3 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/AStar.cs
r4593 r4635 57 57 public void InitializePathFinder(int xStart, int zStart, int xEnd, int zEnd, bool ignoreSolidnessForEnd) 58 58 { 59 tiles = level.BuildSolidnessTable(mob, ignoreSolidnessForEnd , xEnd, zEnd);59 tiles = level.BuildSolidnessTable(mob, ignoreSolidnessForEnd); 60 60 nodeMap = new Node[level.Width * level.Height]; 61 61 open.Clear(); … … 100 100 canPathFind = false; 101 101 } 102 } 103 104 public void ApplySolidnessToPos(List<int> posList) 105 { 106 foreach (int i in posList) 107 tiles[i] = false; 102 108 } 103 109 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Ai/Orders/OrderMove.cs
r4592 r4635 17 17 private int moveFails = 0; 18 18 private float lastDist = 0.0F; 19 private bool shouldFindPath = false; 20 private bool createNewPathFinder; 19 21 20 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false )22 public OrderMove(float x, float z, float stopDistance = 2.0F, bool excludeEndSolidness = false, bool createNewPathFinder = true) 21 23 { 22 24 this.stopDistance = stopDistance; 23 25 this.excludeEndSolidness = excludeEndSolidness; 26 this.createNewPathFinder = createNewPathFinder; 24 27 this.x = x; 25 28 this.z = z; … … 29 32 { 30 33 base.Initialize(mob); 31 mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 34 35 if (createNewPathFinder && mob.DistanceTo(x, z) > 64.0F) 36 { 37 mob.PathFinder.InitializePathFinder((int)(mob.X / Viewport.TILESIZE), (int)(mob.Z / Viewport.TILESIZE), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), excludeEndSolidness); 38 shouldFindPath = true; 39 } 32 40 return this; 33 41 } … … 35 43 public override void Update() 36 44 { 37 if (!mob.PathFinder.CanFindPath) 38 return; 39 if (mob.PathFinder.IsPathFinding) 40 mob.PathFinder.FindPath(50); 45 if (shouldFindPath) 46 { 47 if (!mob.PathFinder.CanFindPath) 48 return; 49 if (mob.PathFinder.IsPathFinding) 50 mob.PathFinder.FindPath(50); 51 } 41 52 42 if ( mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count)53 if (shouldFindPath && mob.PathFinder.Path.Count > 0 && ppi < mob.PathFinder.Path.Count) 43 54 { 44 55 Node currentTarget = mob.PathFinder.Path[ppi]; … … 86 97 get 87 98 { 88 return (mob.DistanceTo(x, z) < stopDistance) || moveFails > 10|| !mob.PathFinder.CanFindPath;99 return (mob.DistanceTo(x, z) < stopDistance) || moveFails > 5 || !mob.PathFinder.CanFindPath; 89 100 } 90 101 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/CastleMaster.csproj
r4616 r4635 77 77 <Compile Include="Ai\Node.cs" /> 78 78 <Compile Include="Ai\Orders\Order.cs" /> 79 <Compile Include="Ai\Orders\OrderGoAround.cs" /> 79 80 <Compile Include="Ai\Orders\OrderMove.cs" /> 80 81 <Compile Include="Entities\Entity.cs" /> … … 107 108 <Compile Include="Units\Unit.cs" /> 108 109 <Compile Include="Units\UnitKing.cs" /> 110 <Compile Include="Units\UnitStore.cs" /> 109 111 <Compile Include="World\Level.cs" /> 110 112 <Compile Include="World\LevelBuilder.cs" /> -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/Entity.cs
r4616 r4635 55 55 protected Vector2 ScreenPos { get { return screenPos * Viewport.ZOOM; } } 56 56 57 public v irtual void Remove()57 public void Remove() 58 58 { 59 59 Removed = true; … … 86 86 public bool Move(float xd, float zd) 87 87 { 88 if (xd == 0.0F && zd == 0.0F) return false;88 if (xd == 0.0F && zd == 0.0F) return false; 89 89 90 90 if (BoundingRectangle.XRight + xd > level.Width * Viewport.TILESIZE) return false; -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Entities/EntityArrow.cs
r4616 r4635 10 10 using CastleMaster.Physics; 11 11 using CastleMaster.Graphics; 12 using System.Diagnostics; 12 13 13 14 namespace CastleMaster.Entities -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Game.cs
r4616 r4635 80 80 input.RegisterKeyboardKey(Keys.S); 81 81 input.RegisterKeyboardKey(Keys.D); 82 input.RegisterKeyboardKey(Keys.Z);83 input.RegisterKeyboardKey(Keys.X);84 82 input.RegisterKeyboardKey(Keys.F4); 83 input.RegisterKeyboardKey(Keys.ShiftKey); 84 input.RegisterKeyboardKey(Keys.ControlKey); 85 85 86 86 input.RegisterMouseKey(MouseButtons.Middle); -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/AnimationHelper.cs
r4590 r4635 20 20 currentTicks = 0; 21 21 } 22 23 public bool IsRunning { get { return isRunning; } } 22 24 23 25 public int CurrentFrame { get { return currentFrame; } } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Graphics/Resources.cs
r4616 r4635 12 12 public static int SPRITESHEET_RANGER { get; private set; } 13 13 public static int SPRITE_KING { get; private set; } 14 public static int SPRITE_STORE { get; private set; } 14 15 15 16 public static void LoadResources(ContentManager cm, RenderHelper renderer) … … 21 22 SPRITESHEET_RANGER = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/archer"), 32, 32)); 22 23 SPRITE_KING = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/king"), 160, 128)); 24 SPRITE_STORE = renderer.RegisterSpriteSheet(new SpriteSheet(cm.Load<Texture2D>("mobs/store"), 240, 147)); 23 25 } 24 26 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Players/PlayerReal.cs
r4592 r4635 9 9 using Microsoft.Xna.Framework; 10 10 using CastleMaster.Units; 11 using CastleMaster.Units.Mobs; 12 using System.Diagnostics; 11 13 12 14 namespace CastleMaster.Players … … 14 16 public class PlayerReal : Player 15 17 { 18 private const int SPEED_SLOW = 10; 19 private const int SPREED_FAST = 20; 20 16 21 private bool moveWorldWithMouse = false; 17 22 private Point oldMousePos; 18 23 private Unit selectedUnit; 24 private int cameraSpeed = 10; 25 private List<Mob> selectedMobUnits; 19 26 20 27 public PlayerReal(Team team, Level level, Camera camera) … … 22 29 { 23 30 oldMousePos = Point.Zero; 31 selectedMobUnits = new List<Mob>(); 24 32 } 25 33 26 34 public override void Update() 27 35 { 36 cameraSpeed = InputHandler.IsKeyDown(Keys.ShiftKey) ? SPREED_FAST : SPEED_SLOW; 37 38 if (InputHandler.IsKeyDown(Keys.W)) 39 camera.YTop -= cameraSpeed; 40 if (InputHandler.IsKeyDown(Keys.S)) 41 camera.YTop += cameraSpeed; 42 if (InputHandler.IsKeyDown(Keys.A)) 43 camera.XLeft -= cameraSpeed; 44 if (InputHandler.IsKeyDown(Keys.D)) 45 camera.XLeft += cameraSpeed; 46 28 47 if (InputHandler.HasMouseButtonBeenPressed(MouseButtons.Middle) || moveWorldWithMouse) 29 48 { … … 47 66 { 48 67 Unit u = SelectUnit(Team); 49 if (selectedUnit != null) 50 selectedUnit.IsSelected = false; 51 selectedUnit = u; 52 if (selectedUnit != null) 53 selectedUnit.IsSelected = true; 68 69 if (InputHandler.IsKeyDown(Keys.ControlKey) && u != null && u is Mob) 70 { 71 if (selectedUnit != null) 72 { 73 selectedUnit.IsSelected = false; 74 selectedUnit = null; 75 } 76 selectedMobUnits.Add((Mob)u); 77 u.IsSelected = true; 78 } 79 else 80 { 81 selectedMobUnits.ForEach(m => m.IsSelected = false); 82 selectedMobUnits.Clear(); 83 84 if (u != null) 85 { 86 if (!(u is Mob)) 87 selectedUnit = u; 88 else 89 selectedMobUnits.Add((Mob)u); 90 91 u.IsSelected = true; 92 } 93 } 54 94 } 55 95 … … 57 97 { 58 98 if (selectedUnit != null) 59 selectedUnit.OnFunctionClick(camera.MouseWorldPos.X, camera.MouseWorldPos.Y); 99 selectedUnit.OnFunctionClick(camera.MouseWorldPos.X, camera.MouseWorldPos.Y, false); 100 else if (selectedMobUnits.Count > 0) 101 selectedMobUnits[0].OnGroupOrder(selectedMobUnits, camera.MouseWorldPos.X, camera.MouseWorldPos.Y); 60 102 } 61 103 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/Mob.cs
r4616 r4635 11 11 using CastleMaster.Graphics; 12 12 using CastleMaster.Entities; 13 using System.Collections; 13 14 14 15 namespace CastleMaster.Units.Mobs 15 16 { 16 public class Mob : Unit17 public abstract class Mob : Unit 17 18 { 18 pr ivateOrder currentOrder;19 protected Order currentOrder; 19 20 private float dir = 0.0F; 20 pr ivateAStar pathFinder;21 protected AStar pathFinder; 21 22 protected int dirID; 22 23 protected AnimationHelper walkingAnimation; … … 36 37 pushResistance = 0.0F; 37 38 } 39 40 public Level Level { get { return level; } } 38 41 39 42 protected float Direction { get { return dir; } } … … 65 68 MoveTo(dir, pushPower); 66 69 isPushed = false; 70 } 71 } 72 73 public void OnGroupOrder(List<Mob> mobs, float x, float z) 74 { 75 foreach (var mobGroup in mobs.GroupBy(m => m.TypeID)) 76 { 77 List<Mob> ms = mobGroup.ToList(); 78 ms[0].OnSameTypeGroupOrder(ms, x, z); 79 } 80 } 81 82 protected virtual void OnSameTypeGroupOrder(List<Mob> mobs, float x, float z) 83 { 84 OnFunctionClick(x, z, false); 85 foreach (Mob m in mobs) 86 { 87 if (m == this) continue; 88 m.OnFunctionClick(x, z, true); 89 m.pathFinder = pathFinder; 67 90 } 68 91 } … … 156 179 return (int)(Math.Floor(dir * 8 / MathHelper.TwoPi + 0.5F)) & 7; 157 180 } 181 182 public abstract int TypeID { get; } 158 183 } 159 184 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobRanger.cs
r4616 r4635 15 15 private enum OrderType { ATTACK, WALK, NONE } 16 16 17 private const float ATTACK_RANGE = 60.0F;18 private const float ATTACK_RANGE_SQR = ATTACK_RANGE * ATTACK_RANGE;17 private float ATTACK_RANGE_OFFSET = 20.0F; 18 private float attackRange, attackRangeSqr; 19 19 20 20 private Unit target; 21 21 private OrderType currentOrderType = OrderType.NONE; 22 22 private bool isAttacking = false; 23 private int maxDamage = 5;23 private int maxDamage = 4; 24 24 private AnimationHelper hitAnimation; 25 25 private int spriteX; 26 private float pushPower = 5.0F;26 private float pushPower = 2.0F; 27 27 28 28 public MobRanger(Level level, Player owner) … … 30 30 { 31 31 HasHealth = true; 32 maxHealth = 50;32 maxHealth = 30; 33 33 34 34 spriteSize.X = 17; … … 41 41 rectOffset.Update(-4.0F, -4.0F, 5.0F, 5.0F); 42 42 isSolid = true; 43 moveSpeed = 1. 0F;44 hitAnimation = new AnimationHelper( 10, 5, false, 3);43 moveSpeed = 1.6F; 44 hitAnimation = new AnimationHelper(5, 5, false, 3); 45 45 hitAnimation.RoundEnded += delegate() 46 46 { 47 47 if (target != null) 48 level.AddEntity(new EntityArrow(level, 5, 2.0F, target, this, Owner.Team), X + (float)Math.Cos(Direction) * 2.0F, Z + (float)Math.Sin(Direction) * 2.0F);48 level.AddEntity(new EntityArrow(level, Game.Random.Next(0, maxDamage + 1), pushPower, target, this, Owner.Team), X + (float)Math.Cos(Direction) * 2.0F, Z + (float)Math.Sin(Direction) * 2.0F); 49 49 }; 50 } 51 52 public override int TypeID 53 { 54 get { return 1; } 50 55 } 51 56 … … 70 75 } 71 76 72 private void CreateAttackOrder(Unit u )77 private void CreateAttackOrder(Unit u, bool wasCalledBefore) 73 78 { 74 79 currentOrderType = OrderType.ATTACK; 75 SetOrder(new OrderMove(u.X, u.Z, ATTACK_RANGE, true)); 80 attackRange = u.Width + ATTACK_RANGE_OFFSET; 81 attackRangeSqr = attackRange * attackRange; 82 SetOrder(new OrderMove(u.X, u.Z, attackRange, true, !wasCalledBefore)); 76 83 target = u; 77 84 } … … 81 88 base.Damage(attacker, damage, dir, pushPower); 82 89 if (!isAttacking && currentOrderType == OrderType.NONE) 83 CreateAttackOrder(attacker );90 CreateAttackOrder(attacker, false); 84 91 } 85 92 … … 93 100 } 94 101 95 public override void OnFunctionClick(float x, float z )102 public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 96 103 { 97 104 Unit u = Owner.SelectUnit(Game.GetEnemyTeam(Owner.Team)); 98 105 if (u != null) 99 CreateAttackOrder(u );106 CreateAttackOrder(u, wasCalledBefore); 100 107 else 101 108 { 102 109 if (target != null) StopAttack(); 103 110 currentOrderType = OrderType.WALK; 104 SetOrder(new OrderMove(x, z ));111 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore)); 105 112 } 106 113 } … … 112 119 if (isAttacking) 113 120 { 114 if (DistanceToSqr(target.X, target.Z) > ATTACK_RANGE_SQR)121 if (DistanceToSqr(target.X, target.Z) > attackRangeSqr) 115 122 { 116 123 isAttacking = false; 117 CreateAttackOrder(target );124 CreateAttackOrder(target, false); 118 125 } 119 126 else … … 129 136 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 4); 130 137 if (units.Count > 0) 131 CreateAttackOrder(units[0] );138 CreateAttackOrder(units[0], false); 132 139 } 133 140 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWarrior.cs
r4616 r4635 15 15 private enum OrderType { ATTACK, WALK, NONE } 16 16 17 private const float ATTACK_RANGE= 20.0F;18 private const float ATTACK_RANGE_SQR = ATTACK_RANGE * ATTACK_RANGE;17 private float ATTACK_RANGE_OFFSET = 20.0F; 18 private float attackRange, attackRangeSqr; 19 19 20 20 private Unit target; 21 21 private OrderType currentOrderType = OrderType.NONE; 22 22 private bool isAttacking = false; 23 private int maxDamage = 5;23 private int maxDamage = 7; 24 24 private AnimationHelper hitAnimation; 25 25 private int spriteX; … … 41 41 rectOffset.Update(-4.0F, -4.0F, 5.0F, 5.0F); 42 42 isSolid = true; 43 moveSpeed = 1. 0F;43 moveSpeed = 1.25F; 44 44 hitAnimation = new AnimationHelper(8, 5, false, 3); 45 45 hitAnimation.RoundEnded += delegate … … 48 48 Hit(target, Game.Random.Next(1, maxDamage + 1), Direction, pushPower); 49 49 }; 50 } 51 52 public override int TypeID 53 { 54 get { return 2; } 50 55 } 51 56 … … 70 75 } 71 76 72 private void CreateAttackOrder(Unit u )77 private void CreateAttackOrder(Unit u, bool wasCalledBefore) 73 78 { 74 79 currentOrderType = OrderType.ATTACK; 75 SetOrder(new OrderMove(u.X, u.Z, ATTACK_RANGE, true)); 80 attackRange = u.Width / 2 + ATTACK_RANGE_OFFSET; 81 attackRangeSqr = attackRange * attackRange; 82 SetOrder(new OrderMove(u.X, u.Z, attackRange, true, !wasCalledBefore)); 76 83 target = u; 77 84 } … … 81 88 base.Damage(attacker, damage, dir, pushPower); 82 89 if (!isAttacking && currentOrderType == OrderType.NONE) 83 CreateAttackOrder(attacker );90 CreateAttackOrder(attacker, false); 84 91 } 85 92 … … 93 100 } 94 101 95 public override void OnFunctionClick(float x, float z )102 public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 96 103 { 97 104 Unit u = Owner.SelectUnit(Game.GetEnemyTeam(Owner.Team)); 98 105 if (u != null) 99 CreateAttackOrder(u );106 CreateAttackOrder(u, wasCalledBefore); 100 107 else 101 108 { 102 109 if (target != null) StopAttack(); 103 110 currentOrderType = OrderType.WALK; 104 SetOrder(new OrderMove(x, z ));111 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore)); 105 112 } 106 113 } … … 112 119 if (isAttacking) 113 120 { 114 if (DistanceToSqr(target.X, target.Z) > ATTACK_RANGE_SQR)121 if (DistanceToSqr(target.X, target.Z) > attackRangeSqr) 115 122 { 116 123 isAttacking = false; 117 CreateAttackOrder(target );124 CreateAttackOrder(target, false); 118 125 } 119 126 else … … 124 131 StopAttack(); 125 132 } 133 if (target == null || target.Removed) 134 StopAttack(); 126 135 } 127 136 else if (!isAttacking && currentOrderType == OrderType.NONE) … … 129 138 List<Unit> units = level.GetNearbyEnemyUnits(Game.GetEnemyTeam(Owner.Team), (int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE), 2); 130 139 if (units.Count > 0) 131 CreateAttackOrder(units[0] );140 CreateAttackOrder(units[0], false); 132 141 } 133 142 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Mobs/MobWoodcutter.cs
r4616 r4635 23 23 { 24 24 HasHealth = true; 25 maxHealth = 15;25 maxHealth = 20; 26 26 27 27 spriteSize.X = 17; … … 35 35 isSolid = true; 36 36 37 moveSpeed = 1.0F;37 moveSpeed = 2.0F; 38 38 choppingAnimation = new AnimationHelper(10, 5, false, 3); 39 39 choppingAnimation.RoundEnded += delegate() … … 47 47 } 48 48 }; 49 } 50 51 public override int TypeID 52 { 53 get { return 0; } 49 54 } 50 55 … … 63 68 } 64 69 65 public override void OnFunctionClick(float x, float z )70 public override void OnFunctionClick(float x, float z, bool wasCalledBefore) 66 71 { 67 72 TileEntity te = level.GetTileEntity((int)(x / Viewport.TILESIZE), (int)(z / Viewport.TILESIZE)); … … 71 76 isOrderedToChop = true; 72 77 currentTarget = (TileEntityTree)te; 73 SetOrder(new OrderMove( te.X, te.Z, 20.0F, true));78 SetOrder(new OrderMove(currentTarget.X, currentTarget.Z, 20.0F, true, !wasCalledBefore)); 74 79 } 75 80 else … … 80 85 currentTarget = null; 81 86 } 82 SetOrder(new OrderMove(x, z ));87 SetOrder(new OrderMove(x, z, createNewPathFinder: !wasCalledBefore)); 83 88 } 84 89 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/Unit.cs
r4616 r4635 83 83 } 84 84 85 public virtual void OnFunctionClick(float x, float z ) { }85 public virtual void OnFunctionClick(float x, float z, bool wasCalledBefore) { } 86 86 87 87 public override void Update() 88 88 { 89 base.Update(); 90 89 91 if (IsSelected) 90 92 { … … 105 107 } 106 108 } 109 } 110 111 public override void OnRemoved() 112 { 113 level.RemoveUnit(this); 107 114 } 108 115 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/Units/UnitKing.cs
r4616 r4635 14 14 : base(level, owner) 15 15 { 16 width = 5 * Viewport.TILESIZE; 17 depth = 5 * Viewport.TILESIZE; 16 18 HasHealth = true; 17 19 maxHealth = 150; … … 29 31 30 32 rectOffset.Update(-2 * Viewport.TILESIZE, -2 * Viewport.TILESIZE, 2 * Viewport.TILESIZE, 2 * Viewport.TILESIZE); 33 immunityTime = 20; 31 34 } 32 35 33 36 public override void Render(RenderHelper renderer) 34 37 { 35 renderer.Render(ScreenPos, 0, 0, Resources.SPRITE_KING, Viewport.ZOOM);38 renderer.Render(ScreenPos, 0, 0, Resources.SPRITE_KING, colorizer, Viewport.ZOOM); 36 39 base.Render(renderer); 37 40 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Level.cs
r4616 r4635 12 12 using CastleMaster.Units.Mobs; 13 13 using System; 14 using System.Diagnostics; 14 15 15 16 namespace CastleMaster.World … … 215 216 } 216 217 218 public void RemoveUnit(Unit u) 219 { 220 units[u.Owner.Team.ID].Remove(u); 221 } 222 217 223 public void SetPlayer(Player player, int id) 218 224 { … … 222 228 public void SetTile(int tileX, int tileZ, int tileID) 223 229 { 224 if (IsValidPos(tileX, tileZ)) 225 tiles[tileX + tileZ * width] = tileID; 230 tiles[tileX + tileZ * width] = tileID; 226 231 } 227 232 228 233 public void SetData(int tileX, int tileZ, byte dataVal) 229 234 { 230 if (IsValidPos(tileX, tileZ)) 231 data[tileX + tileZ * width] = dataVal; 235 data[tileX + tileZ * width] = dataVal; 232 236 } 233 237 … … 336 340 337 341 Tile t = registeredTiles[tiles[x + z * width]]; 338 if (t.IsSolid && t.GetBoundingRect(x, z).Intersects(entBR))342 if (t.IsSolidTo(ent) && t.GetBoundingRect(x, z).Intersects(entBR)) 339 343 t.AddBoundingRect(ref result, x, z); 340 344 } … … 375 379 } 376 380 377 public bool[] BuildSolidnessTable(Mob mob, bool excludeEndSolidness = false , int xEnd = 0, int zEnd = 0)381 public bool[] BuildSolidnessTable(Mob mob, bool excludeEndSolidness = false) 378 382 { 379 383 bool[] result = new bool[tiles.Length]; … … 381 385 for (int i = 0; i < tiles.Length; i++) 382 386 { 383 result[i] = tiles[i] == TILE_VOID || registeredTiles[tiles[i]].IsSolid; 387 Tile t = registeredTiles[tiles[i]]; 388 if (t is TileFloor && excludeEndSolidness) 389 result[i] = false; 390 else 391 result[i] = tiles[i] == TILE_VOID || t.IsSolid; 384 392 385 393 List<Entity> entInTiles = entitiesInTiles[i]; … … 394 402 return result; 395 403 } 404 405 public List<int> GetEntitySolidnessList(Entity caller, int xTile, int zTile, int radius) 406 { 407 List<int> result = new List<int>(); 408 409 for (int z = zTile - radius; z <= zTile + radius; z++) 410 { 411 if (z < 0 || z >= height) continue; 412 for (int x = xTile - radius; x <= xTile + radius; x++) 413 { 414 if (x < 0 || x >= width) continue; 415 if (x == xTile && z == zTile) continue; 416 417 foreach (Entity ent in entitiesInTiles[x + z * width]) 418 { 419 if (ent.Blocks(caller)) 420 { 421 result.Add(x + z * width); 422 continue; 423 } 424 } 425 } 426 } 427 428 429 return result; 430 } 396 431 } 397 432 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/LevelForest.cs
r4616 r4635 11 11 public class LevelForest : Level 12 12 { 13 private int TILE_FLOOR, TILE_WATER, TILE_FLOOR_SOLID, TILE_KING1_HINT, TILE_KING1_HINT2; 14 private UnitKing king1; 13 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; 14 private UnitKing king1, king2; 15 private UnitStore store1, store2; 15 16 16 17 public LevelForest(Texture2D tileMap) … … 21 22 protected override void InitTiles() 22 23 { 24 king1 = new UnitKing(this, Players[0]); 25 store1 = new UnitStore(this, Players[0]); 26 27 king2 = new UnitKing(this, Players[1]); 28 store2 = new UnitStore(this, Players[1]); 29 23 30 TILE_FLOOR = new TileFloor(this).ID; 24 31 TILE_WATER = new TileWater(this).ID; 25 32 TILE_FLOOR_SOLID = new TileFloor(this, true).ID; 26 king1 = new UnitKing(this, Players[0]);27 33 TILE_KING1_HINT = new TileRenderHint(this, king1, true, false).ID; 28 34 TILE_KING1_HINT2 = new TileRenderHint(this, king1, false, false).ID; 35 TILE_STORE1_HINT = new TileRenderHint(this, store1, true, true).ID; 36 TILE_KING2_HINT = new TileRenderHint(this, king2, true, false).ID; 37 TILE_STORE2_HINT = new TileRenderHint(this, store2, true, true).ID; 38 TILE_KING2_HINT2 = new TileRenderHint(this, king2, false, false).ID; 29 39 } 30 40 … … 35 45 LevelBuilder lb = new LevelBuilder(this, tileMap); 36 46 37 lb.AddTile(0xFF808080, TILE_FLOOR_SOLID);38 47 lb.AddTile(0xFF707070, TILE_KING1_HINT); 39 48 lb.AddTile(0xFF606060, TILE_KING1_HINT2); 40 lb.AddTile(0xFFFFD800, TILE_FLOOR); 41 lb.AddTile(0xFF00FFFF, TILE_FLOOR); 42 lb.AddTile(0xFFFF0000, TILE_FLOOR); 43 lb.AddTile(0xFF0000FF, TILE_FLOOR); 44 lb.AddTile(0xFF21007F, TILE_FLOOR); 49 lb.AddTile(0xFF505050, TILE_STORE1_HINT); 50 51 lb.AddTile(0xFF707071, TILE_KING2_HINT); 52 lb.AddTile(0xFF606061, TILE_KING2_HINT2); 53 lb.AddTile(0xFF505051, TILE_STORE2_HINT); 54 55 lb.AddTile(0xFF808080, TILE_FLOOR_SOLID); 45 56 lb.AddTile(0xFF404040, TILE_FLOOR); 46 57 lb.AddTile(0xFF0094FF, TILE_WATER); 47 58 lb.AddTile(0xFF303030, TILE_FLOOR, 2); 48 lb.AddTile(0xFF202020, TILE_FLOOR, 4); 49 lb.AddTile(0xFF202021, TILE_FLOOR, 5); 50 lb.AddTile(0xFF101010, TILE_FLOOR, 3); 51 lb.AddTile(0xFF0094FF, TILE_WATER, 8); 52 lb.AddTile(0xFF00B200, TILE_FLOOR, 6); 53 lb.AddTile(0xFF00CC00, TILE_FLOOR, 6); 59 60 lb.AddTile(0xFF0000FF, TILE_FLOOR); 61 lb.AddTile(0xFFFFD800, TILE_FLOOR); 54 62 lb.AddTile(0xFFFF0000, TILE_FLOOR); 55 lb.AddTile(0xFF FF0001, TILE_FLOOR);63 lb.AddTile(0xFF21007F, TILE_FLOOR); 56 64 lb.AddEntity(0xFFE55B00, typeof(TileEntityBlock), 8.0F, 8.0F, this, 4, 1); 57 65 lb.AddEntity(0xFF00B200, typeof(TileEntityBlock), 8.0F, 8.0F, this, 2, 2); … … 61 69 lb.AddEntity(0xFF0000FF, typeof(MobWarrior), 8.0F, 8.0F, this, Players[0]); 62 70 lb.AddEntity(0xFFFF0000, typeof(MobWoodcutter), 8.0F, 8.0F, this, Players[0]); 71 lb.AddEntity(0xFFFFD800, typeof(MobRanger), 8.0F, 8.0F, this, Players[0]); 63 72 lb.AddEntity(0xFF21007F, typeof(MobWarrior), 8.0F, 8.0F, this, Players[1]); 64 73 lb.AddEntity(0xFF00FFFF, typeof(MobWoodcutter), 8.0F, 8.0F, this, Players[1]); 65 lb.AddEntity(0xFFFFD800, typeof(MobRanger), 8.0F, 8.0F, this, Players[0]); 74 75 lb.AddCustom(0xFFFF6A03, delegate(Level level, int xTile, int zTile) 76 { 77 level.AddEntity(king2, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 78 }); 79 lb.AddCustom(0xFFFF6A02, delegate(Level level, int xTile, int zTile) 80 { 81 level.AddEntity(store2, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 82 }); 83 66 84 lb.AddCustom(0xFFFF6A00, delegate(Level level, int xTile, int zTile) 67 85 { 68 86 level.AddEntity(king1, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 87 }); 88 lb.AddCustom(0xFFFF6A01, delegate(Level level, int xTile, int zTile) 89 { 90 level.AddEntity(store1, xTile * Viewport.TILESIZE + 8.0F, zTile * Viewport.TILESIZE + 8.0F); 69 91 }); 70 92 -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Tiles/Tile.cs
r4581 r4635 21 21 22 22 public bool IsSolid { get; protected set; } 23 24 public virtual bool IsSolidTo(Entity ent) 25 { 26 return IsSolid && !(ent is EntityArrow); 27 } 23 28 24 29 public virtual BoundingRectangle GetBoundingRect(int xTile, int zTile) -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMaster/World/Tiles/TileRenderHint.cs
r4616 r4635 18 18 { 19 19 this.entToRender = entToRender; 20 this.renderTile = renderTile; 20 21 IsSolid = isSolid; 21 22 } -
2013/30/DenisZ/CastleMaster/CastleMaster/CastleMasterContent/CastleMasterContent.contentproj
r4616 r4635 146 146 </Compile> 147 147 </ItemGroup> 148 <ItemGroup> 149 <Compile Include="mobs\store.png"> 150 <Name>store</Name> 151 <Importer>TextureImporter</Importer> 152 <Processor>TextureProcessor</Processor> 153 </Compile> 154 </ItemGroup> 148 155 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 149 156 <!-- 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.