From 89ae5551029696023b722449a701b2f900aae349 Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Fri, 18 Aug 2023 00:31:46 +0300 Subject: [PATCH] Huchman_1 --- .../AnimationsFileCreator.csproj | 3 +- AnimationsFileCreator/Program.cs | 8 --- DangerousD/Content/map.tmx | 59 +++++++++++++++++++ DangerousD/GameCore/GameObjects/GameObject.cs | 7 +++ .../LivingEntities/Monsters/Frank.cs | 6 +- .../LivingEntities/Monsters/FrankBalls.cs | 45 ++++++++------ .../LivingEntities/Monsters/Hunchman.cs | 12 ++++ DangerousD/GameCore/Managers/AppManager.cs | 2 +- DangerousD/GameCore/Managers/GameManager.cs | 1 + DangerousD/GameCore/Managers/MapManager.cs | 2 +- .../GameCore/Managers/PhysicsManager.cs | 4 ++ 11 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 DangerousD/Content/map.tmx diff --git a/AnimationsFileCreator/AnimationsFileCreator.csproj b/AnimationsFileCreator/AnimationsFileCreator.csproj index 9e982a1..296b0a7 100644 --- a/AnimationsFileCreator/AnimationsFileCreator.csproj +++ b/AnimationsFileCreator/AnimationsFileCreator.csproj @@ -2,8 +2,7 @@ Exe - net6.0-windows - true + net6.0 diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index 9a712a0..1fc3f13 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework; using Newtonsoft.Json; using System; -using System.Windows.Forms; using System.IO; using System.Linq; using System.Reflection.Metadata; @@ -17,13 +16,6 @@ namespace AnimationsFileCreator Console.WriteLine("Добро пожаловать в костыльную программу по созданию файлов анимации для игры DungerousD"); Console.Write("Введите название текстуры (нажмите enter, чтобы выбрать файл во всплывающем окошке): "); string textureName = Console.ReadLine(); - if (textureName == "") - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.ShowDialog(); - textureName = dialog.FileName.Split('\\').Last(); - textureName = textureName.Split('.')[0]; - } Console.WriteLine("Введите количество кадров анимации: "); int framesCount = int.Parse(Console.ReadLine()); Console.WriteLine("Введите длительность кадра в анимации: "); diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx new file mode 100644 index 0000000..b6b3b95 --- /dev/null +++ b/DangerousD/Content/map.tmx @@ -0,0 +1,59 @@ + + + + + + +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294 + + +294,294,294,294,294,321,321,321,321,321,321,321,321,321,321,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,321,321,321,321,321,321,321,321,321,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +294,294,294,294,321,321,321,321,321,321,321,321,321,321,321,321 + + + + + + + + + + + + + + + + + + + diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index ae5cd2c..777e096 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -36,6 +36,12 @@ namespace DangerousD.GameCore { } + protected int obsticles = 0; + public virtual void OnCollisionWithObsticle(GameObject gameObject) + { + obsticles++;//SD + } + public virtual void Initialize() { } @@ -47,6 +53,7 @@ namespace DangerousD.GameCore public virtual void Update(GameTime gameTime) { + obsticles = 0; GraphicsComponent.Update(); } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs index b67dd12..27ab55f 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs @@ -20,13 +20,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters get { return position; } } - public Frank(Vector2 position) : base(position) + public Frank(Vector2 position) : base(new Vector2(300, 200)) { - this.position = position; + //position = new Vector2(300, 200); Width = 112; Height = 160; GraphicsComponent.StartAnimation("FrankMoveLeft"); - monster_speed = 1; + monster_speed = 3; name = "Frank"; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs index 6ae475d..0538c4b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -7,37 +7,37 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects.MapObjects; namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class FrankBalls : CoreEnemy { private Rectangle collision; - private Vector2 position; - private int healthBall; private bool isFlyRight = true; private bool isAttacking = false; - public Rectangle Collision { get { return collision; } } - public FrankBalls(Vector2 position) : base(position) + public FrankBalls(Vector2 position) : base(new Vector2(300, 200)) { - this.position = position; + name = "FrankBalls"; Width = 40; Height = 40; monster_speed = 2; + monster_health = 13; acceleration = Vector2.Zero; + velocity = new Vector2(monster_speed, monster_speed); } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight"); public override void Update(GameTime gameTime) { - collision = new Rectangle((int)position.X, (int)position.Y, 40, 40); + collision = new Rectangle((int)_pos.X, (int)_pos.Y, 40, 40); if (!isAttacking) { @@ -53,6 +53,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters isFlyRight = false; } + var foundObj = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)_pos.X-1, (int)_pos.Y-1, Width+2, Height+2), typeof(StopTile)); + + if (foundObj != null && foundObj.Count > 0) + { + + float av = foundObj.Sum(x => x.Rectangle.X)/foundObj.Count; + float avy = foundObj.Sum(x => x.Rectangle.Y)/foundObj.Count; + + if (avy <= _pos.Y) + velocity.Y = monster_speed; + else if (avy >= _pos.Y) + velocity.Y = -monster_speed; + if (av <= _pos.X) + velocity.X = -monster_speed; + else if (av >= _pos.X) + velocity.X = monster_speed; + monster_health--; + } + base.Update(gameTime); } @@ -78,19 +97,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - velocity.X = 0; - velocity.Y = 0; - - if(isFlyRight) - { - velocity.X += monster_speed; - velocity.Y += monster_speed; - } - else if(!isFlyRight) - { - velocity.X -= monster_speed; - velocity.Y -= monster_speed; - } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index cc6ecd5..7d3e939 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs @@ -12,8 +12,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Hunchman : CoreEnemy { + private bool isGoRight = true; + public Hunchman(Vector2 position) : base(position) { + Width = 20; + Height = 30; + name = "Hunchman"; + GraphicsComponent.StartAnimation(""); + monster_speed = 3; + } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight"); @@ -30,7 +38,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { + var player = AppManager.Instance.GameManager.players[0]; + if(player.Pos.X > 0) + { + } } } } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index f800998..0993679 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -166,7 +166,7 @@ namespace DangerousD.GameCore case GameState.Lobby: break; case GameState.Game: - GameManager.mapManager.LoadLevel("lvl"); + GameManager.mapManager.LoadLevel("map"); break; case GameState.GameOver: break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index f2ce8c8..caae816 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -46,6 +46,7 @@ namespace DangerousD.GameCore internal void Register(GameObject gameObject) { + GetAllGameObjects.Add(gameObject); if (gameObject is Player) { livingEntities.Add(gameObject as LivingEntity); diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs index 36a0f6b..593383c 100644 --- a/DangerousD/GameCore/Managers/MapManager.cs +++ b/DangerousD/GameCore/Managers/MapManager.cs @@ -63,7 +63,7 @@ namespace DangerousD.GameCore.Managers { if (tiles[i] != 0) { - Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale, + Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale + 400, ((chunkY + i / chunkW) * tileSize.Y + offsetY) * _scale); //pos *= _scale; Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint()); diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 28ecf14..edaad38 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -97,6 +97,10 @@ namespace DangerousD.GameCore.Managers if (!isYNormalise) currentEntity.velocity.Y = 0; currentEntity.SetPosition(new Vector2(oldRect.X, oldRect.Y)); + if (!isXNormalise || !isYNormalise) + { + currentEntity.OnCollisionWithObsticle(mapObjects[i]); + } } }