diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index 9924833..123c029 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -81,11 +81,12 @@ /processorParam:TextureFormat=Color /build:deathBackground.jpg + #begin DoomTestSong.mp3 /importer:Mp3Importer /processor:SoundEffectProcessor /processorParam:Quality=Best -/build:DoomTestSong.mp3 +/build:sounds/DoomTestSong.mp3 #begin doors.png /importer:TextureImporter @@ -235,6 +236,18 @@ /processorParam:TextureFormat=Color /build:sliderBackground.png +#begin sounds/DoomTestSong.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:sounds/DoomTestSong.mp3 + +#begin sounds/shotgun_shot.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:sounds/shotgun_shot.mp3 + #begin textboxbackground1-1.png /importer:TextureImporter /processor:TextureProcessor diff --git a/DangerousD/Content/animations/playerShootLeft b/DangerousD/Content/animations/playerShootLeft index f2b9f3b..e710737 100644 --- a/DangerousD/Content/animations/playerShootLeft +++ b/DangerousD/Content/animations/playerShootLeft @@ -1 +1,24 @@ -{"id":"playerShootLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":34,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} +{ + "id": "playerShootLeft", + "textureName": "playerAnimation", + "startSpriteRectangle": { + "X": 201, + "Y": 34, + "Width": 32, + "Height": 32 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 3 + }, + { + "Item1": 1, + "Item2": 20 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": false, + "offset": "4, 0" +} diff --git a/DangerousD/Content/animations/playerShootRight b/DangerousD/Content/animations/playerShootRight index 922862b..3b7ef81 100644 --- a/DangerousD/Content/animations/playerShootRight +++ b/DangerousD/Content/animations/playerShootRight @@ -1 +1,24 @@ -{"id":"playerShootRight","textureName":"playerAnimation","startSpriteRectangle":{"X":201,"Y":1,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"4, 0"} +{ + "id": "playerShootRight", + "textureName": "playerAnimation", + "startSpriteRectangle": { + "X": 201, + "Y": 1, + "Width": 32, + "Height": 32 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 3 + }, + { + "Item1": 1, + "Item2": 20 + } + ], + "textureFrameInterval": 1, + "framesCount": 2, + "isCycle": false, + "offset": "4, 0" +} diff --git a/DangerousD/Content/DoomTestSong.mp3 b/DangerousD/Content/sounds/DoomTestSong.mp3 similarity index 100% rename from DangerousD/Content/DoomTestSong.mp3 rename to DangerousD/Content/sounds/DoomTestSong.mp3 diff --git a/DangerousD/Content/sounds/shotgun_shot.mp3 b/DangerousD/Content/sounds/shotgun_shot.mp3 new file mode 100644 index 0000000..56a4a56 Binary files /dev/null and b/DangerousD/Content/sounds/shotgun_shot.mp3 differ diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index a583904..8526427 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -30,6 +30,7 @@ namespace DangerousD.GameCore LoadContent(); AppManager.Instance.GameManager.Register(this); + GraphicsComponent.parentId = id; } public virtual void OnCollision(GameObject gameObject) @@ -68,5 +69,9 @@ namespace DangerousD.GameCore } } + public GraphicsComponent GetGraphicsComponent() + { + return this.GraphicsComponent; + } } } \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 272f332..ed9119d 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -31,14 +31,17 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities private int bullets; public bool FallingThroughPlatform = false; public bool isUping = false; + public bool isNetworkPlayer; + + - public int Bullets { get { return bullets; } } public Player(Vector2 position, bool isNetworkPlayer = false) : base(position) { + this.isNetworkPlayer = isNetworkPlayer; Width = 16; Height = 32; @@ -47,24 +50,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities 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; + leftBorder = (int)position.X - 100; + bullets = 5; + + this.GraphicsComponent.actionOfAnimationEnd += (a) => + { + if (a == "playerShootLeft" || a == "playerShootRight") + { + isShooting = false; + } + if (a == "playerReload") + { + bullets++; + } + }; } - velocity = new Vector2(0, 0); - rightBorder = (int)position.X + 100; - leftBorder = (int)position.X - 100; - bullets = 5; - - this.GraphicsComponent.actionOfAnimationEnd += (a) => - { - if (a == "playerShootLeft" || a == "playerShootRight") - { - isShooting = false; - } - if (a == "playerReload") - { - bullets++; - } - }; } public bool IsAlive { get { return isAlive; } } @@ -136,6 +139,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities { if (!isShooting) { + AppManager.Instance.SoundManager.StartSound("shotgun_shot", Pos, Pos); isShooting = true; bullets--; if (isRight) @@ -251,6 +255,5 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities FallingThroughPlatform = true; isOnGround = false; } - } } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 5a659c8..27eeea8 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -1,4 +1,5 @@ using DangerousD.GameCore.Managers; +using DangerousD.GameCore.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -18,6 +19,7 @@ namespace DangerousD.GameCore.Graphics private List texturesNames; private AnimationContainer currentAnimation; static private int scaling = 4; + public int parentId; public AnimationContainer CurrentAnimation { get @@ -105,6 +107,14 @@ namespace DangerousD.GameCore.Graphics public void StartAnimation(string startedanimationId) { + if (startedanimationId == "playerShootRight" && parentId == 17) + { + string a = "2"; + } + if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer && startedanimationId != GetCurrentAnimation) + { + AppManager.Instance.NetworkTasks.Add(new NetworkTask(parentId, startedanimationId, Vector2.Zero)); + } currentFrame = 0; currentAnimation = animations.Find(x => x.Id == startedanimationId); diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 33327c7..81a43d0 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -111,9 +111,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()); + if (GameManager.GetPlayer1 != null) + DebugHUD.Set("id: ", GameManager.GetPlayer1.id.ToString()); InputManager.Update(); SoundManager.Update(); @@ -229,10 +228,11 @@ namespace DangerousD.GameCore case NetworkTaskOperationEnum.CreateEntity: break; case NetworkTaskOperationEnum.SendPosition: - if (networkTask.objId != GameManager.GetPlayer1.id) + if (networkTask.objId != GameManager.GetPlayer1.id ) { LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId); - entity.SetPosition(networkTask.position); + if (entity != null) + entity.SetPosition(networkTask.position); if (multiPlayerStatus == MultiPlayerStatus.Host) { NetworkTasks.Add(networkTask); @@ -240,6 +240,20 @@ namespace DangerousD.GameCore } break; case NetworkTaskOperationEnum.ChangeState: + if (networkTask.objId != GameManager.GetPlayer1.id) + { + List gcs = new List(); + foreach (var player in GameManager.players) + { + gcs.Add(player.GetGraphicsComponent()); + } + LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId); + if (entity != null) + { + GraphicsComponent gc = entity.GetGraphicsComponent(); + gc.StartAnimation(networkTask.name); + } + } break; case NetworkTaskOperationEnum.ConnectToHost: Player connectedPlayer = new Player(Vector2.Zero, true); @@ -257,15 +271,17 @@ namespace DangerousD.GameCore if (!GameManager.GetPlayer1.isIdFromHost) { GameManager.GetPlayer1.id = networkTask.objId; + GraphicsComponent gcsd = GameManager.GetPlayer1.GetGraphicsComponent(); + gcsd.parentId = networkTask.objId; GameManager.GetPlayer1.isIdFromHost = true; } break; case NetworkTaskOperationEnum.AddConnectedPlayer: Player remoteConnectedPlayer = new Player(networkTask.position, true); remoteConnectedPlayer.id = networkTask.objId; - + remoteConnectedPlayer.GetGraphicsComponent().parentId = networkTask.objId; break; - default: + default: break; } } diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index d7ed9ab..d6ba67f 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -150,14 +150,21 @@ namespace DangerousD.GameCore } else - { for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++) { livingEntitiesWithoutPlayers[i].PlayAnimation(); } } + foreach (Player player in players) + { + if (player.id != GetPlayer1.id) + { + player.PlayAnimation(); + } + } GetPlayer1.Update(gameTime); + foreach (var item in otherObjects) item.Update(gameTime); diff --git a/DangerousD/GameCore/Managers/SoundManager.cs b/DangerousD/GameCore/Managers/SoundManager.cs index ab9a5d8..70352c4 100644 --- a/DangerousD/GameCore/Managers/SoundManager.cs +++ b/DangerousD/GameCore/Managers/SoundManager.cs @@ -19,7 +19,7 @@ namespace DangerousD.GameCore public void LoadSounds() // метод для загрузки звуков из папки { - var k = Directory.GetFiles("../../..//Content").Where(x => x.EndsWith("mp3")); + var k = Directory.GetFiles("../../..//Content//sounds").Where(x => x.EndsWith("mp3")); if (k.Count() > 0) { @@ -27,7 +27,7 @@ namespace DangerousD.GameCore string[] soundFiles = k.Select(x => x.Split("\\").Last().Split("/").Last().Replace(".mp3", "")).ToArray();// папка со звуками там где exe foreach (var soundFile in soundFiles) { - Sounds.Add(soundFile, AppManager.Instance.Content.Load(soundFile).CreateInstance()); + Sounds.Add(soundFile, AppManager.Instance.Content.Load("sounds//" + soundFile).CreateInstance()); } } @@ -53,7 +53,7 @@ namespace DangerousD.GameCore { var sound = new Sound(Sounds[soundName], soundPos); sound.SoundEffect.IsLooped = false; - sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; + sound.SoundEffect.Volume = (float)(MaxSoundDistance-sound.GetDistance(playerPos)) / MaxSoundDistance; sound.SoundEffect.Play(); PlayingSounds.Add(sound); if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Host) @@ -79,7 +79,7 @@ namespace DangerousD.GameCore for (int i = 0; i < PlayingSounds.Count; i++) { if (!PlayingSounds[i].isAmbient) - PlayingSounds[i].SoundEffect.Volume = (float)PlayingSounds[i].GetDistance(player.Pos) / MaxSoundDistance; + PlayingSounds[i].SoundEffect.Volume = (float)(MaxSoundDistance - PlayingSounds[i].GetDistance(player.Pos)) / MaxSoundDistance; if (PlayingSounds[i].SoundEffect.State == SoundState.Stopped) PlayingSounds.Remove(PlayingSounds[i]); }