diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index bda2baf..9a712a0 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -5,6 +5,7 @@ using System; using System.Windows.Forms; using System.IO; using System.Linq; +using System.Reflection.Metadata; namespace AnimationsFileCreator { @@ -62,7 +63,7 @@ namespace AnimationsFileCreator container.TextureFrameInterval = 1; container.Id = id; string json = JsonConvert.SerializeObject(container); - StreamWriter writer = new StreamWriter("../../../../DangerousD/Content/animations/" + id); + StreamWriter writer = new StreamWriter("../../../../DangerousD/Content/animations/"+id); writer.WriteLine(json); writer.Close(); } diff --git a/DangerousD/Content/animations/SilasAttack b/DangerousD/Content/animations/SilasAttack new file mode 100644 index 0000000..4727523 --- /dev/null +++ b/DangerousD/Content/animations/SilasAttack @@ -0,0 +1,20 @@ +{ + "id": "SilasAttack", + "textureName": "MonstersAnimations", + "startSpriteRectangle": { + "X": 1, + "Y": 618, + "Width": 72, + "Height": 80 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 5 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": true, + "offset": "0, 0" +} diff --git a/DangerousD/Content/animations/SilasHandMove b/DangerousD/Content/animations/SilasHandMove new file mode 100644 index 0000000..06589c3 --- /dev/null +++ b/DangerousD/Content/animations/SilasHandMove @@ -0,0 +1 @@ +{"id":"SilasHandMove","textureName":"MonstersAnimations","startSpriteRectangle":{"X":197,"Y":618,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SilasMove b/DangerousD/Content/animations/SilasMove new file mode 100644 index 0000000..334d3c5 --- /dev/null +++ b/DangerousD/Content/animations/SilasMove @@ -0,0 +1,20 @@ +{ + "id": "SilasMove", + "textureName": "MonstersAnimations", + "startSpriteRectangle": { + "X": 1, + "Y": 618, + "Width": 72, + "Height": 80 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 60 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": true, + "offset": "0, 0" +} diff --git a/DangerousD/GameCore/GUI/LobbyGUI.cs b/DangerousD/GameCore/GUI/LobbyGUI.cs index f782750..2927758 100644 --- a/DangerousD/GameCore/GUI/LobbyGUI.cs +++ b/DangerousD/GameCore/GUI/LobbyGUI.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using DangerousD.GameCore.Managers; using MonogameLibrary.UI.Base; using System.Diagnostics; +using DangerousD.GameCore.Network; namespace DangerousD.GameCore.GUI { @@ -32,8 +33,32 @@ namespace DangerousD.GameCore.GUI Elements.Add(new Label(Manager) { rectangle = new Rectangle(screenWidth / 30 * 2, screenHeight / 30 * 5, screenWidth / 30 * 26, screenHeight / 15 * 10) }); - // Buttons + // Buttons and ip textbox { + TextBox searchBarTextBox = new TextBox(Manager) + { + rectangle = new Rectangle(screenWidth / 30 * 14, screenHeight / 30, + screenWidth / 30 * 10, screenHeight / 30 * 3), + text = "ip", + scale = 0.16f, + fontColor = Color.Gray, + fontName = "font2", + textAligment = TextAligment.Left + + }; + searchBarTextBox.TextChanged += input => { + if (searchBarTextBox.fontColor == Color.Gray) + { + searchBarTextBox.text = ""; searchBarTextBox.fontColor = Color.Black; + } + }; + searchBarTextBox.StopChanging += input => { + if (input.Length == 0) + { + searchBarTextBox.fontColor = Color.Gray; + searchBarTextBox.text = "ip"; + } + }; Button backButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30, screenHeight / 30, 60, 50), @@ -55,7 +80,9 @@ namespace DangerousD.GameCore.GUI fontName = "font2" }; hostButton.LeftButtonPressed += () => { - + + AppManager.Instance.NetworkManager.HostInit(AppManager.Instance.IpAddress); + }; Button refreshButton = new ButtonText(Manager) @@ -79,7 +106,7 @@ namespace DangerousD.GameCore.GUI fontName = "font2" }; joinSelectedButton.LeftButtonPressed += () => { - + AppManager.Instance.NetworkManager.ClientInit(AppManager.Instance.IpAddress); }; Button joinByIpButton = new ButtonText(Manager) { @@ -90,34 +117,7 @@ namespace DangerousD.GameCore.GUI fontName = "font2" }; joinByIpButton.LeftButtonPressed += () => { - - }; - } - - // SearchBar - { - TextBox searchBarTextBox = new TextBox(Manager) { - rectangle = new Rectangle(screenWidth / 30 * 14, screenHeight / 30, - screenWidth / 30 * 10, screenHeight / 30 * 3), - text = "ip", - scale = 0.16f, - fontColor = Color.Gray, - fontName = "font2", - textAligment = TextAligment.Left - - }; - searchBarTextBox.TextChanged += input => { - if (searchBarTextBox.fontColor == Color.Gray) - { - searchBarTextBox.text = ""; searchBarTextBox.fontColor = Color.Black; - } - }; - searchBarTextBox.StopChanging += input => { - if (input.Length == 0) - { - searchBarTextBox.fontColor = Color.Gray; - searchBarTextBox.text = "ip"; - } + AppManager.Instance.NetworkManager.ClientInit(searchBarTextBox.text); }; } } diff --git a/DangerousD/GameCore/GUI/MenuGUI.cs b/DangerousD/GameCore/GUI/MenuGUI.cs index f619d5f..b1ac08d 100644 --- a/DangerousD/GameCore/GUI/MenuGUI.cs +++ b/DangerousD/GameCore/GUI/MenuGUI.cs @@ -35,6 +35,7 @@ internal class MenuGUI : AbstractGui butSingle.LeftButtonPressed += () => { AppManager.Instance.ChangeGameState(GameState.Game); + AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.SinglePlayer); }; var butMulti = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 190, 300, 50), text = "Multiplayer", fontName = "ButtonFont" }; Elements.Add(butMulti); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs index 4fbe6ff..8950202 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs @@ -16,6 +16,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities protected int monster_speed; protected string name; protected bool isAlive = true; + protected bool isAttack; + protected int leftBoarder; + protected int rightBoarder; public CoreEnemy(Vector2 position) : base(position) { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs index 6c13e1b..cf33f30 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasHands.cs @@ -1,4 +1,8 @@ -using System; +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,60 @@ using System.Threading.Tasks; namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { - internal class SilasHands + public class SilasHands : CoreEnemy { + public SilasHands(Vector2 position) : base(position) + { + name = "SilasHand"; + Width = 48; + Height = 48; + monster_health = 2; + monster_speed = 2; + acceleration = Vector2.Zero; + + } + + protected override GraphicsComponent GraphicsComponent { get; }=new GraphicsComponent(new List() { "SilasHandMove" }, "SilasHandMove"); + + public override void Attack() + { + throw new NotImplementedException(); + } + + public override void Death() + { + throw new NotImplementedException(); + } + + public override void Move(GameTime gameTime) + { + if (Pos.Y> AppManager.Instance.GameManager.GetPlayer1.Pos.Y) + { + velocity.Y = monster_speed; + + } + else + { + velocity.Y = 0; + } + if (Pos.X> AppManager.Instance.GameManager.GetPlayer1.Pos.X) + { + velocity.X = -monster_speed; + } + else + { + velocity.X = monster_speed; + } + } + public override void Update(GameTime gameTime) + { + base.Update(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(); + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs index 4a5d727..09a3928 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SilasMaster.cs @@ -1,4 +1,8 @@ -using System; +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,64 @@ using System.Threading.Tasks; namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { - public class SilasMaster + public class SilasMaster : CoreEnemy { + private int attackTime = 60; + private int moveTime = 360; + private int currentTime = 0; + public SilasMaster(Vector2 position) : base(position) + { + name = "SilasMaster"; + Width = 144; + Height = 160; + monster_health = 15; + monster_speed = 4; + acceleration = Vector2.Zero; + } + protected override GraphicsComponent GraphicsComponent { get; } = new GraphicsComponent(new List() { "SilasMove", "SilasAttack" }, "SilasMove"); + public override void Attack() + { + if (currentTime==0) + { + GraphicsComponent.StartAnimation("SilasAttack"); + } + else if (currentTime >= attackTime) + { + GraphicsComponent.StartAnimation("SilasMove"); + currentTime = 0; + } + currentTime++; + } + + public override void Death() + { + throw new NotImplementedException(); + } + + public override void Move(GameTime gameTime) + { + if (currentTime == 0) + { + GraphicsComponent.StartAnimation("SilasMove"); + } + else if (currentTime >= moveTime) + { + GraphicsComponent.StartAnimation("SilasAttack"); + currentTime = 0; + } + currentTime++; + } + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + if (GraphicsComponent.CurrentAnimation.Id=="SilasMove") + { + Move(gameTime); + } + else + { + Attack(); + } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs index a7c6173..91c2aa7 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs @@ -17,6 +17,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters protected int webLength; protected bool isDown; protected bool isDownUp; + public Spider(Vector2 position) : base(position) { isDownUp = true; diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs index 1ddaf45..1867b60 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs @@ -20,6 +20,9 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie"}, "DeathFromZombie"); + + public GraphicsComponent Gr => GraphicsComponent; + private void PlayDeath(string deathName) { if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie") diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 7f25a41..b194de9 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -16,10 +16,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { Width = 32; Height = 64; - /*GraphicsComponent.actionOfAnimationEnd += () => - { - AppManager.Instance.ChangeGameState(GameState.GameOver); - };*/ } public bool IsAlive { get { return isAlive; } } @@ -35,7 +31,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities if(monsterName == "Zombie") { DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); - //GraphicsComponent.actionOfAnimationEnd(); + deathRectangle.Gr.actionOfAnimationEnd += (a) => + { + if (a == "DeathFrom" + monsterName) + { + AppManager.Instance.ChangeGameState(GameState.GameOver); + } + }; } isAlive = false; } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 6c86077..beb6928 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -11,12 +11,19 @@ namespace DangerousD.GameCore.Graphics public class GraphicsComponent { - public Action actionOfAnimationEnd; + public event Action actionOfAnimationEnd; private List animations; private List textures; private List texturesNames; private AnimationContainer currentAnimation; - + public AnimationContainer CurrentAnimation + { + get + { + return currentAnimation; + } + } + public string LastAnimation { get; set; } public string GetCurrentAnimation { get { return currentAnimation.Id; } @@ -26,16 +33,21 @@ namespace DangerousD.GameCore.Graphics //private SpriteBatch _spriteBatch; private int currentFrame; + public int CurrentFrame + { + get + { + return currentFrame; + } + } private int interval; private int lastInterval; private Rectangle sourceRectangle; - public GraphicsComponent(List animationsId, string neitralAnimationId) { //this._spriteBatch = _spriteBatch; currentFrame = 0; lastInterval = 1; - LoadAnimations(animationsId, neitralAnimationId); currentAnimation = neitralAnimation; SetInterval(); diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index 341cd38..b60565b 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -11,15 +11,19 @@ namespace DangerousD.GameCore.Levels public void InitLevel() { new Player(new Vector2(80,0)); - //var Zombie = new Zombie(new Vector2(140, 128)); - var Frank = new Frank(new Vector2(384, 0)); + var Zombie = new Zombie(new Vector2(140, 128)); + var Frank = new Frank(new Vector2(384, 128)); var Spider = new Spider(new Vector2(112, 0)); var FlameSkull = new FlameSkull(new Vector2(512, 0)); var Werewolf = new Werewolf(new Vector2(640, 0)); var Ghost = new Ghost(new Vector2(730, 0)); + var Frank = new Frank(new Vector2(100, 64)); var FrankBalls = new FrankBalls(new Vector2(Frank.Pos.X, Frank.Pos.Y)); - + var Zombie = new Zombie(new Vector2(300, 64)); + + var SilasHand = new SilasHands(new Vector2(200,64)); + var SilasMaster = new SilasMaster(new Vector2(400, 64)); new GrassBlock(new Vector2(0, 224)); for (int i = 0; i < 50; i++) { diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index ab061b9..f0c8215 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -14,12 +14,15 @@ using DangerousD.GameCore.Managers; namespace DangerousD.GameCore { public enum GameState { Menu, Options, Lobby, Game, Login, GameOver } + public enum MultiPlayerStatus { SinglePlayer, Host, Client } public class AppManager : Game { - public static AppManager Instance { get; private set; } + public static AppManager Instance { get; private set; } + public string IpAddress { get; private set; } = "127.0.0.1"; private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; - GameState gameState; + private SpriteBatch _spriteBatch; + public GameState gameState { get; private set; } + public MultiPlayerStatus multiPlayerStatus { get; private set; } IDrawableObject MenuGUI; IDrawableObject OptionsGUI; IDrawableObject LoginGUI; @@ -45,6 +48,8 @@ namespace DangerousD.GameCore SettingsManager = new SettingsManager(); SettingsManager.LoadSettings(); + NetworkManager.GetReceivingMessages += NetworkSync; + resolution = SettingsManager.Resolution; _graphics.PreferredBackBufferWidth = resolution.X; _graphics.PreferredBackBufferHeight = resolution.Y; @@ -162,10 +167,39 @@ namespace DangerousD.GameCore case GameState.Game: GameManager.mapManager.LoadLevel(""); break; + case GameState.GameOver: + break; default: throw new ArgumentOutOfRangeException(); } } + public void NetworkSync(NetworkTask networkTask) + { + switch (networkTask.operation) + { + case NetworkTaskOperationEnum.TakeDamage: + break; + case NetworkTaskOperationEnum.SendSound: + // SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos); + break; + case NetworkTaskOperationEnum.CreateEntity: + break; + case NetworkTaskOperationEnum.SendPosition: + break; + case NetworkTaskOperationEnum.ChangeState: + break; + case NetworkTaskOperationEnum.ConnectToHost: + break; + case NetworkTaskOperationEnum.GetClientPlayerId: + break; + default: + break; + } + } + public void SetMultiplayerState(MultiPlayerStatus multiPlayerStatus) + { + this.multiPlayerStatus = multiPlayerStatus; + } } } diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 6cd702d..2784a84 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -12,7 +12,7 @@ namespace DangerousD.GameCore { public class GameManager { - + public List GetAllGameObjects { get; private set; } public List livingEntities; public List entities; public List mapObjects; diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index bae99da..a4598de 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -136,7 +136,7 @@ namespace DangerousD.GameCore.Managers Rectangle rectangle; Vector2 distance = entity1.Pos - entity2.Pos; - rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y, entity2.Width, entity2.Height); + rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y - 5, entity2.Width, entity2.Height); GameObject gameObject = null; double length = distance.Length(); @@ -144,32 +144,31 @@ namespace DangerousD.GameCore.Managers { rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X); rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y); + for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++) + { + if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.entities[i]; + } + } + for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++) + { + if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.mapObjects[i]; + } + } + for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++) + { + if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.livingEntities[i]; + } + } } - for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++) - { - if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.entities[i]; - } - } - for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++) - { - if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.mapObjects[i]; - } - } - - - for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++) - { - if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.livingEntities[i]; - } - } - return gameObject; + + return null; } public GameObject RayCast(LivingEntity entity1, Vector2 targetCast) { @@ -182,28 +181,29 @@ namespace DangerousD.GameCore.Managers { rectangle.X = (int)(targetCast.X + (i / k) * direction.X); rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X); + for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++) + { + if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.entities[i]; + } + } + for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++) + { + if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.mapObjects[i]; + } + } + for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++) + { + if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) + { + return AppManager.Instance.GameManager.livingEntities[i]; + } + } } - for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++) - { - if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.entities[i]; - } - } - for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++) - { - if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.mapObjects[i]; - } - } - for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++) - { - if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle)) - { - return AppManager.Instance.GameManager.livingEntities[i]; - } - } + return null; } public List CheckRectangle(Rectangle rectangle, Type type) diff --git a/DangerousD/GameCore/Managers/SoundManager.cs b/DangerousD/GameCore/Managers/SoundManager.cs index 9021fa8..2512192 100644 --- a/DangerousD/GameCore/Managers/SoundManager.cs +++ b/DangerousD/GameCore/Managers/SoundManager.cs @@ -33,8 +33,11 @@ namespace DangerousD.GameCore sound.SoundEffect.IsLooped = false; sound.SoundEffect.Play(); PlayingSounds.Add(sound); + if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.Host) + { + AppManager.Instance.NetworkManager.SendMsg(new Network.NetworkTask(Vector2.Zero, soundName)); + } } - public void StartSound(string soundName, Vector2 soundPos, Vector2 playerPos) // запустить звук у которого есть позиция { var sound = new Sound(Sounds[soundName], soundPos); @@ -42,6 +45,10 @@ namespace DangerousD.GameCore sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; sound.SoundEffect.Play(); PlayingSounds.Add(sound); + if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Host) + { + AppManager.Instance.NetworkManager.SendMsg(new Network.NetworkTask(soundPos, soundName)); + } } public void StopAllSounds() // остановка всех звуков { diff --git a/DangerousD/GameCore/Network/NetworkTask.cs b/DangerousD/GameCore/Network/NetworkTask.cs index a1fb999..1dbb508 100644 --- a/DangerousD/GameCore/Network/NetworkTask.cs +++ b/DangerousD/GameCore/Network/NetworkTask.cs @@ -13,6 +13,7 @@ namespace DangerousD.GameCore.Network public NetworkTaskOperationEnum operation { get; set; } public string name { get; set; } public int value { get; set; } + public bool isParam { get; set; } public int objId { get; set; } public Vector2 position { get; set; } public Vector2 velocity { get; set; } @@ -102,5 +103,28 @@ namespace DangerousD.GameCore.Network operation = NetworkTaskOperationEnum.GetClientPlayerId; objId = PlayerId; } + + /// + /// Универсальный конструктор для нестандартных операций. То, что не нужно(кроме операции) делать null. + /// + /// + /// + /// + /// + /// + /// + /// + /// + public NetworkTask(NetworkTaskOperationEnum operation, string name, int value, bool isParam, int objId, Vector2 position, Vector2 velocity, Type type) + { + this.operation = operation; + this.name = name; + this.value = value; + this.isParam = isParam; + this.objId = objId; + this.position = position; + this.velocity = velocity; + this.type = type; + } } }