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 1c25c38..0ea387f 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -13,7 +13,7 @@ #---------------------------------- Content ---------------------------------# -#begin animation1.png +#begin MonstersAnimations.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -23,7 +23,19 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:animation1.png +/build: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 ButtonFont.spritefont /importer:FontDescriptionImporter @@ -95,18 +107,6 @@ /processorParam:TextureFormat=Color /build:menuFon3.jpg -#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/animation1.png b/DangerousD/Content/animation1.png deleted file mode 100644 index a599347..0000000 Binary files a/DangerousD/Content/animation1.png and /dev/null differ diff --git a/DangerousD/Content/animations/BallMoveRight b/DangerousD/Content/animations/BallMoveRight new file mode 100644 index 0000000..fe03349 --- /dev/null +++ b/DangerousD/Content/animations/BallMoveRight @@ -0,0 +1 @@ +{"id":"BallMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":229,"Y":332,"Width":16,"Height":16},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} 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/FlameSkullMoveLeft b/DangerousD/Content/animations/FlameSkullMoveLeft new file mode 100644 index 0000000..8b2ffbd --- /dev/null +++ b/DangerousD/Content/animations/FlameSkullMoveLeft @@ -0,0 +1 @@ +{"id":"FlameSkullMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":593,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/FlameSkullMoveRight b/DangerousD/Content/animations/FlameSkullMoveRight new file mode 100644 index 0000000..c0c96b6 --- /dev/null +++ b/DangerousD/Content/animations/FlameSkullMoveRight @@ -0,0 +1 @@ +{"id":"FlameSkullMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":576,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostAttack b/DangerousD/Content/animations/GhostAttack new file mode 100644 index 0000000..7ada2dc --- /dev/null +++ b/DangerousD/Content/animations/GhostAttack @@ -0,0 +1 @@ +{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostMoveLeft b/DangerousD/Content/animations/GhostMoveLeft new file mode 100644 index 0000000..32b880b --- /dev/null +++ b/DangerousD/Content/animations/GhostMoveLeft @@ -0,0 +1 @@ +{"id":"GhostMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":536,"Width":24,"Height":26},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostMoveRight b/DangerousD/Content/animations/GhostMoveRight new file mode 100644 index 0000000..74911c7 --- /dev/null +++ b/DangerousD/Content/animations/GhostMoveRight @@ -0,0 +1 @@ +{"id":"GhostMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":503,"Width":24,"Height":26},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostSpawn b/DangerousD/Content/animations/GhostSpawn new file mode 100644 index 0000000..99d53e1 --- /dev/null +++ b/DangerousD/Content/animations/GhostSpawn @@ -0,0 +1 @@ +{"id":"GhostSpawn","textureName":"MonstersAnimations","startSpriteRectangle":{"X":26,"Y":503,"Width":24,"Height":30},"frameSecond":[{"Item1":0,"Item2":20}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanDaggerLeft b/DangerousD/Content/animations/HunchmanDaggerLeft new file mode 100644 index 0000000..b21064a --- /dev/null +++ b/DangerousD/Content/animations/HunchmanDaggerLeft @@ -0,0 +1 @@ +{"id":"HunchmanDaggerLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":224,"Y":129,"Width":9,"Height":6},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanDaggerRight b/DangerousD/Content/animations/HunchmanDaggerRight new file mode 100644 index 0000000..43354f1 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanDaggerRight @@ -0,0 +1 @@ +{"id":"HunchmanDaggerRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":224,"Y":116,"Width":9,"Height":6},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderMoveLeft b/DangerousD/Content/animations/SpiderMoveLeft new file mode 100644 index 0000000..262a25b --- /dev/null +++ b/DangerousD/Content/animations/SpiderMoveLeft @@ -0,0 +1 @@ +{"id":"SpiderMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":225,"Width":34,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderMoveRight b/DangerousD/Content/animations/SpiderMoveRight new file mode 100644 index 0000000..ffebe55 --- /dev/null +++ b/DangerousD/Content/animations/SpiderMoveRight @@ -0,0 +1 @@ +{"id":"SpiderMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":199,"Width":34,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderOnWeb b/DangerousD/Content/animations/SpiderOnWeb new file mode 100644 index 0000000..c9f8c45 --- /dev/null +++ b/DangerousD/Content/animations/SpiderOnWeb @@ -0,0 +1 @@ +{"id":"SpiderOnWeb","textureName":"MonstersAnimations","startSpriteRectangle":{"X":80,"Y":199,"Width":16,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderWeb b/DangerousD/Content/animations/SpiderWeb new file mode 100644 index 0000000..39363d6 --- /dev/null +++ b/DangerousD/Content/animations/SpiderWeb @@ -0,0 +1 @@ +{"id":"SpiderWeb","textureName":"MonstersAnimations","startSpriteRectangle":{"X":108,"Y":199,"Width":4,"Height":8},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfJumpLeft b/DangerousD/Content/animations/WolfJumpLeft new file mode 100644 index 0000000..2e54b48 --- /dev/null +++ b/DangerousD/Content/animations/WolfJumpLeft @@ -0,0 +1 @@ +{"id":"WolfJumpLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":133,"Y":290,"Width":40,"Height":33},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfJumpRight b/DangerousD/Content/animations/WolfJumpRight new file mode 100644 index 0000000..43760af --- /dev/null +++ b/DangerousD/Content/animations/WolfJumpRight @@ -0,0 +1 @@ +{"id":"WolfJumpRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":133,"Y":258,"Width":40,"Height":33},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfMoveLeft b/DangerousD/Content/animations/WolfMoveLeft new file mode 100644 index 0000000..924a49c --- /dev/null +++ b/DangerousD/Content/animations/WolfMoveLeft @@ -0,0 +1 @@ +{"id":"WolfMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":292,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfMoveRight b/DangerousD/Content/animations/WolfMoveRight new file mode 100644 index 0000000..67ca172 --- /dev/null +++ b/DangerousD/Content/animations/WolfMoveRight @@ -0,0 +1 @@ +{"id":"WolfMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":258,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"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 078a850..c354e3e 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -14,8 +14,8 @@ namespace DangerousD.GameCore { protected Vector2 _pos; public Vector2 Pos => _pos; - public int Width { get; protected set; } - public int Height { get; protected set; } + public int Width { get; set; } + public int Height { get; set; } public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height); public Vector2 velocity; public Vector2 acceleration; diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs similarity index 90% rename from DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs rename to DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs index 1b28997..4fbe6ff 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs @@ -24,11 +24,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public override void Update(GameTime gameTime) { - if (monster_health <= 0) - { - Death(); - isAlive = false; - } base.Update(gameTime); } public abstract void Death(); @@ -36,5 +31,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public abstract void Attack(); public abstract void Move(GameTime gameTime); + + public void TakeDamage(int damage) + { + monster_health -= damage; + if (monster_health <= 0) + { + Death(); + isAlive = false; + } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs index c521c2e..cd00606 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs @@ -14,10 +14,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public FlameSkull(Vector2 position) : base(position) { - + Width = 62; + Height = 40; + monster_speed = 3; + name = "Skull"; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FlameSkullMoveLeft", "FlameSkullMoveRight" }, "FlameSkullMoveRight"); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FlameSkullMoveRight" , "FlameSkullMoveLeft"}, "FlameSkullMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs index 0434e4d..b0b3429 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs @@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters Height = 160; GraphicsComponent.StartAnimation("FrankMoveLeft"); monster_speed = 1; - name = "Фрэнк"; + name = "Frank"; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); @@ -35,35 +35,27 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - /* if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20) + var player = AppManager.Instance.GameManager.players[0]; + if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20) { player.Death(name); - } */ - + } + if (isGoRight) - { + { if (GraphicsComponent.GetCurrentAnimation != "FrankMoveRight") { GraphicsComponent.StartAnimation("FrankMoveRight"); - velocity = new Vector2(monster_speed, 0); } + velocity.X = monster_speed; } - else if (!isGoRight) + else { if (GraphicsComponent.GetCurrentAnimation != "FrankMoveLeft") { GraphicsComponent.StartAnimation("FrankMoveLeft"); - velocity = new Vector2(-monster_speed, 0); } - } - - if (_pos.X <= 1) - { - isGoRight = true; - } - else if (_pos.X >= 500) - { - isGoRight = false; + velocity.X = -monster_speed; } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs new file mode 100644 index 0000000..7101da2 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -0,0 +1,41 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class FrankBalls : CoreEnemy + { + public FrankBalls(Vector2 position) : base(position) + { + name = "FrankBalls"; + Width = 40; + Height = 40; + monster_speed = 1; + acceleration = Vector2.Zero; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs index b8827b1..1e47e99 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs @@ -12,11 +12,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public Ghost(Vector2 position) : base(position) { + monster_speed = 1; + name = "Ghost"; + Width = 48; + Height = 62; + GraphicsComponent.StartAnimation("GhostSpawn"); } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, ""); - + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "GhostMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs new file mode 100644 index 0000000..9e616ed --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs @@ -0,0 +1,40 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class HunchmanDagger : CoreEnemy + { + public HunchmanDagger(Vector2 position) : base(position) + { + name = "Hunchman"; + monster_speed = 1; + Width = 9; + Height = 6; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new (new List { "HunchmanDaggerRight", "HunchmanDaggerLeft" }, "HunchmanDaggerLeft"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs index 9513d71..bffa5f6 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs @@ -12,15 +12,85 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Spider : CoreEnemy { + protected SpiderWeb web; + protected float delay; + protected int webLength; + protected bool isDown; + protected bool isDownUp; public Spider(Vector2 position) : base(position) { + isDownUp = true; + isDown = true; + web = new SpiderWeb(Pos); + name = "Spider"; + Width = 112; + Height = 24; + delay = 0; + webLength = 0; + monster_speed = 1; + acceleration = Vector2.Zero; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderMoveRight", "SpiderMoveLeft", "SpiderDown", "SpiderUp" }, ""); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderMoveRight", "SpiderMoveLeft", "SpiderOnWeb" }, "SpiderMoveRight"); - public override void Attack() + public override void Update(GameTime gameTime) { + if (isDownUp) + { + Width = 48; + Height = 72; + delay += (float)gameTime.ElapsedGameTime.TotalSeconds; + if (delay > 0.5 && webLength <= 4 && isDown) + { + StartCicycleAnimation("SpiderOnWeb"); + webLength++; + _pos.Y += 25; + web.Height = webLength * 25; + web.SetPosition(new Vector2(_pos.X + Width / 2 - web.Width / 2, Pos.Y - 25 * webLength)); + delay = 0; + if (webLength == 4) + { + isDown = false; + } + } + else if (delay > 0.5 && webLength != 0 && !isDown) + { + StartCicycleAnimation("SpiderOnWeb"); + webLength--; + _pos.Y -= 25; + web.Height = webLength * 25; + web.SetPosition(new Vector2(_pos.X + Width / 2 - web.Width / 2, Pos.Y - 25 * webLength)); + delay = 0; + if (webLength == 0) + { + isDown = true; + } + } + else + { + Width = 112; + Height = 24; + } + } + base.Update(gameTime); + } + public override void Attack() + { //48 72 + + } + + public override void Draw(SpriteBatch spriteBatch) + { + if (GraphicsComponent.GetCurrentAnimation == "SpiderOnWeb") + { + GraphicsComponent.DrawAnimation(new Rectangle((int)Pos.X, (int)Pos.Y, 48, 72), spriteBatch); + + } + else + { + base.Draw(spriteBatch); + } } public override void Death() diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs new file mode 100644 index 0000000..d91ccaf --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs @@ -0,0 +1,41 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class SpiderWeb : CoreEnemy + { + public SpiderWeb(Vector2 position) : base(position) + { + name = "Web"; + monster_speed = 1; + Width = 16; + Height = 0; + acceleration = Vector2.Zero; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderWeb" }, "SpiderWeb"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs index 91af742..9d5acb8 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs @@ -14,9 +14,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public Werewolf(Vector2 position) : base(position) { + name = "Wolf"; + monster_speed = 1; + Width = 78; + Height = 96; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, ""); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, "WolfMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index e120977..dba2deb 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) { - if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack") - GraphicsComponent.StartAnimation("ZombieRightAttack"); + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { + GraphicsComponent.StartAnimation("ZombieAttackRight"); + } AppManager.Instance.GameManager.players[0].Death(name); } else if (!isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack") - GraphicsComponent.StartAnimation("ZombieLeftAttack"); + { + GraphicsComponent.StartAnimation("ZombieLeftAttack"); + } AppManager.Instance.GameManager.players[0].Death(name); } } @@ -67,26 +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.X = monster_speed; } else if (!isGoRight) { - if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + { GraphicsComponent.StartAnimation("ZombieMoveLeft"); + } velocity.X = -monster_speed; } - } - public void TakeDamage(int damage) + if(Pos.X >= rightBorder) + { + isGoRight = false; + } + + else if(Pos.X <= leftBorder) + { + isGoRight = true; + } + } + public override void OnCollision(GameObject gameObject) { - monster_health -= damage; - //play take damage animation + if(gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + } + } + base.OnCollision(gameObject); } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs new file mode 100644 index 0000000..1ddaf45 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/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/GameObjects/LivingEntities/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs similarity index 50% rename from DangerousD/GameCore/GameObjects/LivingEntities/Player.cs rename to DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 90266bf..cd23ad2 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -5,18 +5,25 @@ 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; + GraphicsComponent.actionOfAnimationEnd += () => + { + AppManager.Instance.ChangeGameState(GameState.GameOver); + }; } + 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 +32,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public void Death(string monsterName) { - //анимация по имени монстра + if(monsterName == "Zombie") + { + DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); + GraphicsComponent.actionOfAnimationEnd(); + } + isAlive = false; } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs index 75890aa..5c18831 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntity.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs @@ -23,4 +23,12 @@ public abstract class LivingEntity : Entity } base.Update(gameTime); } + + public virtual void StartCicycleAnimation(string animationName) + { + if (GraphicsComponent.GetCurrentAnimation != animationName) + { + GraphicsComponent.StartAnimation(animationName); + } + } } \ No newline at end of file diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 024a3d2..6e60b29 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -116,7 +116,10 @@ namespace DangerousD.GameCore.Graphics if (!currentAnimation.IsCycle) { currentAnimation = neitralAnimation; - actionOfAnimationEnd(); + if(actionOfAnimationEnd != null) + { + actionOfAnimationEnd(); + } } currentFrame = 0; diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index d23c7c6..c3558d9 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -2,7 +2,7 @@ using DangerousD.GameCore.GameObjects.MapObjects; using Microsoft.Xna.Framework; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; - +using System.Collections.Generic; namespace DangerousD.GameCore.Levels { @@ -10,10 +10,15 @@ 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(140, 128)); + var Frank = new Frank(new Vector2(384, 128)); - var Zombie = new Zombie(new Vector2(300, 64)); - var Frank = new Frank(new Vector2(100, 64)); + var Spider = new Spider(new Vector2(112, 0)); + var FlameSkull = new FlameSkull(new Vector2(512, 0)); + var Werewolf = new Werewolf(new Vector2(640, 0)); + var Ghost = new Ghost(new Vector2(730, 0)); + var FrankBalls = new FrankBalls(new Vector2(Frank.Pos.X, Frank.Pos.Y)); new GrassBlock(new Vector2(0, 224)); for (int i = 0; i < 50; i++) diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index dc44ba9..ab061b9 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -13,7 +13,7 @@ using DangerousD.GameCore.Managers; namespace DangerousD.GameCore { - public enum GameState { Menu, Options, Lobby, Game, Login } + public enum GameState { Menu, Options, Lobby, Game, Login, GameOver } public class AppManager : Game { public static AppManager Instance { get; private set; } 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);