added up shooting
This commit is contained in:
parent
665cb6b38b
commit
12e3101988
6 changed files with 138 additions and 44 deletions
1
DangerousD/Content/animations/playerShootBoomUpLeft
Normal file
1
DangerousD/Content/animations/playerShootBoomUpLeft
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"playerShootBoomUpLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":267,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"}
|
24
DangerousD/Content/animations/playerShootBoomUpRight
Normal file
24
DangerousD/Content/animations/playerShootBoomUpRight
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"id": "playerShootBoomUpRight",
|
||||||
|
"textureName": "playerAnimation",
|
||||||
|
"startSpriteRectangle": {
|
||||||
|
"X": 267,
|
||||||
|
"Y": 1,
|
||||||
|
"Width": 24,
|
||||||
|
"Height": 32
|
||||||
|
},
|
||||||
|
"frameSecond": [
|
||||||
|
{
|
||||||
|
"Item1": 0,
|
||||||
|
"Item2": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Item1": 1,
|
||||||
|
"Item2": 20
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"textureFrameInterval": 1,
|
||||||
|
"framesCount": 2,
|
||||||
|
"isCycle": false,
|
||||||
|
"offset": "0, 0"
|
||||||
|
}
|
|
@ -36,9 +36,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
|
|
||||||
public abstract void Move(GameTime gameTime);
|
public abstract void Move(GameTime gameTime);
|
||||||
|
|
||||||
public void TakeDamage(int damage)
|
public virtual void TakeDamage()
|
||||||
{
|
{
|
||||||
monster_health -= damage;
|
monster_health--;
|
||||||
if (monster_health <= 0)
|
if (monster_health <= 0)
|
||||||
{
|
{
|
||||||
Death();
|
Death();
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
rightBorder = (int)position.X + 100;
|
rightBorder = (int)position.X + 100;
|
||||||
physicsManager = new PhysicsManager();
|
physicsManager = new PhysicsManager();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
monster_health = 2;
|
||||||
if(random.Next(0, 2) == 0)
|
if(random.Next(0, 2) == 0)
|
||||||
{
|
{
|
||||||
isGoRight = true;
|
isGoRight = true;
|
||||||
|
@ -183,10 +184,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
public override void Attack(GameTime gameTime)
|
public override void Attack(GameTime gameTime)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public void TakeDamage()
|
public override void TakeDamage()
|
||||||
{
|
{
|
||||||
monster_health--;
|
monster_health--;
|
||||||
GraphicsComponent.StartAnimation("ZombieRightAttack");
|
|
||||||
Particle particle = new Particle(Pos);
|
Particle particle = new Particle(Pos);
|
||||||
if (monster_health <= 0)
|
if (monster_health <= 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,7 @@ using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using DangerousD.GameCore.GameObjects.LivingEntities.Monsters;
|
using DangerousD.GameCore.GameObjects.LivingEntities.Monsters;
|
||||||
using DangerousD.GameCore.Network;
|
using DangerousD.GameCore.Network;
|
||||||
|
using DangerousD.GameCore.GameObjects.MapObjects;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GameObjects.LivingEntities
|
namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
{
|
{
|
||||||
|
@ -65,6 +66,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
{
|
{
|
||||||
bullets++;
|
bullets++;
|
||||||
}
|
}
|
||||||
|
if(a == "playerShootBoomUpRight" || a == "playerShootBoomUpLeft")
|
||||||
|
{
|
||||||
|
isShooting = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +78,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
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", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft"}, "playerReload");
|
"playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft", "playerShootBoomUpRight",
|
||||||
|
"playerShootBoomUpLeft"}, "playerReload");
|
||||||
|
|
||||||
public void Attack()
|
public void Attack()
|
||||||
{
|
{
|
||||||
|
@ -184,41 +190,57 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
bullets--;
|
bullets--;
|
||||||
if (isRight)
|
if (isRight)
|
||||||
{
|
{
|
||||||
StartCicycleAnimation("playerShootRight");
|
if (!isUping)
|
||||||
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared());
|
|
||||||
if (targets.Count() > 0)
|
|
||||||
{
|
{
|
||||||
Zombie targetZombie = (Zombie)targets.First();
|
StartCicycleAnimation("playerShootRight");
|
||||||
targetZombie.TakeDamage();
|
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared());
|
||||||
|
if (targets.Count() > 0)
|
||||||
}
|
|
||||||
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands)).OrderBy(x => (x.Pos - Pos).LengthSquared());
|
|
||||||
if (targets.Count() > 0)
|
|
||||||
{
|
|
||||||
SilasHands targetHand = (SilasHands)targets.First();
|
|
||||||
targetHand.TakeDamage();
|
|
||||||
}
|
|
||||||
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
StartCicycleAnimation("playerShootLeft");
|
|
||||||
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie));
|
|
||||||
if (targets != null)
|
|
||||||
{
|
|
||||||
foreach (var target in targets)
|
|
||||||
{
|
{
|
||||||
Zombie targetZombie = (Zombie)target;
|
Zombie targetZombie = (Zombie)targets.First();
|
||||||
targetZombie.TakeDamage();
|
targetZombie.TakeDamage();
|
||||||
}
|
}
|
||||||
|
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands)).OrderBy(x => (x.Pos - Pos).LengthSquared());
|
||||||
|
if (targets.Count() > 0)
|
||||||
|
{
|
||||||
|
SilasHands targetHand = (SilasHands)targets.First();
|
||||||
|
targetHand.TakeDamage();
|
||||||
|
}
|
||||||
|
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7));
|
||||||
}
|
}
|
||||||
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands));
|
else
|
||||||
if (targets.Count() > 0)
|
|
||||||
{
|
{
|
||||||
SilasHands targetHand = (SilasHands)targets.First();
|
StartCicycleAnimation("playerShootBoomUpRight");
|
||||||
targetHand.TakeDamage();
|
Bullet bullet = new Bullet(new Vector2(Pos.X + 16, Pos.Y));
|
||||||
|
bullet.ShootUpRight();
|
||||||
|
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 12, Pos.Y - 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!isRight)
|
||||||
|
{
|
||||||
|
if (!isUping)
|
||||||
|
{
|
||||||
|
StartCicycleAnimation("playerShootLeft");
|
||||||
|
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared());
|
||||||
|
if (targets.Count() > 0)
|
||||||
|
{
|
||||||
|
Zombie targetZombie = (Zombie)targets.First();
|
||||||
|
targetZombie.TakeDamage();
|
||||||
|
}
|
||||||
|
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands));
|
||||||
|
if (targets.Count() > 0)
|
||||||
|
{
|
||||||
|
SilasHands targetHand = (SilasHands)targets.First();
|
||||||
|
targetHand.TakeDamage();
|
||||||
|
}
|
||||||
|
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StartCicycleAnimation("playerShootBoomUpLeft");
|
||||||
|
Bullet bullet = new Bullet(new Vector2(Pos.X, Pos.Y));
|
||||||
|
bullet.ShootUpLeft();
|
||||||
|
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 6, Pos.Y - 7));
|
||||||
}
|
}
|
||||||
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,14 +304,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
}
|
}
|
||||||
else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
|
else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
|
||||||
{
|
{
|
||||||
if(bullets < 5)
|
if (isRight)
|
||||||
{
|
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "playerReload")
|
|
||||||
{
|
|
||||||
GraphicsComponent.StartAnimation("playerReload");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (isRight)
|
|
||||||
{
|
{
|
||||||
if (isUping)
|
if (isUping)
|
||||||
{
|
{
|
||||||
|
@ -298,6 +313,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
GraphicsComponent.StartAnimation("playerShootUpRight");
|
GraphicsComponent.StartAnimation("playerShootUpRight");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (bullets < 5)
|
||||||
|
{
|
||||||
|
if (GraphicsComponent.GetCurrentAnimation != "playerReload")
|
||||||
|
{
|
||||||
|
GraphicsComponent.StartAnimation("playerReload");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("playerRightStay");
|
GraphicsComponent.StartAnimation("playerRightStay");
|
||||||
|
@ -312,6 +334,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
GraphicsComponent.StartAnimation("playerShootUpLeft");
|
GraphicsComponent.StartAnimation("playerShootUpLeft");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (bullets < 5)
|
||||||
|
{
|
||||||
|
if (GraphicsComponent.GetCurrentAnimation != "playerReload")
|
||||||
|
{
|
||||||
|
GraphicsComponent.StartAnimation("playerReload");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("playerStayLeft");
|
GraphicsComponent.StartAnimation("playerStayLeft");
|
||||||
|
@ -331,13 +360,51 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
isOnGround = false;
|
isOnGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Bullet : GameObjects.LivingEntity
|
public class Bullet : LivingEntity
|
||||||
{
|
{
|
||||||
public Bullet(Vector2 position) : base(position)
|
public Bullet(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
|
Height = 5;
|
||||||
|
Width = 5;
|
||||||
|
}
|
||||||
|
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft"}, "playerMoveLeft");
|
||||||
|
Vector2 direction;
|
||||||
|
Vector2 maindirection;
|
||||||
|
public void ShootUpRight()
|
||||||
|
{
|
||||||
|
direction = new Vector2(1, -1);
|
||||||
|
acceleration = Vector2.Zero;
|
||||||
|
velocity = new Vector2(10, 10) * direction;
|
||||||
|
maindirection = velocity;
|
||||||
|
}
|
||||||
|
public void ShootUpLeft()
|
||||||
|
{
|
||||||
|
direction = new Vector2(-1, -1);
|
||||||
|
acceleration = Vector2.Zero;
|
||||||
|
velocity = new Vector2(10, 10) * direction;
|
||||||
|
maindirection = velocity;
|
||||||
|
}
|
||||||
|
public override void OnCollision(GameObject gameObject)
|
||||||
|
{
|
||||||
|
if (gameObject is not Player)
|
||||||
|
{
|
||||||
|
if (gameObject is CoreEnemy)
|
||||||
|
{
|
||||||
|
CoreEnemy enemy = (CoreEnemy)gameObject;
|
||||||
|
enemy.TakeDamage();
|
||||||
|
AppManager.Instance.GameManager.Remove(this);
|
||||||
|
}
|
||||||
|
base.OnCollision(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
if (maindirection!=velocity)
|
||||||
|
{
|
||||||
|
AppManager.Instance.GameManager.Remove(this);
|
||||||
|
}
|
||||||
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
protected override GraphicsComponent GraphicsComponent { get; } = new("ZombieMoveLeft");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ public abstract class LivingEntity : Entity
|
||||||
public Vector2 velocity;
|
public Vector2 velocity;
|
||||||
public Vector2 acceleration;
|
public Vector2 acceleration;
|
||||||
|
|
||||||
|
public Vector2 Acceleration { get; private set; }
|
||||||
|
|
||||||
public LivingEntity(Vector2 position) : base(position)
|
public LivingEntity(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
acceleration = new Vector2(0, 30);
|
acceleration = new Vector2(0, 30);
|
||||||
|
|
Loading…
Add table
Reference in a new issue