diff --git a/.gitignore b/.gitignore index 8636995..1537aee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin obj .vs -.idea \ No newline at end of file +.idea +DangerousD.sln.DotSettings.user \ No newline at end of file diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index 2075f19..8d94070 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -13,7 +13,7 @@ #---------------------------------- Content ---------------------------------# -#begin ../../../animation1.png +#begin animation1.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -23,7 +23,7 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:../../../animation1.png;animation1.png +/build:animation1.png #begin File.spritefont /importer:FontDescriptionImporter diff --git a/DangerousD/Content/MonstersAnimations.png b/DangerousD/Content/MonstersAnimations.png index 01d185c..5bc9cca 100644 Binary files a/DangerousD/Content/MonstersAnimations.png and b/DangerousD/Content/MonstersAnimations.png differ diff --git a/DangerousD/Content/animation1.png b/DangerousD/Content/animation1.png index 01d185c..a599347 100644 Binary files a/DangerousD/Content/animation1.png and b/DangerousD/Content/animation1.png differ diff --git a/DangerousD/GameCore/GameObjects/Entity.cs b/DangerousD/GameCore/GameObjects/Entity.cs index eb865e5..cf2caa9 100644 --- a/DangerousD/GameCore/GameObjects/Entity.cs +++ b/DangerousD/GameCore/GameObjects/Entity.cs @@ -13,17 +13,6 @@ namespace DangerousD.GameCore.GameObjects public Entity(Vector2 position) : base(position) {} - public void SetPosition(Vector2 position) { targetPosition = position; } - public override void Update(GameTime gameTime) - { - if (Vector2.Distance(Pos, targetPosition) > 0.5f) - { - Vector2 dir = targetPosition - Pos; - dir.Normalize(); - _pos += dir * speed; - } - base.Update(gameTime); - } } } diff --git a/DangerousD/GameCore/GameObjects/IDrawableObject.cs b/DangerousD/GameCore/GameObjects/IDrawableObject.cs index 61df454..f157dcb 100644 --- a/DangerousD/GameCore/GameObjects/IDrawableObject.cs +++ b/DangerousD/GameCore/GameObjects/IDrawableObject.cs @@ -11,4 +11,4 @@ namespace DangerousD.GameCore.GUI void Update(GameTime gameTime); void Draw(SpriteBatch spriteBatch); } -} +} \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs index c5b7230..1b28997 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs @@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities //здесь я не понял } - public virtual void Update(GameTime gameTime, Player player) + public override void Update(GameTime gameTime) { if (monster_health <= 0) { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 68e2881..23e010a 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { Width = 72; Height = 120; - monster_speed = 20; + monster_speed = 10; GraphicsComponent.StartAnimation("ZombieLeftAttack"); name = "Zombie"; leftBorder = (int)position.X; @@ -27,14 +27,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); - public override void Update(GameTime gameTime, Player player) + 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 <= player.Pos.X || Pos.X - 20 >= player.Pos.X) + if(Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X) { Attack(); - player.Death(name); + AppManager.Instance.GameManager.GetPlayer1.Death(name); } base.Update(gameTime); @@ -46,13 +50,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { GraphicsComponent.StopAnimation(); GraphicsComponent.StartAnimation("ZombieRightAttack"); - AppManager.Instance.GameManager.Player.Death(name); + AppManager.Instance.GameManager.players[0].Death(name); } else if (!isGoRight) { GraphicsComponent.StopAnimation(); GraphicsComponent.StartAnimation("ZombieLeftAttack"); - AppManager.Instance.GameManager.Player.Death(name); + AppManager.Instance.GameManager.players[0].Death(name); } } @@ -67,19 +71,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters if (isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") - { GraphicsComponent.StartAnimation("ZombieMoveRight"); - velocity = new Vector2(monster_speed, 0); - } + velocity = new Vector2(monster_speed, 0); } else if (!isGoRight) { if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") - { GraphicsComponent.StartAnimation("ZombieMoveLeft"); - velocity = new Vector2(-monster_speed, 0); - } + velocity = new Vector2(-monster_speed, 0); } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs index dd0e96e..90266bf 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs @@ -12,9 +12,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { public Player(Vector2 position) : base(position) { + Width = 32; + Height = 64; } - protected override GraphicsComponent GraphicsComponent => throw new NotImplementedException(); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");//TODO: Change to player public void Kill() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs index f5a2b98..5352489 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntity.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs @@ -11,7 +11,7 @@ public abstract class LivingEntity : Entity { acceleration = new Vector2(0, 10); } - public void SetPosition(Vector2 position) { targetPosition = position; } + public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine public override void Update(GameTime gameTime) { @@ -19,7 +19,7 @@ public abstract class LivingEntity : Entity { Vector2 dir = targetPosition - Pos; dir.Normalize(); - Pos += dir * velocity; + _pos += dir * velocity; } base.Update(gameTime); } diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index 835674c..323370b 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -10,10 +10,16 @@ namespace DangerousD.GameCore.Levels { public void InitLevel() { - var Трава = new GrassBlock(new Vector2(0, 128)); - var Death = new TestAnimationDeath(new Vector2(128, 128)); + new Player(new Vector2(0,0)); var Zombie = new Zombie(new Vector2(256, 128)); var Frank = new Frank(new Vector2(384, 128)); + + new GrassBlock(new Vector2(0, 224)); + for (int i = 0; i < 50; i++) + { + new GrassBlock(new Vector2(i*32, 256)); + } + new GrassBlock(new Vector2(500, 224)); } } } diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 5c946bf..f017120 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -18,13 +18,16 @@ namespace DangerousD.GameCore public List mapObjects; public MapManager mapManager; public PhysicsManager physicsManager; - + public List players; + public Player GetPlayer1 { get; private set; } public GameManager() { livingEntities = new List(); mapObjects = new List(); entities = new List(); + players = new List(); mapManager = new MapManager(); + physicsManager = new PhysicsManager(); mapManager.Init(); } @@ -36,6 +39,11 @@ namespace DangerousD.GameCore entities.Add(gameObject as Entity); if (gameObject is MapObject) mapObjects.Add(gameObject as MapObject); + if (gameObject is Player) + { + players.Add(gameObject as Player); + GetPlayer1= players[0]; + } } public void Draw(SpriteBatch _spriteBatch) @@ -56,7 +64,10 @@ namespace DangerousD.GameCore item.Update(gameTime); foreach (var item in livingEntities) item.Update(gameTime); - + + physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime); + + } } } \ No newline at end of file diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index dbb832f..a181e20 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -19,6 +19,13 @@ namespace DangerousD.GameCore.Managers { item.velocity = item.velocity + item.acceleration * delta; } + + //SD setting positions before check + foreach (var item in livingEntities) + { + item.SetPosition(item.Pos + item.velocity); + } + CheckCollisions(livingEntities, mapObjects); OnCollision(entities, livingEntities); OnCollision(livingEntities); @@ -44,24 +51,24 @@ namespace DangerousD.GameCore.Managers if (livingEntities[i].Rectangle.Right > mapObjects[j].Rectangle.Left) { + //livingEntities[i].SetPosition(livingEntities[i].Pos- new Vector2(livingEntities[i].velocity.X)); livingEntities[i].velocity.X = 0; - livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X - (livingEntities[i].Rectangle.Right - mapObjects[j].Rectangle.Left), livingEntities[i].Pos.Y)); } - else if (livingEntities[i].Rectangle.Left < mapObjects[j].Rectangle.Right) + if (livingEntities[i].Rectangle.Left < mapObjects[j].Rectangle.Right) { livingEntities[i].velocity.X = 0; livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X + mapObjects[j].Rectangle.Right - livingEntities[i].Rectangle.Left, livingEntities[i].Pos.Y)); } - else if (livingEntities[i].Rectangle.Bottom > mapObjects[j].Rectangle.Top) + if (livingEntities[i].Rectangle.Bottom > mapObjects[j].Rectangle.Top) { livingEntities[i].velocity.Y = 0; livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X, livingEntities[i].Pos.Y - (livingEntities[i].Rectangle.Bottom - mapObjects[j].Rectangle.Top))); } - else if (livingEntities[i].Rectangle.Top < mapObjects[j].Rectangle.Bottom) + if (livingEntities[i].Rectangle.Top < mapObjects[j].Rectangle.Bottom) { livingEntities[i].velocity.Y = 0; livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X,