diff --git a/DangerousD/Content/LastLvl.tmx b/DangerousD/Content/LastLvl.tmx new file mode 100644 index 0000000..2efe988 --- /dev/null +++ b/DangerousD/Content/LastLvl.tmx @@ -0,0 +1,130 @@ + + + + + + +410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + +410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0 + + +410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + +410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,376,375,369,370,388,389,726,390,369,370,376,389,376,388,726, +0,376,389,369,370,390,726,388,388,369,370,390,726,388,389,389, +0,388,726,369,370,390,377,375,377,369,370,431,389,389,431,431, +0,389,431,369,370,377,377,389,388,369,370,431,389,375,375,431, +0,377,377,369,370,390,376,389,431,369,370,375,375,726,388,390, +0,388,431,369,370,388,390,376,726,369,370,375,377,376,388,377, +0,388,375,369,370,376,375,377,388,369,370,376,375,389,388,431, +0,390,726,369,370,377,431,431,388,369,370,389,390,390,376,377, +0,377,376,369,370,389,377,431,376,369,370,389,431,726,431,388, +0,377,431,369,370,375,390,390,377,369,370,375,377,389,388,376, +0,390,390,369,370,431,376,389,390,369,370,390,431,376,389,390, +0,431,377,369,370,376,390,388,388,369,370,377,375,390,389,377, +0,390,726,369,370,375,377,726,390,369,370,389,376,388,388,375, +0,390,389,382,383,388,377,388,390,382,383,431,726,390,388,431, +0,389,377,395,396,389,431,377,431,395,396,375,388,726,376,389 + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +389,388,375,369,370,388,377,389,389,369,370,390,375,0,0,0, +390,388,726,369,370,375,726,376,726,369,370,388,375,0,0,0, +388,389,431,369,370,726,377,726,431,369,370,377,375,0,0,0, +388,376,431,369,370,377,375,726,726,369,370,431,376,0,0,0, +376,389,388,369,370,377,390,431,389,369,370,376,431,0,0,0, +389,388,389,369,370,376,726,390,377,369,370,389,377,0,0,0, +431,377,389,369,370,431,726,726,389,369,370,431,390,0,0,0, +390,389,377,369,370,390,390,376,431,369,370,390,376,0,0,0, +388,388,377,369,370,388,431,390,388,369,370,389,377,0,0,0, +388,389,390,369,370,726,377,377,388,369,370,390,390,0,0,0, +388,376,390,369,370,377,377,389,726,369,370,375,726,0,0,0, +431,726,390,369,370,375,431,377,726,369,370,389,389,0,0,0, +390,388,726,369,370,389,375,390,388,369,370,377,726,0,0,0, +375,375,375,382,383,376,390,726,388,382,383,431,726,0,0,0, +389,389,390,395,396,390,390,726,390,395,396,431,390,0,0,0 + + + + + + + + + + + + + + diff --git a/DangerousD/Content/animations/DeathFromSilasHand b/DangerousD/Content/animations/DeathFromSilasHand new file mode 100644 index 0000000..ef28c10 --- /dev/null +++ b/DangerousD/Content/animations/DeathFromSilasHand @@ -0,0 +1 @@ +{"id":"DeathFromSilasHand","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":295,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/GameCore/GameObjects/Entities/Door.cs b/DangerousD/GameCore/GameObjects/Entities/Door.cs index cacaf22..fe18355 100644 --- a/DangerousD/GameCore/GameObjects/Entities/Door.cs +++ b/DangerousD/GameCore/GameObjects/Entities/Door.cs @@ -37,15 +37,19 @@ namespace DangerousD.GameCore.GameObjects.Entities public override void OnCollision(GameObject gameObject) { base.OnCollision(gameObject); - if (gameObject is Player) + if (this is not TeleportingDoor) { - Player player = (Player)gameObject; - if (player.isUping) + if (gameObject is Player) { - AppManager.Instance.GameManager.Remove(this); - //тут спавн лута + Player player = (Player)gameObject; + if (player.isUping) + { + AppManager.Instance.GameManager.Remove(this); + //тут спавн лута + } } } + } } } diff --git a/DangerousD/GameCore/GameObjects/Entities/SilasBall.cs b/DangerousD/GameCore/GameObjects/Entities/SilasBall.cs index 94e7ca6..157b410 100644 --- a/DangerousD/GameCore/GameObjects/Entities/SilasBall.cs +++ b/DangerousD/GameCore/GameObjects/Entities/SilasBall.cs @@ -1,4 +1,5 @@ -using DangerousD.GameCore.Graphics; +using DangerousD.GameCore.GameObjects.LivingEntities; +using DangerousD.GameCore.Graphics; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -14,12 +15,15 @@ namespace DangerousD.GameCore.GameObjects.Entities { private Vector2 v; + public string name; public SilasBall(Vector2 position) : base(position) { Height = 24; Width = 24; acceleration = Vector2.Zero; - + name = "SilasHand"; + + } public SilasBall(Vector2 position, Vector2 velosity) : base(position) { @@ -28,7 +32,8 @@ namespace DangerousD.GameCore.GameObjects.Entities acceleration = Vector2.Zero; velocity = velosity; v = velosity; - + name = "SilasHand"; + } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SilasBallMove" }, "SilasBallMove"); @@ -48,5 +53,21 @@ namespace DangerousD.GameCore.GameObjects.Entities } + public void Attack() + { + AppManager.Instance.GameManager.GetPlayer1.Death(name); + } + public override void OnCollision(GameObject gameObject) + { + base.OnCollision(gameObject); + if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + + } + } + } } } diff --git a/DangerousD/GameCore/GameObjects/Entities/TeleportingDoor.cs b/DangerousD/GameCore/GameObjects/Entities/TeleportingDoor.cs new file mode 100644 index 0000000..558771d --- /dev/null +++ b/DangerousD/GameCore/GameObjects/Entities/TeleportingDoor.cs @@ -0,0 +1,54 @@ +using DangerousD.GameCore.GameObjects.LivingEntities; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.Entities +{ + internal class TeleportingDoor : Door + { + public Vector2 Target; + public bool IsVisible = true; + public Action action; + public TeleportingDoor(Vector2 position, Vector2 size, Rectangle sourceRectangle, Vector2 target, Action action) : base(position, size, sourceRectangle) + { + Target = target; + this.action = action; + } + public override void OnCollision(GameObject gameObject) + { + if (IsVisible) + { + if (gameObject is Player) + { + Player player = (Player)gameObject; + if (player.isUping) + { + IsVisible = false; + + } + } + } + else + { + if (gameObject is Player) + { + Player player = (Player)gameObject; + if (player.isUping) + { + player.SetPosition(Target); + if (action!=null) + { + action(); + } + + } + } + } + } + + } +} diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index 8526427..b91383a 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -63,9 +63,7 @@ namespace DangerousD.GameCore if (AppManager.Instance.InputManager.CollisionsCheat) { spriteBatch.Draw(debugTexture, - new Rectangle(Rectangle.X - GraphicsComponent.CameraPosition.X, - Rectangle.Y - GraphicsComponent.CameraPosition.Y, Rectangle.Width, Rectangle.Height), - Color.White); + new Rectangle((Rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling, (Rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling, Rectangle.Width * GraphicsComponent.scaling, Rectangle.Height * GraphicsComponent.scaling),Color.White); } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs index 15018ea..3e2a1b8 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs @@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters Width = 16; Height = 16; monster_health = 2; - monster_speed = 2; + monster_speed = 1; acceleration = Vector2.Zero; } @@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { - + AppManager.Instance.GameManager.GetPlayer1.Death(name); } public override void Attack(GameTime gameTime) @@ -38,7 +38,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { - throw new NotImplementedException(); + for (int i = 0; i < 3; i++) + { + Particle particle = new Particle(Pos); + } + + AppManager.Instance.GameManager.Remove(this); + } public override void Move(GameTime gameTime) @@ -71,12 +77,30 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { base.Update(gameTime); Move(gameTime); - if ((Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X)&&(Pos.Y + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.Y || Pos.Y - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.Y)) - { - - AppManager.Instance.GameManager.GetPlayer1.Death(name); - } + GraphicsComponent.Update(); } + public void TakeDamage() + { + monster_health--; + GraphicsComponent.StartAnimation("SilasHandMove"); + Particle particle = new Particle(Pos); + if (monster_health <= 0) + { + Death(); + } + } + public override void OnCollision(GameObject gameObject) + { + if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + + } + } + base.OnCollision(gameObject); + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs index 6b436b7..46b1cc4 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs @@ -16,6 +16,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters private int attackTime = 60; private int moveTime = 360; private int currentTime = 0; + private int interval = 0; int leftBorder; int rightBorder; List hands = new List(); @@ -119,9 +120,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Update(GameTime gameTime) { base.Update(gameTime); + for (int i = 0; i < hands.Count; i++) + { + if (!AppManager.Instance.GameManager.GetAllGameObjects.Contains(hands[i])) + { + hands.RemoveAt(i); + } + } + + if (hands.Count<2) { - hands.Add(new SilasHands(new Vector2(Pos.X + 60, Pos.Y + 120))); + hands.Add(new SilasHands(new Vector2(Pos.X + 30, Pos.Y + 30))); } if (GraphicsComponent.CurrentAnimation.Id == "SilasMove") { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs index 25e01f0..8644b77 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs @@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath PlayDeath(DeathType); } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie"}, + protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie", "DeathFromSilasHand" }, "DeathFromZombie"); public GraphicsComponent Gr => GraphicsComponent; @@ -29,6 +29,10 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath { GraphicsComponent.StartAnimation("DeathFromZombie"); } + if (GraphicsComponent.GetCurrentAnimation != "DeathFromSilasHand") + { + GraphicsComponent.StartAnimation("DeathFromSilasHand"); + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index eaae151..8fc27bf 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -87,12 +87,29 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { base.OnCollision(gameObject); } + public Rectangle GetShootRectangle(bool isRight) + { + if (isRight) + return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2); + else + return new Rectangle((int)Pos.X-shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2); + } public override void Draw(SpriteBatch spriteBatch) { if (isVisible) { base.Draw(spriteBatch); } + if (AppManager.Instance.InputManager.CollisionsCheat) + { + Rectangle attackRect = GetShootRectangle(isRight); + spriteBatch.Draw(debugTexture, + new Rectangle((attackRect.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling, + (attackRect.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling, + attackRect.Width * GraphicsComponent.scaling, + attackRect.Height * GraphicsComponent.scaling), Color.White); + + } } public void Death(string monsterName) { @@ -123,6 +140,28 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities } }; } + else if (monsterName == "SilasHand") + { + AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName); + deathRectangle.Gr.actionOfAnimationEnd += (a) => + { + if (a == "DeathFrom" + monsterName) + { + AppManager.Instance.ChangeGameState(GameState.Death); + } + }; + } + else if (monsterName == "SilasBall") + { + AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName); + deathRectangle.Gr.actionOfAnimationEnd += (a) => + { + if (a == "DeathFrom" + monsterName) + { + AppManager.Instance.ChangeGameState(GameState.Death); + } + }; + } isAlive = false; } public void Jump() @@ -146,18 +185,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities if (isRight) { StartCicycleAnimation("playerShootRight"); - 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()); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), 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)).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)); + var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(Zombie)); if (targets != null) { foreach (var target in targets) @@ -166,6 +212,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities 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)); } } @@ -257,6 +309,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { FallingThroughPlatform = true; isOnGround = false; - } + } } } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 27eeea8..5aa452f 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; namespace DangerousD.GameCore.Graphics @@ -18,7 +19,7 @@ namespace DangerousD.GameCore.Graphics private List textures; private List texturesNames; private AnimationContainer currentAnimation; - static private int scaling = 4; + static public int scaling = 4; public int parentId; public AnimationContainer CurrentAnimation { diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 81a43d0..10124d6 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -204,7 +204,7 @@ namespace DangerousD.GameCore case GameState.Lobby: break; case GameState.Game: - GameManager.mapManager.LoadLevel("lvl"); + GameManager.mapManager.LoadLevel("LastLvl"); GameManager.FindBorders(); break; case GameState.Death: