diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index dc2bf5b..bda2baf 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -62,7 +62,7 @@ namespace AnimationsFileCreator container.TextureFrameInterval = 1; container.Id = id; string json = JsonConvert.SerializeObject(container); - StreamWriter writer = new StreamWriter(id); + StreamWriter writer = new StreamWriter("../../../../DangerousD/Content/animations/" + id); writer.WriteLine(json); writer.Close(); } diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index b5e65dd..ed4246e 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -13,6 +13,30 @@ #---------------------------------- Content ---------------------------------# +#begin ../../../animation1.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:../../../animation1.png;MonstersAnimations.png + +#begin deathAnimation.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:deathAnimation.png + #begin File.spritefont /importer:FontDescriptionImporter /processor:FontDescriptionProcessor @@ -34,18 +58,6 @@ /processorParam:TextureFormat=Compressed /build:Font2.spritefont -#begin MonstersAnimations.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:MonstersAnimations.png - #begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png /importer:TextureImporter /processor:TextureProcessor diff --git a/DangerousD/Content/animations/DeathFromZombie b/DangerousD/Content/animations/DeathFromZombie new file mode 100644 index 0000000..e6174de --- /dev/null +++ b/DangerousD/Content/animations/DeathFromZombie @@ -0,0 +1 @@ +{"id":"DeathFromZombie","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":99,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/ZombieLeftAttack b/DangerousD/Content/animations/ZombieLeftAttack index 63d7675..cb1466b 100644 --- a/DangerousD/Content/animations/ZombieLeftAttack +++ b/DangerousD/Content/animations/ZombieLeftAttack @@ -1 +1 @@ -{"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} +{"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} diff --git a/DangerousD/Content/animations/ZombieRightAttack b/DangerousD/Content/animations/ZombieRightAttack index 2a48da2..7da67ee 100644 --- a/DangerousD/Content/animations/ZombieRightAttack +++ b/DangerousD/Content/animations/ZombieRightAttack @@ -1 +1 @@ -{"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} +{"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} diff --git a/DangerousD/Content/deathAnimation.png b/DangerousD/Content/deathAnimation.png new file mode 100644 index 0000000..3eb4a52 Binary files /dev/null and b/DangerousD/Content/deathAnimation.png differ diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index c4b19cf..51f73ff 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -30,7 +30,7 @@ namespace DangerousD.GameCore AppManager.Instance.GameManager.Register(this); } - public virtual void OnCollision() + public virtual void OnCollision(GameObject gameObject) { } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 23e010a..22e32d0 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -15,30 +15,23 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters private bool isGoRight = true; int leftBorder; int rightBorder; + bool isAttaking = false; public Zombie(Vector2 position) : base(position) { Width = 72; Height = 120; - monster_speed = 10; - GraphicsComponent.StartAnimation("ZombieLeftAttack"); + monster_speed = 3; name = "Zombie"; - leftBorder = (int)position.X; - rightBorder = (int)position.X + 200; + leftBorder = (int)position.X - 60; + rightBorder = (int)position.X + 120; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); public override void Update(GameTime gameTime) { - if (AppManager.Instance.GameManager.GetPlayer1.Pos.X>Pos.X) - isGoRight = true; - else - isGoRight = false; - Move(gameTime); - - if(Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X) + if (!isAttaking) { - Attack(); - AppManager.Instance.GameManager.GetPlayer1.Death(name); + Move(gameTime); } base.Update(gameTime); @@ -46,16 +39,22 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { + velocity.X = 0; + isAttaking = true; if (isGoRight) { - GraphicsComponent.StopAnimation(); - GraphicsComponent.StartAnimation("ZombieRightAttack"); + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { + GraphicsComponent.StartAnimation("ZombieAttackRight"); + } AppManager.Instance.GameManager.players[0].Death(name); } else if (!isGoRight) { - GraphicsComponent.StopAnimation(); - GraphicsComponent.StartAnimation("ZombieLeftAttack"); + if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack") + { + GraphicsComponent.StartAnimation("ZombieLeftAttack"); + } AppManager.Instance.GameManager.players[0].Death(name); } } @@ -67,20 +66,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - double delta = gameTime.ElapsedGameTime.TotalSeconds; + float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; if (isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { GraphicsComponent.StartAnimation("ZombieMoveRight"); - velocity = new Vector2(monster_speed, 0); + } + velocity.X = monster_speed; } else if (!isGoRight) { - if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + { GraphicsComponent.StartAnimation("ZombieMoveLeft"); - velocity = new Vector2(-monster_speed, 0); + } + velocity.X = -monster_speed; } + + if(Pos.X >= rightBorder) + { + isGoRight = false; + } + + else if(Pos.X <= leftBorder) + { + isGoRight = true; + } + } + public override void OnCollision(GameObject gameObject) + { + if(gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + } + } + base.OnCollision(gameObject); } public void TakeDamage(int damage) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs index 90266bf..3c8e320 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs @@ -5,18 +5,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects.PlayerDeath; namespace DangerousD.GameCore.GameObjects.LivingEntities { public class Player : LivingEntity { + bool isAlive = true; public Player(Vector2 position) : base(position) { Width = 32; Height = 64; } + public bool IsAlive { get { return isAlive; } } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");//TODO: Change to player + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack", "DeathFromZombie" }, "ZombieMoveLeft");//TODO: Change to player public void Kill() { @@ -25,7 +28,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public void Death(string monsterName) { - //анимация по имени монстра + if(monsterName == "Zombie") + { + DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); + } + isAlive = false; } } } diff --git a/DangerousD/GameCore/GameObjects/PlayerDeath/DeathRectangle.cs b/DangerousD/GameCore/GameObjects/PlayerDeath/DeathRectangle.cs new file mode 100644 index 0000000..1ddaf45 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/PlayerDeath/DeathRectangle.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects; +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; + +namespace DangerousD.GameCore.GameObjects.PlayerDeath +{ + public class DeathRectangle : GameObject + { + public DeathRectangle(Vector2 pos, string DeathType) : base(pos) + { + Height = 128; + Width = 128; + PlayDeath(DeathType); + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie"}, + "DeathFromZombie"); + private void PlayDeath(string deathName) + { + if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie") + { + GraphicsComponent.StartAnimation("DeathFromZombie"); + } + } + + } +} diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index e468dbb..c140696 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -10,9 +10,9 @@ namespace DangerousD.GameCore.Levels { public void InitLevel() { - new Player(new Vector2(0,0)); + new Player(new Vector2(80,0)); - var Zombie = new Zombie(new Vector2(256, 128)); + var Zombie = new Zombie(new Vector2(140, 128)); var Frank = new Frank(new Vector2(384, 128)); new GrassBlock(new Vector2(0, 224)); diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index f017120..55d83c2 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -19,6 +19,7 @@ namespace DangerousD.GameCore public MapManager mapManager; public PhysicsManager physicsManager; public List players; + public List otherObjects = new(); public Player GetPlayer1 { get; private set; } public GameManager() { @@ -33,16 +34,27 @@ namespace DangerousD.GameCore internal void Register(GameObject gameObject) { - if (gameObject is LivingEntity) - livingEntities.Add(gameObject as LivingEntity); - if (gameObject is Entity) - entities.Add(gameObject as Entity); - if (gameObject is MapObject) - mapObjects.Add(gameObject as MapObject); if (gameObject is Player) { + livingEntities.Add(gameObject as LivingEntity); players.Add(gameObject as Player); - GetPlayer1= players[0]; + GetPlayer1 = players[0]; + } + else if (gameObject is LivingEntity) + { + livingEntities.Add(gameObject as LivingEntity); + } + else if (gameObject is Entity) + { + entities.Add(gameObject as Entity); + } + else if (gameObject is MapObject) + { + mapObjects.Add(gameObject as MapObject); + } + else + { + otherObjects.Add(gameObject); } } @@ -54,6 +66,8 @@ namespace DangerousD.GameCore item.Draw(_spriteBatch); foreach (var item in livingEntities) item.Draw(_spriteBatch); + foreach (var item in otherObjects) + item.Draw(_spriteBatch); } public void Update(GameTime gameTime) @@ -64,6 +78,8 @@ namespace DangerousD.GameCore item.Update(gameTime); foreach (var item in livingEntities) item.Update(gameTime); + foreach (var item in otherObjects) + item.Update(gameTime); physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime); diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index e847c45..03d97b3 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -92,8 +92,8 @@ namespace DangerousD.GameCore.Managers { if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle)) { - livingEntities[j].OnCollision(); - entities[i].OnCollision(); + livingEntities[j].OnCollision(entities[i]); + entities[i].OnCollision(livingEntities[j]); } } } @@ -107,8 +107,8 @@ namespace DangerousD.GameCore.Managers { if (livingEntities[i].Rectangle.Intersects(livingEntities[j].Rectangle)) { - livingEntities[i].OnCollision(); - livingEntities[j].OnCollision(); + livingEntities[i].OnCollision(livingEntities[j]); + livingEntities[j].OnCollision(livingEntities[i]); } } }