Skip to content

Commit

Permalink
Merge pull request #388 from Panxuc/dev
Browse files Browse the repository at this point in the history
feat: ✨ bullet can attack wormhole
  • Loading branch information
asdawej authored May 18, 2024
2 parents a6f3932 + e9e0b95 commit 3959816
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Asteroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas;
public class Asteroid(XY initPos)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Asteroid)
{
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Construction(XY initPos)
{
public AtomicLong TeamID { get; } = new(long.MaxValue);
public InVariableRange<long> HP { get; } = new(0, GameData.CommunityHP);
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;

private readonly object lockOfConstructionType = new();
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Home(XY initPos, long id)
{
public long TeamID { get; } = id;
public InVariableRange<long> HP { get; } = new(GameData.HomeHP);
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;
public AtomicInt RepairNum { get; } = new AtomicInt(0);
public bool Repair(int constructSpeed, Ship ship)
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/NullArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas;
public class NullArea(XY initPos)
: Immovable(initPos, int.MaxValue, GameObjType.Null)
{
public override bool IsRigid => false;
public override bool IsRigid(bool args = false) => false;
public override ShapeType Shape => ShapeType.Null;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace GameClass.GameObj.Areas;
public class OutOfBoundBlock(XY initPos)
: Immovable(initPos, int.MaxValue, GameObjType.OutOfBoundBlock), IOutOfBound
{
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Resource(XY initPos)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Resource)
{
public InVariableRange<long> HP { get; } = new(GameData.ResourceHP);
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;
public AtomicInt ProduceNum { get; } = new AtomicInt(0);
public bool Produce(int produceSpeed, Ship ship)
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Ruin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas;
public class Ruin(XY initPos)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Ruin)
{
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Square;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Shadow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas;
public class Shadow(XY initPos)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Shadow)
{
public override bool IsRigid => false;
public override bool IsRigid(bool args = false) => false;
public override ShapeType Shape => ShapeType.Square;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/WormholeCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GameClass.GameObj.Areas;
public class WormholeCell(XY initPos, Wormhole wormhole)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Wormhole)
{
public override bool IsRigid => Wormhole.HP < GameData.WormholeHP / 2;
public override bool IsRigid(bool args = false) => args || Wormhole.HP < GameData.WormholeHP / 2;
public override ShapeType Shape => ShapeType.Square;
public readonly Wormhole Wormhole = wormhole;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/BombedBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public sealed class BombedBullet(Bullet bullet)
: Immovable(bullet.Position, bullet.Radius, GameObjType.BombedBullet)
{
public override ShapeType Shape => ShapeType.Circle;
public override bool IsRigid => false;
public override bool IsRigid(bool args = false) => false;
public long MappingID { get; } = bullet.ID;
public readonly Bullet bulletHasBombed = bullet;
public readonly XY facingDirection = bullet.FacingDirection;
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Bullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class Bullet : ObjOfShip
public abstract int SwingTime { get; }
public abstract double ArmorModifier { get; }
public abstract double ShieldModifier { get; }
public override bool IsRigid => true; // 默认为true
public override bool IsRigid(bool args = false) => true; // 默认为true
public override ShapeType Shape => ShapeType.Circle; // 默认为圆形
public abstract BulletType TypeOfBullet { get; }
public abstract bool CanAttack(GameObj target);
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/GameObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class GameObj(XY initPos, int initRadius, GameObjType initType)

protected XY position = initPos;
public abstract XY Position { get; }
public abstract bool IsRigid { get; }
public abstract bool IsRigid(bool args = false);
public abstract ShapeType Shape { get; }

private readonly AtomicBool isRemoved = new(false);
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Ship : Movable, IShip
{
public AtomicLong TeamID { get; } = new(long.MaxValue);
public AtomicLong PlayerID { get; } = new(long.MaxValue);
public override bool IsRigid => true;
public override bool IsRigid(bool args = false) => true;
public override ShapeType Shape => ShapeType.Circle;
public int ViewRange { get; }
public override bool IgnoreCollideExecutor(IGameObj targetObj)
Expand Down
10 changes: 5 additions & 5 deletions logic/GameEngine/CollisionChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace GameEngine
{
internal class CollisionChecker(IMap gameMap)
{
public IGameObj? CheckCollision(IMovable obj, XY Pos)
public IGameObj? CheckCollision(IMovable obj, XY Pos, bool collideWithWormhole = false)
{
// 在列表中检查碰撞
IGameObj? CheckCollisionInList(LockedClassList<IGameObj> lst)
{
return lst.Find(listObj => obj.WillCollideWith(listObj, Pos));
return lst.Find(listObj => obj.WillCollideWith(listObj, Pos, collideWithWormhole));
}

IGameObj? collisionObj;
Expand All @@ -33,16 +33,16 @@ internal class CollisionChecker(IMap gameMap)
/// <param name="obj">移动的物体</param>
/// <param name="moveVec">移动的位移向量</param>
/// <returns>和它碰撞的物体</returns>
public IGameObj? CheckCollisionWhenMoving(IMovable obj, XY moveVec)
public IGameObj? CheckCollisionWhenMoving(IMovable obj, XY moveVec, bool collideWithWormhole = false)
{
XY nextPos = obj.Position + moveVec;
if (!obj.IsRigid)
if (!obj.IsRigid())
{
if (gameMap.IsOutOfBound(obj))
return gameMap.GetOutOfBound(nextPos);
return null;
}
return CheckCollision(obj, nextPos);
return CheckCollision(obj, nextPos, collideWithWormhole);
}
/// <summary>
/// /// 可移动物体(圆)向矩形物体移动时,可移动且不会碰撞的最大距离。直接用double计算,防止误差
Expand Down
6 changes: 4 additions & 2 deletions logic/GameEngine/MoveEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace GameEngine
public class MoveEngine(
IMap gameMap,
Func<IMovable, IGameObj, XY, MoveEngine.AfterCollision> OnCollision,
Action<IMovable> EndMove
Action<IMovable> EndMove,
bool collideWithWormhole = false
)
{
/// <summary>
Expand All @@ -46,6 +47,7 @@ public enum AfterCollision

private readonly CollisionChecker collisionChecker = new(gameMap);
private readonly Func<IMovable, IGameObj, XY, AfterCollision> OnCollision = OnCollision;
private bool collideWithWormhole = collideWithWormhole;

/// <summary>
/// 在无碰撞的前提下行走最远的距离
Expand Down Expand Up @@ -102,7 +104,7 @@ private bool LoopDo(IMovable obj, double direction, ref double deltaLen, long st
do
{
flag = false;
IGameObj? collisionObj = collisionChecker.CheckCollisionWhenMoving(obj, res);
IGameObj? collisionObj = collisionChecker.CheckCollisionWhenMoving(obj, res, collideWithWormhole);
if (collisionObj == null)
break;

Expand Down
3 changes: 2 additions & 1 deletion logic/Gaming/AttackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public AttackManager(Game game, Map gameMap, ShipManager shipManager)
BulletBomb((Bullet)obj, null);
}
obj.CanMove.SetROri(false);
}
},
collideWithWormhole: true
);
this.game = game;
}
Expand Down
2 changes: 1 addition & 1 deletion logic/Preparation/Interface/IGameObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IGameObj
public GameObjType Type { get; }
public long ID { get; }
public XY Position { get; } // if Square, Pos equals the center
public bool IsRigid { get; }
public bool IsRigid(bool args = false);
public AtomicBool IsRemoved { get; }
public ShapeType Shape { get; }
public int Radius { get; } // if Square, Radius equals half length of one side
Expand Down
4 changes: 2 additions & 2 deletions logic/Preparation/Interface/IMovable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public interface IMovable : IGameObj
public long StateNum { get; }
public Semaphore ThreadNum { get; }
public long MovingSetPos(XY moveVec, long stateNum);
public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞
public bool WillCollideWith(IGameObj? targetObj, XY nextPos, bool collideWithWormhole = false) // 检查下一位置是否会和目标物碰撞
{
if (targetObj == null)
return false;
// 会移动的只有子弹和人物,都是Circle
if (!targetObj.IsRigid || targetObj.ID == ID)
if (!targetObj.IsRigid(collideWithWormhole) || targetObj.ID == ID)
return false;

if (IgnoreCollideExecutor(targetObj) || targetObj.IgnoreCollideExecutor(this))
Expand Down

0 comments on commit 3959816

Please sign in to comment.