diff --git a/DangerousD/Content/animations/GibsMoveLeftBottom b/DangerousD/Content/animations/GibsMoveLeftBottom
new file mode 100644
index 0000000..b0f96f0
--- /dev/null
+++ b/DangerousD/Content/animations/GibsMoveLeftBottom
@@ -0,0 +1 @@
+{"id":"GibsMoveLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":70,"Y":724,"Width":14,"Height":11},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/GibsMoveLeftTop b/DangerousD/Content/animations/GibsMoveLeftTop
new file mode 100644
index 0000000..e80c714
--- /dev/null
+++ b/DangerousD/Content/animations/GibsMoveLeftTop
@@ -0,0 +1 @@
+{"id":"GibsMoveLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":2,"Y":721,"Width":14,"Height":12},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/GibsMoveRightBottom b/DangerousD/Content/animations/GibsMoveRightBottom
new file mode 100644
index 0000000..246ab34
--- /dev/null
+++ b/DangerousD/Content/animations/GibsMoveRightBottom
@@ -0,0 +1 @@
+{"id":"GibsMoveRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":106,"Y":722,"Width":13,"Height":12},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/GibsMoveRightTop b/DangerousD/Content/animations/GibsMoveRightTop
new file mode 100644
index 0000000..4b193fd
--- /dev/null
+++ b/DangerousD/Content/animations/GibsMoveRightTop
@@ -0,0 +1 @@
+{"id":"GibsMoveRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":37,"Y":721,"Width":14,"Height":13},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/GibsNotMove b/DangerousD/Content/animations/GibsNotMove
new file mode 100644
index 0000000..e5333b8
--- /dev/null
+++ b/DangerousD/Content/animations/GibsNotMove
@@ -0,0 +1 @@
+{"id":"GibsNotMove","textureName":"MonstersAnimations","startSpriteRectangle":{"X":137,"Y":731,"Width":16,"Height":5},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"}
diff --git a/DangerousD/Content/lvl.tmx b/DangerousD/Content/lvl.tmx
index 5377e12..0f91aa8 100644
--- a/DangerousD/Content/lvl.tmx
+++ b/DangerousD/Content/lvl.tmx
@@ -752,7 +752,7 @@
-
diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx
new file mode 100644
index 0000000..813425e
--- /dev/null
+++ b/DangerousD/Content/map.tmx
@@ -0,0 +1,75 @@
+
+
diff --git a/DangerousD/GameCore/GUI/HUD.cs b/DangerousD/GameCore/GUI/HUD.cs
index 07e446a..ee17186 100644
--- a/DangerousD/GameCore/GUI/HUD.cs
+++ b/DangerousD/GameCore/GUI/HUD.cs
@@ -11,7 +11,6 @@ namespace DangerousD.GameCore.GUI
{
public class HUD : AbstractGui
{
- int ammout = 0;
List rects = new List { };
int wigth = AppManager.Instance.inGameResolution.X;
int height = AppManager.Instance.inGameResolution.Y;
@@ -27,9 +26,8 @@ namespace DangerousD.GameCore.GUI
}
public override void Update(GameTime gameTime)
{
-
rects.Clear();
- for (int i = 0; i < ammout; i++)
+ for (int i = 0; i < AppManager.Instance.GameManager.GetPlayer1.Bullets; i++)
{
rects.Add(new Rect(Manager) { rectangle = new Rectangle(wigth / 29 + i * 13, height / 17, 5, 20), mainColor = Color.Yellow });
rects[i].LoadTexture(AppManager.Instance.Content);
diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs
index ceb5e5a..65bf8c9 100644
--- a/DangerousD/GameCore/GameObjects/GameObject.cs
+++ b/DangerousD/GameCore/GameObjects/GameObject.cs
@@ -15,6 +15,7 @@ namespace DangerousD.GameCore
protected Vector2 _pos;
public Vector2 Pos => _pos;
public int id;
+ public bool isIdFromHost = false;
public int Width { get; set; }
public int Height { get; set; }
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
index 188dfb9..82dcc2a 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
@@ -78,7 +78,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death()
{
+ for (int i = 0; i < 3; i++)
+ {
+ Particle particle = new Particle(Pos);
+ }
+
AppManager.Instance.GameManager.Remove(this);
+
}
public override void Move(GameTime gameTime)
@@ -160,6 +166,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
monster_health--;
GraphicsComponent.StartAnimation("ZombieRightAttack");
+ Particle particle = new Particle(Pos);
if (monster_health <= 0)
{
Death();
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs
new file mode 100644
index 0000000..cf08319
--- /dev/null
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs
@@ -0,0 +1,46 @@
+using DangerousD.GameCore.Graphics;
+using Microsoft.Xna.Framework;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DangerousD.GameCore.GameObjects.LivingEntities
+{
+ public class Particle : LivingEntity
+ {
+ int delay;
+ public Particle(Vector2 position) : base(position)
+ {
+ Width = 14;
+ Height = 14;
+ Random random = new Random();
+ velocity = new Vector2(random.Next(3, 15), random.Next(3,30));
+ acceleration.Y = 10;
+ delay = 100;
+
+ }
+
+ protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GibsMoveLeftBottom", "GibsMoveLeftTop", "GibsMoveRightBottom", "GibsMoveRightTop" }, "GibsMoveRightTop");
+ public override void Update(GameTime gameTime)
+ {
+ delay--;
+ if (velocity.X > 0)
+ {
+ velocity.X--;
+ }
+ if(velocity.Y<=0)
+ {
+ GraphicsComponent.StartAnimation("GipsNoMove");
+; }
+ if(delay<=0)
+ {
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ base.Update(gameTime);
+ }
+
+ }
+}
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
index 60eaf05..455a92b 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
@@ -32,16 +32,23 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
private int bullets;
public bool FallingThroughPlatform = false;
- public Player(Vector2 position) : base(position)
+
+
+
+ public int Bullets { get { return bullets; } }
+
+ public Player(Vector2 position, bool isNetworkPlayer = false) : base(position)
+
{
Width = 16;
Height = 32;
- AppManager.Instance.InputManager.ShootEvent += Shoot;
-
- AppManager.Instance.InputManager.MovEventJump += Jump;
- AppManager.Instance.InputManager.MovEventDown += MoveDown;
- AppManager.Instance.InputManager.ShootEvent += Shoot;
+ if (!isNetworkPlayer)
+ {
+ AppManager.Instance.InputManager.ShootEvent += Shoot;
+ AppManager.Instance.InputManager.MovEventJump += Jump;
+ AppManager.Instance.InputManager.MovEventDown += MoveDown;
+ }
velocity = new Vector2(0, 0);
rightBorder = (int)position.X + 100;
@@ -61,11 +68,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
};
}
- public Player(Vector2 position, bool isInvincible) : this(position)
- {
- this.isInvincible = isInvincible;
- }
-
public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",
diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs
index f218ba6..00d6298 100644
--- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs
+++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework;
+using DangerousD.GameCore.Managers;
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -16,7 +17,7 @@ namespace DangerousD.GameCore.Graphics
private List textures;
private List texturesNames;
private AnimationContainer currentAnimation;
- static private int scaling=3;
+ static private int scaling = 4;
public AnimationContainer CurrentAnimation
{
get
@@ -129,12 +130,12 @@ namespace DangerousD.GameCore.Graphics
{
if (!currentAnimation.IsCycle)
{
- if(actionOfAnimationEnd != null)
+ if (actionOfAnimationEnd != null)
{
actionOfAnimationEnd(currentAnimation.Id);
- }
+ }
currentAnimation = neitralAnimation;
-
+
}
currentFrame = 0;
@@ -152,12 +153,12 @@ namespace DangerousD.GameCore.Graphics
{
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
float scale;
- if (currentAnimation.Offset.X!=0)
+ if (currentAnimation.Offset.X != 0)
{
destinationRectangle.X -= (int)currentAnimation.Offset.X;
- scale=destinationRectangle.Height/sourceRectangle.Height;
+ scale = destinationRectangle.Height / sourceRectangle.Height;
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
-
+
}
else if (currentAnimation.Offset.Y != 0)
{
@@ -235,9 +236,26 @@ namespace DangerousD.GameCore.Graphics
}
public static void SetCameraPosition(Vector2 playerPosition)
{
- CameraPosition=(playerPosition).ToPoint();
+ CameraPosition = (playerPosition).ToPoint();
CameraPosition.X -= 300;
CameraPosition.Y -= 200;
+ if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X)
+ {
+ CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X;
+ }
+ if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460)
+ {
+ CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460;
+ }
+ if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z)
+ {
+ CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z;
+ }
+ if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 470)
+ {
+ CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 470;
+ }
+ AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}");
}
public static Point CameraPosition = new Point(-700, 300);
}
diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs
index 84d6b07..33327c7 100644
--- a/DangerousD/GameCore/Managers/AppManager.cs
+++ b/DangerousD/GameCore/Managers/AppManager.cs
@@ -12,6 +12,7 @@ using MonogameLibrary.UI.Base;
using DangerousD.GameCore.Managers;
using DangerousD.GameCore.GameObjects.LivingEntities;
using DangerousD.GameCore.GameObjects;
+using System.Threading.Tasks;
namespace DangerousD.GameCore
{
@@ -111,6 +112,8 @@ namespace DangerousD.GameCore
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
+ if (GameManager.GetPlayer1 != null)
+ DebugHUD.Set("Objid: ", GameManager.GetPlayer1.id.ToString());
InputManager.Update();
SoundManager.Update();
@@ -203,6 +206,7 @@ namespace DangerousD.GameCore
break;
case GameState.Game:
GameManager.mapManager.LoadLevel("lvl");
+ GameManager.FindBorders();
break;
case GameState.Death:
break;
@@ -225,24 +229,41 @@ namespace DangerousD.GameCore
case NetworkTaskOperationEnum.CreateEntity:
break;
case NetworkTaskOperationEnum.SendPosition:
- LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
- entity.SetPosition(networkTask.position);
+ if (networkTask.objId != GameManager.GetPlayer1.id)
+ {
+ LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
+ entity.SetPosition(networkTask.position);
+ if (multiPlayerStatus == MultiPlayerStatus.Host)
+ {
+ NetworkTasks.Add(networkTask);
+ }
+ }
break;
case NetworkTaskOperationEnum.ChangeState:
break;
case NetworkTaskOperationEnum.ConnectToHost:
- Player connectedPlayer = new Player(Vector2.Zero);
+ Player connectedPlayer = new Player(Vector2.Zero, true);
NetworkTasks.Add(new NetworkTask(connectedPlayer.id));
NetworkTask task = new NetworkTask();
- NetworkTasks.Add(task.AddConnectedPlayer(GameManager.GetPlayer1.id, GameManager.GetPlayer1.Pos));
+ foreach (Player player in GameManager.players)
+ {
+ if (player.id != connectedPlayer.id)
+ {
+ NetworkTasks.Add(task.AddConnectedPlayer(player.id, player.Pos));
+ }
+ }
break;
case NetworkTaskOperationEnum.GetClientPlayerId:
- GameManager.GetPlayer1.id = networkTask.objId;
+ if (!GameManager.GetPlayer1.isIdFromHost)
+ {
+ GameManager.GetPlayer1.id = networkTask.objId;
+ GameManager.GetPlayer1.isIdFromHost = true;
+ }
break;
case NetworkTaskOperationEnum.AddConnectedPlayer:
- Player remoteConnectedPlayer = new Player(networkTask.position);
+ Player remoteConnectedPlayer = new Player(networkTask.position, true);
remoteConnectedPlayer.id = networkTask.objId;
- GameManager.players.Add(remoteConnectedPlayer);
+
break;
default:
break;
diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs
index 6b3c2b4..53ffa61 100644
--- a/DangerousD/GameCore/Managers/GameManager.cs
+++ b/DangerousD/GameCore/Managers/GameManager.cs
@@ -28,7 +28,7 @@ namespace DangerousD.GameCore
public PhysicsManager physicsManager;
public List players;
public List otherObjects = new();
-
+ public Vector4 CameraBorder;
public Player GetPlayer1 { get; private set; }
public GameManager()
{
@@ -42,6 +42,7 @@ namespace DangerousD.GameCore
players = new List();
mapManager = new MapManager(1);
physicsManager = new PhysicsManager();
+ CameraBorder = Vector4.Zero;
}
@@ -129,7 +130,6 @@ namespace DangerousD.GameCore
public void Update(GameTime gameTime)
{
- AppManager.Instance.DebugHUD.Set("playerId: ", GetPlayer1.id.ToString());
if (AppManager.Instance.NetworkTasks.Count > 0)
{
AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList());
@@ -147,15 +147,15 @@ namespace DangerousD.GameCore
{
livingEntitiesWithoutPlayers[i].Update(gameTime);
}
- GetPlayer1.Update(gameTime);
}
else
+
+
{
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
{
livingEntitiesWithoutPlayers[i].PlayAnimation();
}
- GetPlayer1.Update(gameTime);
}
GetPlayer1.Update(gameTime);
foreach (var item in otherObjects)
@@ -163,5 +163,27 @@ namespace DangerousD.GameCore
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime);
}
+ public void FindBorders()
+ {
+ foreach (var item in GetAllGameObjects)
+ {
+ if (item.Pos.X CameraBorder.Y)
+ {
+ CameraBorder.Y = item.Pos.X;
+ }
+ if (item.Pos.Y < CameraBorder.Z)
+ {
+ CameraBorder.Z = item.Pos.X;
+ }
+ if (item.Pos.Y > CameraBorder.W)
+ {
+ CameraBorder.W = item.Pos.X;
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs
index fd23e3c..6ab49b0 100644
--- a/DangerousD/GameCore/Managers/MapManager.cs
+++ b/DangerousD/GameCore/Managers/MapManager.cs
@@ -98,9 +98,9 @@ namespace DangerousD.GameCore.Managers
new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX,
float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale;
Entity inst;
- if (type.Equals(typeof(Player)) && entity.Attributes["name"] is not null && entity.Attributes["name"].Value == "DEBUGUS")
+ if (type.Equals(typeof(Player)))
{
- inst = (Entity)Activator.CreateInstance(type, pos, true);
+ inst = (Entity)Activator.CreateInstance(type, pos, false);
}
else
{
diff --git a/DangerousD/GameCore/Network/NetworkManager.cs b/DangerousD/GameCore/Network/NetworkManager.cs
index 292e210..56ac3a1 100644
--- a/DangerousD/GameCore/Network/NetworkManager.cs
+++ b/DangerousD/GameCore/Network/NetworkManager.cs
@@ -91,7 +91,7 @@ namespace DangerousD.GameCore.Network
}
catch { }
}
- public void SendMsg(List networkTask)
+ public void SendMsg(List networkTask, Socket ignoreSocket = null)
{
byte[] Data = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(networkTask));
int count = Data.Length;
@@ -101,8 +101,11 @@ namespace DangerousD.GameCore.Network
{
foreach (Socket socket in clientSockets)
{
- socket.Send(BitConverter.GetBytes(count));
- socket.Send(Data);
+ if (!(socket == ignoreSocket))
+ {
+ socket.Send(BitConverter.GetBytes(count));
+ socket.Send(Data);
+ }
}
}
catch { }
@@ -148,7 +151,8 @@ namespace DangerousD.GameCore.Network
}
else
{
- GetReceivingMessages(JsonConvert.DeserializeObject>(so.sb.ToString()));
+ List tasks = JsonConvert.DeserializeObject>(so.sb.ToString());
+ GetReceivingMessages(tasks);
}
}
catch { }