diff --git a/DangerousD/Content/animations/SlimeJumpLeftBottom b/DangerousD/Content/animations/SlimeJumpLeftBottom new file mode 100644 index 0000000..876f587 --- /dev/null +++ b/DangerousD/Content/animations/SlimeJumpLeftBottom @@ -0,0 +1 @@ +{"id":"SlimeJumpLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":176,"Y":157,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeJumpLeftTop b/DangerousD/Content/animations/SlimeJumpLeftTop new file mode 100644 index 0000000..e73565f --- /dev/null +++ b/DangerousD/Content/animations/SlimeJumpLeftTop @@ -0,0 +1 @@ +{"id":"SlimeJumpLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":151,"Y":157,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeJumpRightBottom b/DangerousD/Content/animations/SlimeJumpRightBottom new file mode 100644 index 0000000..3a0d067 --- /dev/null +++ b/DangerousD/Content/animations/SlimeJumpRightBottom @@ -0,0 +1 @@ +{"id":"SlimeJumpRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":176,"Y":174,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeJumpRightTop b/DangerousD/Content/animations/SlimeJumpRightTop new file mode 100644 index 0000000..6e75357 --- /dev/null +++ b/DangerousD/Content/animations/SlimeJumpRightTop @@ -0,0 +1 @@ +{"id":"SlimeJumpRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":151,"Y":174,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeMoveLeftBottom b/DangerousD/Content/animations/SlimeMoveLeftBottom new file mode 100644 index 0000000..c2477cc --- /dev/null +++ b/DangerousD/Content/animations/SlimeMoveLeftBottom @@ -0,0 +1 @@ +{"id":"SlimeMoveLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":182,"Width":24,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeMoveLeftTop b/DangerousD/Content/animations/SlimeMoveLeftTop new file mode 100644 index 0000000..90723bf --- /dev/null +++ b/DangerousD/Content/animations/SlimeMoveLeftTop @@ -0,0 +1 @@ +{"id":"SlimeMoveLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":51,"Y":182,"Width":24,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeMoveRightBottom b/DangerousD/Content/animations/SlimeMoveRightBottom new file mode 100644 index 0000000..2caee25 --- /dev/null +++ b/DangerousD/Content/animations/SlimeMoveRightBottom @@ -0,0 +1 @@ +{"id":"SlimeMoveRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":165,"Width":24,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeMoveRightTop b/DangerousD/Content/animations/SlimeMoveRightTop new file mode 100644 index 0000000..ff14358 --- /dev/null +++ b/DangerousD/Content/animations/SlimeMoveRightTop @@ -0,0 +1 @@ +{"id":"SlimeMoveRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":51,"Y":165,"Width":24,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeReadyJumpLeftBottom b/DangerousD/Content/animations/SlimeReadyJumpLeftBottom new file mode 100644 index 0000000..aba1149 --- /dev/null +++ b/DangerousD/Content/animations/SlimeReadyJumpLeftBottom @@ -0,0 +1 @@ +{"id":"SlimeReadyJumpLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":157,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":1,"framesCount":1,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeReadyJumpLeftTop b/DangerousD/Content/animations/SlimeReadyJumpLeftTop new file mode 100644 index 0000000..896a29d --- /dev/null +++ b/DangerousD/Content/animations/SlimeReadyJumpLeftTop @@ -0,0 +1 @@ +{"id":"SlimeReadyJumpLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":157,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":1,"framesCount":1,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeReadyJumpRightBottom b/DangerousD/Content/animations/SlimeReadyJumpRightBottom new file mode 100644 index 0000000..16f8e64 --- /dev/null +++ b/DangerousD/Content/animations/SlimeReadyJumpRightBottom @@ -0,0 +1 @@ +{"id":"SlimeReadyJumpRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":174,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":1,"framesCount":1,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SlimeReadyJumpRightTop b/DangerousD/Content/animations/SlimeReadyJumpRightTop new file mode 100644 index 0000000..95fb101 --- /dev/null +++ b/DangerousD/Content/animations/SlimeReadyJumpRightTop @@ -0,0 +1 @@ +{"id":"SlimeReadyJumpRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":174,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":1,"framesCount":1,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index 952e1de..2553820 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -56,6 +56,7 @@ namespace DangerousD.GameCore GraphicsComponent.DrawAnimation(Rectangle, spriteBatch); //debug spriteBatch.Draw(debugTexture,new Rectangle(Rectangle.X-GraphicsComponent.CameraPosition.X,Rectangle.Y-GraphicsComponent.CameraPosition.Y,Rectangle.Width,Rectangle.Height), Color.White); + } } } \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs index 9f3f936..3234dc0 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs @@ -12,19 +12,143 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Slime : CoreEnemy { + private bool isGoRight = true; + private bool isDown = false; + int leftBorder; + int rightBorder; + bool isAttaking = false; + int delay; + bool isJumping = false; public Slime(Vector2 position) : base(position) { + Width = 48; + Height = 16; + name = "Slime"; + monster_speed = 3; + monster_health = 2; + leftBorder = 100; + rightBorder = 400; + //acceleration = Vector2.Zero; + delay = 30; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SlimeMoveLeftTop", "SlimeMoveLeftBottom", "SlimeMoveRightTop", - "SlimeMoveRightBottom", "SlimeReadyJumpRightBottom", "SlimeReadyJumpRightTop", "SlimeReadyJumpLeftBottom", "SlimeReadyJumpLeftTop", "SlimeJumpRightBottom", - "SlimeJumpRightTop", "SlimeJumpLeftBottom", "SlimeJumpLeftTop" }, ""); + "SlimeMoveRightBottom", "SlimeReadyJumpRightBottom", "SlimeReadyJumpRightTop", "SlimeReadyJumpLeftBottom", "SlimeReadyJumpLeftTop", "SlimeJumpRightBottom", + "SlimeJumpRightTop", "SlimeJumpLeftBottom", "SlimeJumpLeftTop" }, "SlimeMoveRightTop"); public override void Attack() { } + public void Jump() + { + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 100, 100)); + velocity.X = 0; + Height = 32; + if (isGoRight && isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpLeftBottom") + { + GraphicsComponent.StartAnimation("SlimeReadyJumpLeftBottom"); + } + delay--; + if (delay <= 0) + { + isJumping = true; + velocity = new Vector2(5, -3); + if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom") + { + GraphicsComponent.StartAnimation("SlimeJumpLeftBottom"); + } + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5)); + if (getCols.Count > 0) + { + isJumping = false; + isDown = false; + } + } + + } + else if (!isGoRight && isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightTop") + { + GraphicsComponent.StartAnimation("SlimeReadyJumpRightTop"); + } + delay--; + if (delay <= 0) + { + velocity = new Vector2(-5, -3); + if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") + { + GraphicsComponent.StartAnimation("SlimeJumpRightTop"); + } + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5)); + if (getCols.Count > 0) + { + isJumping = false; + isDown = false; + } + } + } + else if (isGoRight && !isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpLeftTop") + { + GraphicsComponent.StartAnimation("SlimeReadyJumpLeftTop"); + + } + delay--; + if (delay <= 0) + { + isJumping = true; + velocity = new Vector2(5, 3); + if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftTop") + { + GraphicsComponent.StartAnimation("SlimeJumpLeftTop"); + } + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); + if (getCols.Count > 0) + { + isJumping = false; + isDown = true; + } + } + + } + else if (!isGoRight && !isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightTop") + { + GraphicsComponent.StartAnimation("SlimeReadyJumpRightTop"); + } + delay--; + if (delay <= 0) + { + velocity = new Vector2(-5, 3); + if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") + { + GraphicsComponent.StartAnimation("SlimeJumpRightTop"); + } + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); + if (getCols.Count > 0) + { + isJumping = false; + isDown = true; + } + } + + + } + + } + public override void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5), Color.White); + spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5), Color.White); + base.Draw(spriteBatch); + } public override void Death() { @@ -32,7 +156,82 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { + float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; + delay = 30; + Height = 16; + if (isGoRight && isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeMoveRightBottom") + { + GraphicsComponent.StartAnimation("SlimeMoveRightBottom"); + } + velocity.X = monster_speed; + } + + else if (!isGoRight && isDown) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeMoveLeftBottom") + { + GraphicsComponent.StartAnimation("SlimeMoveLeftBottom"); + } + velocity.X = -monster_speed; + + } + else if (!isDown && isGoRight) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeMoveRightTop") + { + GraphicsComponent.StartAnimation("SlimeMoveRightTop"); + + } + velocity.X = monster_speed; + + + } + else if (!isDown && !isGoRight) + { + if (GraphicsComponent.GetCurrentAnimation != "SlimeMoveLeftTop") + { + GraphicsComponent.StartAnimation("SlimeMoveLeftTop"); + } + velocity.X = -monster_speed; + + } + + if (Pos.X >= rightBorder) + { + isGoRight = false; + } + + else if (Pos.X <= leftBorder) + { + isGoRight = true; + } + } + public override void Update(GameTime gameTime) + { + + if (isDown) + { + + if (acceleration.Y < 0) + { + acceleration.Y = -acceleration.Y; + } + } + else + { + + if (acceleration.Y > 0) + { + acceleration.Y = -acceleration.Y; + } + } + //if (!isAttaking){ Move(gameTime); } + + + base.Update(gameTime); } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index b841dbd..7302e72 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -23,7 +23,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { Width = 24; Height = 40; - monster_speed = 1; + monster_speed = 3; name = "Zombie"; leftBorder = (int)position.X - 100; rightBorder = (int)position.X + 100; diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index f800998..3379b3c 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -64,7 +64,6 @@ namespace DangerousD.GameCore protected override void Initialize() { - GameManager.Initialize(); AnimationBuilder.LoadAnimations(); MenuGUI.Initialize(); LoginGUI.Initialize(); diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 0dfe139..f0ab19f 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -14,6 +14,7 @@ namespace DangerousD.GameCore public class GameManager { public List GetAllGameObjects { get; private set; } + public List livingEntities; public List entities; public List mapObjects; @@ -35,20 +36,16 @@ namespace DangerousD.GameCore players = new List(); mapManager = new MapManager(1); physicsManager = new PhysicsManager(); + } - public void Initialize() - { - //mapManager.LoadLevel("Level1"); - } - - public void LoadContent() - { - } + internal void Register(GameObject gameObject) { - //GetAllGameObjects.Add(gameObject); + + + GetAllGameObjects.Add(gameObject); if (gameObject is Player objPl) { livingEntities.Add(gameObject as LivingEntity); diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 3fdac52..c89d9c1 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -43,12 +43,12 @@ namespace DangerousD.GameCore.Managers currentEntity = livingEntities[i]; oldRect = currentEntity.Rectangle; bool isXNormalise = true; - bool isYNormalise = true; + bool isYNormalise = true; oldRect.Offset((int)currentEntity.velocity.X, 0); for (int j = 0; j < mapObjects.Count; j++) { - if (Math.Abs(mapObjects[i].Pos.X - currentEntity.Pos.X)< currentEntity.velocity.X*2 && Math.Abs(mapObjects[i].Pos.Y - currentEntity.Pos.Y) < 50) + if (Math.Abs(mapObjects[i].Pos.X - currentEntity.Pos.X) < currentEntity.velocity.X * 2 && Math.Abs(mapObjects[i].Pos.Y - currentEntity.Pos.Y) < 50) { if (oldRect.Intersects(mapObjects[j].Rectangle)) { @@ -213,5 +213,20 @@ namespace DangerousD.GameCore.Managers } return intersected; } + public List CheckRectangle(Rectangle rectangle) + { + var gameObjects = AppManager.Instance.GameManager.mapObjects; + List intersected = new List(); + for (int i = 0; i < gameObjects.Count; i++) + { + + if (gameObjects[i].Rectangle.Intersects(rectangle) && gameObjects[i].IsColliderOn) + { + intersected.Add(gameObjects[i]); + } + + } + return intersected; + } } } \ No newline at end of file