Merge branch 'particlesBranch'

This commit is contained in:
bmvolf 2023-08-18 01:47:29 +03:00
commit 621bef7d0a
6 changed files with 104 additions and 25 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View file

@ -0,0 +1 @@
{"id":"playerReload","textureName":"playerAnimation","startSpriteRectangle":{"X":101,"Y":67,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"playerShootLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":34,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"}

View file

@ -0,0 +1 @@
{"id":"playerShootRight","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":1,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"}

View file

@ -27,8 +27,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
Height = 40; Height = 40;
monster_speed = 3; monster_speed = 3;
name = "Zombie"; name = "Zombie";
leftBorder = (int)position.X - 50; monster_health = 2;
rightBorder = (int)position.X + 50; leftBorder = (int)position.X - 100;
rightBorder = (int)position.X + 100;
physicsManager = new PhysicsManager(); physicsManager = new PhysicsManager();
Random random = new Random(); Random random = new Random();
if(random.Next(0, 2) == 0) if(random.Next(0, 2) == 0)
@ -77,7 +78,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death() public override void Death()
{ {
AppManager.Instance.GameManager.Remove(this);
} }
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
@ -154,5 +155,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public void Attack(GameTime gameTime) public void Attack(GameTime gameTime)
{} {}
public void TakeDamage()
{
monster_health--;
GraphicsComponent.StartAnimation("ZombieRightAttack");
if (monster_health <= 0)
{
Death();
}
}
} }
} }

View file

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using DangerousD.GameCore.GameObjects.PlayerDeath; using DangerousD.GameCore.GameObjects.PlayerDeath;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using DangerousD.GameCore.Network; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters;
namespace DangerousD.GameCore.GameObjects.LivingEntities namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
@ -25,8 +25,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public int leftBorder; public int leftBorder;
public bool isVisible = true; public bool isVisible = true;
private bool isAttacked = false; private bool isAttacked = false;
public bool isInvincible = false; private bool isShooting = false;
public GameObject objectAttack; public GameObject objectAttack;
private int bullets;
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
@ -37,21 +38,30 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
AppManager.Instance.InputManager.MovEventJump += Jump; AppManager.Instance.InputManager.MovEventJump += Jump;
AppManager.Instance.InputManager.MovEventDown += MoveDown; AppManager.Instance.InputManager.MovEventDown += MoveDown;
AppManager.Instance.InputManager.ShootEvent += Shoot;
velocity = new Vector2(0, 0); velocity = new Vector2(0, 0);
rightBorder = (int)position.X + 100; rightBorder = (int)position.X + 100;
leftBorder = (int)position.X - 100; leftBorder = (int)position.X - 100;
} bullets = 5;
public Player(Vector2 position, bool isInvincible = false) : this(position) this.GraphicsComponent.actionOfAnimationEnd += (a) =>
{ {
this.isInvincible = isInvincible; if (a == "playerShootLeft" || a == "playerShootRight")
{
isShooting = false;
}
if (a == "playerReload")
{
bullets++;
}
};
} }
public bool IsAlive { get { return isAlive; } } public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",
"playerJumpRight" , "playerJumpLeft"}, "playerStayLeft"); "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload"}, "playerReload");
public void Attack() public void Attack()
{ {
@ -59,6 +69,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
isVisible = false; isVisible = false;
} }
} }
public override void OnCollision(GameObject gameObject) public override void OnCollision(GameObject gameObject)
{ {
@ -97,9 +108,47 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
public void Shoot() public void Shoot()
{ {
if (bullets > 0)
{
if (!isShooting)
{
isShooting = true;
bullets--;
if (isRight)
{
if (GraphicsComponent.GetCurrentAnimation != "playerShootRight")
{
GraphicsComponent.StartAnimation("playerShootRight");
}
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), 100, 10), typeof(Zombie));
if (targets != null)
{
foreach (var target in targets)
{
Zombie targetZombie = (Zombie)target;
targetZombie.TakeDamage();
}
}
}
else
{
if (GraphicsComponent.GetCurrentAnimation != "playerShootRight")
{
GraphicsComponent.StartAnimation("playerShootRight");
}
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), -100, 10), typeof(Zombie));
if (targets != null)
{
foreach (var target in targets)
{
Zombie targetZombie = (Zombie)target;
targetZombie.TakeDamage();
}
}
}
}
}
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
GraphicsComponent.SetCameraPosition(Pos); GraphicsComponent.SetCameraPosition(Pos);
@ -118,25 +167,41 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
velocity.X = 5 * AppManager.Instance.InputManager.VectorMovementDirection.X; velocity.X = 5 * AppManager.Instance.InputManager.VectorMovementDirection.X;
if (AppManager.Instance.InputManager.VectorMovementDirection.X > 0) if (GraphicsComponent.GetCurrentAnimation != "playerShootLeft" && GraphicsComponent.GetCurrentAnimation != "playerShootRight")
{ {
if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")//идёт направо if (AppManager.Instance.InputManager.VectorMovementDirection.X > 0)
{ {
GraphicsComponent.StartAnimation("playerMoveRight"); isRight = true;
if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")//идёт направо
{
GraphicsComponent.StartAnimation("playerMoveRight");
}
} }
} else if (AppManager.Instance.InputManager.VectorMovementDirection.X < 0)//идёт налево
else if (AppManager.Instance.InputManager.VectorMovementDirection.X < 0)//идёт налево
{
if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft")
{ {
GraphicsComponent.StartAnimation("playerMoveLeft"); isRight = false;
if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft")
{
GraphicsComponent.StartAnimation("playerMoveLeft");
}
} }
} else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
else if(AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
{
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
{ {
GraphicsComponent.StartAnimation("ZombieMoveLeft"); if(bullets < 5)
{
if (GraphicsComponent.GetCurrentAnimation != "playerReload")
{
GraphicsComponent.StartAnimation("playerReload");
}
}
else if (isRight)
{
GraphicsComponent.StartAnimation("playerRightStay");
}
else if (!isRight)
{
GraphicsComponent.StartAnimation("playerStayLeft");
}
} }
} }
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer) if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)