abstract Target add

This commit is contained in:
N4K 2023-08-18 14:49:32 +03:00
parent 4d8172f3bd
commit 1c56378003
17 changed files with 68 additions and 51 deletions

View file

@ -62,7 +62,7 @@
</object> </object>
</objectgroup> </objectgroup>
<objectgroup id="5" name="Zombies" class="LivingEntities.Monsters.Spider"> <objectgroup id="5" name="Zombies" class="LivingEntities.Monsters.Spider">
<object id="4" x="-80" y="100"> <object id="4" x="-50" y="200">
<point/> <point/>
</object> </object>
</objectgroup> </objectgroup>

View file

@ -13,7 +13,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public abstract class CoreEnemy : LivingEntity public abstract class CoreEnemy : LivingEntity
{ {
protected int monster_health; protected int monster_health;
protected int monster_speed; protected float monster_speed;
protected string name; protected string name;
protected bool isAlive = true; protected bool isAlive = true;
protected int leftBoarder = 0; protected int leftBoarder = 0;
@ -45,5 +45,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
isAlive = false; isAlive = false;
} }
} }
public abstract void Target();
} }
} }

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
Width = 62; Width = 62;
Height = 40; Height = 40;
monster_speed = 3; monster_speed = 0.25f;
name = "Skull"; name = "Skull";
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
} }
@ -63,19 +63,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
velocity.X = -monster_speed; velocity.X = -monster_speed;
} }
if (Pos.X >= rightBoarder)
{
isGoRight = false;
}
else if (Pos.X <= leftBoarder)
{
isGoRight = true;
}
} }
public override void Attack(GameTime gameTime) public override void Attack(GameTime gameTime)
{ {
throw new NotImplementedException();
}
public override void Target()
{
if (true)
{
}
} }
} }
} }

View file

@ -74,9 +74,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
} }
} }

View file

@ -80,7 +80,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
velocity.Y -= monster_speed; velocity.Y -= monster_speed;
} }
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View file

@ -83,7 +83,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View file

@ -129,9 +129,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
Debug.WriteLine("Collision"); Debug.WriteLine("Collision");
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
} }
} }

View file

@ -42,9 +42,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
} }
} }

View file

@ -62,9 +62,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)

View file

@ -111,9 +111,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)

View file

@ -232,7 +232,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
base.Update(gameTime); base.Update(gameTime);
} }
public void Target() public override void Target()
{ {
} }

View file

@ -19,10 +19,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected SpiderWeb web; protected SpiderWeb web;
protected float delay; protected float delay;
protected int webLength; protected int webLength;
protected int widthS;
protected bool isDown; protected bool isDown;
protected bool isDownUp; protected bool isDownUp;
protected PhysicsManager physicsManager; protected PhysicsManager physicsManager;
protected Player player; protected Player player;
protected Vector2 oldPosition;
public Spider(Vector2 position) : base(position) public Spider(Vector2 position) : base(position)
{ {
@ -30,10 +32,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
isDownUp = true; isDownUp = true;
isDown = true; isDown = true;
physicsManager = AppManager.Instance.GameManager.physicsManager; physicsManager = AppManager.Instance.GameManager.physicsManager;
web = new SpiderWeb(Pos);
name = "Spider"; name = "Spider";
Width = 112; Width = 112;
Height = 24; Height = 24;
widthS = Width;
web = new SpiderWeb(new Vector2(Pos.X+Width/2,Pos.Y));
delay = 0; delay = 0;
webLength = 0; webLength = 0;
monster_speed = 3; monster_speed = 3;
@ -45,7 +48,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
if (!isAttack) if (isAttack == false)
{ {
Move(gameTime); Move(gameTime);
} }
@ -68,12 +71,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
/// </summary> /// </summary>
/// <param name="gameTime"></param> /// <param name="gameTime"></param>
public override void Attack(GameTime gameTime) public override void Attack(GameTime gameTime)
{ //48 72 {
velocity.X = 0;
delay += (float)gameTime.ElapsedGameTime.TotalSeconds;
if (isAttack) if (isAttack)
{ {
if (delay > 0.5 && webLength <= 4 && isDown) velocity.X = 0;
delay += (float)gameTime.ElapsedGameTime.TotalSeconds;
if (delay > 0.25 && webLength <= 4 && isDown)
{ {
Width = 48; Width = 48;
Height = 72; Height = 72;
@ -104,22 +108,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
isDown = true; isDown = true;
} }
} }
var entitiesInter = physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, 200, 600)); if (webLength == 0)
if (entitiesInter.Count > 0)
{ {
foreach (var entity in entitiesInter) isAttack = false;
}
var entities = physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height + 200));
foreach (var entity in entities)
{
if (webLength == 4 && entity is Player)
{ {
if (entity.GetType() == typeof(Player)) AppManager.Instance.GameManager.players[0].Death(name);
{
player.Death(name);
}
} }
} }
} }
if (webLength == 0)
{
isAttack = false;
}
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
@ -169,12 +170,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
} }
public void Target() public override void Target()
{ {
if (player.Pos.X >= Pos.X && player.Pos.X <= Pos.X+Width) if (player.Pos.X >= Pos.X && player.Pos.X <= Pos.X+Width)
{ {
isAttack = true; isAttack = true;
} }
} }
public override void OnCollision(GameObject gameObject)
{
if (gameObject is Player)
{
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
Attack();
}
}
base.OnCollision(gameObject);
}
} }
} }

View file

@ -15,7 +15,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public SpiderWeb(Vector2 position) : base(position) public SpiderWeb(Vector2 position) : base(position)
{ {
name = "Web"; name = "Web";
monster_speed = 1;
Width = 16; Width = 16;
Height = 0; Height = 0;
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
@ -43,9 +42,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
} }
} }

View file

@ -76,9 +76,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
} }
public void Target() public override void Target()
{ {
throw new NotImplementedException();
} }
} }
} }

View file

@ -128,7 +128,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
base.OnCollision(gameObject); base.OnCollision(gameObject);
} }
public void Target() public override void Target()
{ {
if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)).Count > 0) if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)).Count > 0)
{ {

View file

@ -28,7 +28,10 @@ public abstract class LivingEntity : Entity
//} //}
base.Update(gameTime); base.Update(gameTime);
} }
/// <summary>
///
/// </summary>
/// <param name="animationName"></param>
public virtual void StartCicycleAnimation(string animationName) public virtual void StartCicycleAnimation(string animationName)
{ {
if (GraphicsComponent.GetCurrentAnimation != animationName) if (GraphicsComponent.GetCurrentAnimation != animationName)

View file

@ -205,7 +205,7 @@ namespace DangerousD.GameCore
case GameState.Lobby: case GameState.Lobby:
break; break;
case GameState.Game: case GameState.Game:
GameManager.mapManager.LoadLevel("lvl"); GameManager.mapManager.LoadLevel("map");
GameManager.FindBorders(); GameManager.FindBorders();
break; break;
case GameState.Death: case GameState.Death: