diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index dc2bf5b..bda2baf 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -62,7 +62,7 @@ namespace AnimationsFileCreator container.TextureFrameInterval = 1; container.Id = id; string json = JsonConvert.SerializeObject(container); - StreamWriter writer = new StreamWriter(id); + StreamWriter writer = new StreamWriter("../../../../DangerousD/Content/animations/" + id); writer.WriteLine(json); writer.Close(); } diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index 05bebc6..6729fe5 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -14,7 +14,7 @@ #---------------------------------- Content ---------------------------------# -#begin animation1.png +#begin MonstersAnimations.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -24,7 +24,19 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:animation1.png +/build:MonstersAnimations.png + +#begin deathAnimation.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:deathAnimation.png #begin ButtonFont.spritefont /importer:FontDescriptionImporter @@ -33,6 +45,12 @@ /processorParam:TextureFormat=Compressed /build:ButtonFont.spritefont +#begin DoomTestSong.mp3 +/importer:Mp3Importer +/processor:SoundEffectProcessor +/processorParam:Quality=Best +/build:DoomTestSong.mp3 + #begin Font_25.spritefont /importer:FontDescriptionImporter /processor:FontDescriptionProcessor @@ -67,6 +85,7 @@ /build:menuFon.jpg #begin MonstersAnimations.png +#begin menuFon.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -76,9 +95,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:MonstersAnimations.png +/build:menuFon.jpg -#begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png +#begin MenuFon2.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -88,7 +107,19 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png +/build:MenuFon2.jpg + +#begin menuFon3.jpg +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:menuFon3.jpg #begin tiles.png /importer:TextureImporter diff --git a/DangerousD/Content/DoomTestSong.mp3 b/DangerousD/Content/DoomTestSong.mp3 new file mode 100644 index 0000000..91e2df8 Binary files /dev/null and b/DangerousD/Content/DoomTestSong.mp3 differ diff --git a/DangerousD/Content/MenuFon2.jpg b/DangerousD/Content/MenuFon2.jpg new file mode 100644 index 0000000..7e89ce8 Binary files /dev/null and b/DangerousD/Content/MenuFon2.jpg differ diff --git a/DangerousD/Content/animation1.png b/DangerousD/Content/animation1.png deleted file mode 100644 index a599347..0000000 Binary files a/DangerousD/Content/animation1.png and /dev/null differ diff --git a/DangerousD/Content/animations/BallMoveRight b/DangerousD/Content/animations/BallMoveRight new file mode 100644 index 0000000..fe03349 --- /dev/null +++ b/DangerousD/Content/animations/BallMoveRight @@ -0,0 +1 @@ +{"id":"BallMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":229,"Y":332,"Width":16,"Height":16},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/DeathFromZombie b/DangerousD/Content/animations/DeathFromZombie new file mode 100644 index 0000000..e6174de --- /dev/null +++ b/DangerousD/Content/animations/DeathFromZombie @@ -0,0 +1 @@ +{"id":"DeathFromZombie","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":99,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/FlameSkullMoveLeft b/DangerousD/Content/animations/FlameSkullMoveLeft new file mode 100644 index 0000000..8b2ffbd --- /dev/null +++ b/DangerousD/Content/animations/FlameSkullMoveLeft @@ -0,0 +1 @@ +{"id":"FlameSkullMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":593,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/FlameSkullMoveRight b/DangerousD/Content/animations/FlameSkullMoveRight new file mode 100644 index 0000000..c0c96b6 --- /dev/null +++ b/DangerousD/Content/animations/FlameSkullMoveRight @@ -0,0 +1 @@ +{"id":"FlameSkullMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":576,"Width":24,"Height":16},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostAttack b/DangerousD/Content/animations/GhostAttack new file mode 100644 index 0000000..7ada2dc --- /dev/null +++ b/DangerousD/Content/animations/GhostAttack @@ -0,0 +1 @@ +{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostMoveLeft b/DangerousD/Content/animations/GhostMoveLeft new file mode 100644 index 0000000..32b880b --- /dev/null +++ b/DangerousD/Content/animations/GhostMoveLeft @@ -0,0 +1 @@ +{"id":"GhostMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":536,"Width":24,"Height":26},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostMoveRight b/DangerousD/Content/animations/GhostMoveRight new file mode 100644 index 0000000..74911c7 --- /dev/null +++ b/DangerousD/Content/animations/GhostMoveRight @@ -0,0 +1 @@ +{"id":"GhostMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":503,"Width":24,"Height":26},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GhostSpawn b/DangerousD/Content/animations/GhostSpawn new file mode 100644 index 0000000..99d53e1 --- /dev/null +++ b/DangerousD/Content/animations/GhostSpawn @@ -0,0 +1 @@ +{"id":"GhostSpawn","textureName":"MonstersAnimations","startSpriteRectangle":{"X":26,"Y":503,"Width":24,"Height":30},"frameSecond":[{"Item1":0,"Item2":20}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanDaggerLeft b/DangerousD/Content/animations/HunchmanDaggerLeft new file mode 100644 index 0000000..b21064a --- /dev/null +++ b/DangerousD/Content/animations/HunchmanDaggerLeft @@ -0,0 +1 @@ +{"id":"HunchmanDaggerLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":224,"Y":129,"Width":9,"Height":6},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanDaggerRight b/DangerousD/Content/animations/HunchmanDaggerRight new file mode 100644 index 0000000..43354f1 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanDaggerRight @@ -0,0 +1 @@ +{"id":"HunchmanDaggerRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":224,"Y":116,"Width":9,"Height":6},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderMoveLeft b/DangerousD/Content/animations/SpiderMoveLeft new file mode 100644 index 0000000..262a25b --- /dev/null +++ b/DangerousD/Content/animations/SpiderMoveLeft @@ -0,0 +1 @@ +{"id":"SpiderMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":225,"Width":34,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderMoveRight b/DangerousD/Content/animations/SpiderMoveRight new file mode 100644 index 0000000..ffebe55 --- /dev/null +++ b/DangerousD/Content/animations/SpiderMoveRight @@ -0,0 +1 @@ +{"id":"SpiderMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":199,"Width":34,"Height":8},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderOnWeb b/DangerousD/Content/animations/SpiderOnWeb new file mode 100644 index 0000000..c9f8c45 --- /dev/null +++ b/DangerousD/Content/animations/SpiderOnWeb @@ -0,0 +1 @@ +{"id":"SpiderOnWeb","textureName":"MonstersAnimations","startSpriteRectangle":{"X":80,"Y":199,"Width":16,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/SpiderWeb b/DangerousD/Content/animations/SpiderWeb new file mode 100644 index 0000000..39363d6 --- /dev/null +++ b/DangerousD/Content/animations/SpiderWeb @@ -0,0 +1 @@ +{"id":"SpiderWeb","textureName":"MonstersAnimations","startSpriteRectangle":{"X":108,"Y":199,"Width":4,"Height":8},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfJumpLeft b/DangerousD/Content/animations/WolfJumpLeft new file mode 100644 index 0000000..2e54b48 --- /dev/null +++ b/DangerousD/Content/animations/WolfJumpLeft @@ -0,0 +1 @@ +{"id":"WolfJumpLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":133,"Y":290,"Width":40,"Height":33},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfJumpRight b/DangerousD/Content/animations/WolfJumpRight new file mode 100644 index 0000000..43760af --- /dev/null +++ b/DangerousD/Content/animations/WolfJumpRight @@ -0,0 +1 @@ +{"id":"WolfJumpRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":133,"Y":258,"Width":40,"Height":33},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfMoveLeft b/DangerousD/Content/animations/WolfMoveLeft new file mode 100644 index 0000000..924a49c --- /dev/null +++ b/DangerousD/Content/animations/WolfMoveLeft @@ -0,0 +1 @@ +{"id":"WolfMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":292,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/WolfMoveRight b/DangerousD/Content/animations/WolfMoveRight new file mode 100644 index 0000000..67ca172 --- /dev/null +++ b/DangerousD/Content/animations/WolfMoveRight @@ -0,0 +1 @@ +{"id":"WolfMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":258,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/ZombieLeftAttack b/DangerousD/Content/animations/ZombieLeftAttack index 63d7675..cb1466b 100644 --- a/DangerousD/Content/animations/ZombieLeftAttack +++ b/DangerousD/Content/animations/ZombieLeftAttack @@ -1 +1 @@ -{"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} +{"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} diff --git a/DangerousD/Content/animations/ZombieRightAttack b/DangerousD/Content/animations/ZombieRightAttack index 2a48da2..7da67ee 100644 --- a/DangerousD/Content/animations/ZombieRightAttack +++ b/DangerousD/Content/animations/ZombieRightAttack @@ -1 +1 @@ -{"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} +{"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} diff --git a/DangerousD/Content/deathAnimation.png b/DangerousD/Content/deathAnimation.png new file mode 100644 index 0000000..3eb4a52 Binary files /dev/null and b/DangerousD/Content/deathAnimation.png differ diff --git a/DangerousD/Content/menuFon3.jpg b/DangerousD/Content/menuFon3.jpg new file mode 100644 index 0000000..b608638 Binary files /dev/null and b/DangerousD/Content/menuFon3.jpg differ diff --git a/DangerousD/GameCore/GUI/LobbyGUI.cs b/DangerousD/GameCore/GUI/LobbyGUI.cs index a2e613d..f782750 100644 --- a/DangerousD/GameCore/GUI/LobbyGUI.cs +++ b/DangerousD/GameCore/GUI/LobbyGUI.cs @@ -7,6 +7,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using DangerousD.GameCore.Managers; +using MonogameLibrary.UI.Base; +using System.Diagnostics; + namespace DangerousD.GameCore.GUI { class LobbyGUI : AbstractGui @@ -17,8 +21,12 @@ namespace DangerousD.GameCore.GUI } protected override void CreateUI() { - int screenWidth = AppManager.Instance.resolution.X; - int screenHeight = AppManager.Instance.resolution.Y; + int screenWidth = AppManager.Instance.inGameResolution.X; + int screenHeight = AppManager.Instance.inGameResolution.Y; + + var lobbyBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon3" }; + Elements.Add(lobbyBackground); + lobbyBackground.LoadTexture(AppManager.Instance.Content); // CheckBoxs Elements.Add(new Label(Manager) { rectangle = new Rectangle(screenWidth / 30 * 2, screenHeight / 30 * 5, @@ -26,7 +34,7 @@ namespace DangerousD.GameCore.GUI // Buttons { - Button backButton = new Button(Manager) + Button backButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30, screenHeight / 30, 60, 50), text = "<-", @@ -38,7 +46,7 @@ namespace DangerousD.GameCore.GUI AppManager.Instance.ChangeGameState(GameState.Menu); }; - Button hostButton = new Button(Manager) + Button hostButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30, screenHeight / 15 * 13, 120, 50), text = "Host", @@ -50,7 +58,7 @@ namespace DangerousD.GameCore.GUI }; - Button refreshButton = new Button(Manager) + Button refreshButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30 * 6, screenHeight / 15 * 13, 120, 50), text = "Refresh", @@ -62,7 +70,7 @@ namespace DangerousD.GameCore.GUI }; - Button joinSelectedButton = new Button(Manager) + Button joinSelectedButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30 * 25, screenHeight / 15 * 13, 120, 50), text = "Join", @@ -73,7 +81,7 @@ namespace DangerousD.GameCore.GUI joinSelectedButton.LeftButtonPressed += () => { }; - Button joinByIpButton = new Button(Manager) + Button joinByIpButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 30 * 25, screenHeight / 30, 120, 50), text = "JoinByIp", diff --git a/DangerousD/GameCore/GUI/LoginGUI.cs b/DangerousD/GameCore/GUI/LoginGUI.cs index f495d36..a81284f 100644 --- a/DangerousD/GameCore/GUI/LoginGUI.cs +++ b/DangerousD/GameCore/GUI/LoginGUI.cs @@ -5,6 +5,10 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; +using DangerousD.GameCore.Managers; +using MonogameLibrary.UI.Base; +using System.Diagnostics; + using MonogameLibrary.UI.Elements; using MonogameLibrary.UI.Enums; @@ -20,8 +24,12 @@ namespace DangerousD.GameCore.GUI protected override void CreateUI() { - int screenWidth = AppManager.Instance.resolution.X; - int screenHeight = AppManager.Instance.resolution.Y; + int screenWidth = AppManager.Instance.inGameResolution.X; + int screenHeight = AppManager.Instance.inGameResolution.Y; + + var loginBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon2" }; + Elements.Add(loginBackground); + loginBackground.LoadTexture(AppManager.Instance.Content); Elements.Add(new Label(Manager) { rectangle = new Rectangle(screenWidth / 2 - 250, screenHeight / 6 - 50, 500, 100), @@ -29,7 +37,7 @@ namespace DangerousD.GameCore.GUI scale = 0.8f, fontColor = Color.White, mainColor = Color.Transparent, - fontName = "font2" + fontName = "ButtonFont" }); // TextBox-ы @@ -83,7 +91,7 @@ namespace DangerousD.GameCore.GUI // Кнопки { - Button logButton = new Button(Manager) { + Button logButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 4 + 50, screenHeight / 6 * 4, 100, 50), text = "LogIn", scale = 0.2f, @@ -97,7 +105,7 @@ namespace DangerousD.GameCore.GUI } }; - Button regButton = new Button(Manager) + Button regButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 4 * 2 + 50, screenHeight / 6 * 4, 100, 50), text = "Reg", @@ -107,7 +115,7 @@ namespace DangerousD.GameCore.GUI }; regButton.LeftButtonPressed += GoToRegWebServer; - Button backButton = new Button(Manager) + Button backButton = new ButtonText(Manager) { rectangle = new Rectangle(screenWidth / 20, screenHeight / 15, 50, 50), text = "<-", diff --git a/DangerousD/GameCore/GUI/MenuGUI.cs b/DangerousD/GameCore/GUI/MenuGUI.cs index 62ff7c0..f619d5f 100644 --- a/DangerousD/GameCore/GUI/MenuGUI.cs +++ b/DangerousD/GameCore/GUI/MenuGUI.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Elements; using System.Diagnostics; +using System.Runtime.Serialization; namespace DangerousD.GameCore.GUI; @@ -10,13 +11,25 @@ internal class MenuGUI : AbstractGui { protected override void CreateUI() { + + int wigth = AppManager.Instance.Window.ClientBounds.Width; int height = AppManager.Instance.Window.ClientBounds.Height; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "menuFon" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); - Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2 - 60, 60, 50, 50), text = "Dangerous", mainColor = Color.Transparent, scale = 0.7f, fontName = "Font2", fontColor = Color.White }); - Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2 + 250, 90, 50, 50), text = "D", mainColor = Color.Transparent, scale = 1.2f, fontName = "Font2", fontColor = Color.White }); + int TopMenu = 0; + Color[] colors = new Color[] { new Color(64, 53, 51), new Color(84, 58, 52), + new Color(170, 101, 63), new Color(254, 208, 116), new Color(252, 231, 124) }; + for (int i = 0; i < colors.Length; i++) + Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2 - 60, 60, 50, 50), text = "Dangerous", mainColor = Color.Transparent, scale = 1-0.05f*i*i/10, fontName = "Font2", fontColor = colors[i] }); + + int dx = 100; + Color[] colors2 = new Color[] { new Color(64, 53, 51), new Color(84, 58, 52), + new Color(170, 101, 63), new Color(254, 208, 116), new Color(252, 231, 124) }; + for (int i = 0; i < colors2.Length; i++) + Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2 + 250 + dx-i*i, 90 - i * i/5, 50, 50), text = "D", mainColor = Color.Transparent, scale = 1.3f - 0.05f * i * i / 5, fontName = "Font2", fontColor = colors2[i] }); + var butSingle = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 130, 300, 50), text = "Singleplayer", fontName = "ButtonFont" }; Elements.Add(butSingle); butSingle.LeftButtonPressed += () => diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index 47ae72e..ae5cd2c 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -14,8 +14,8 @@ namespace DangerousD.GameCore { protected Vector2 _pos; public Vector2 Pos => _pos; - public int Width { get; protected set; } - public int Height { get; protected set; } + public int Width { get; set; } + public int Height { get; set; } public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height); public Vector2 velocity; public Vector2 acceleration; diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs similarity index 90% rename from DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs rename to DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs index 1b28997..4fbe6ff 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs @@ -24,11 +24,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public override void Update(GameTime gameTime) { - if (monster_health <= 0) - { - Death(); - isAlive = false; - } base.Update(gameTime); } public abstract void Death(); @@ -36,5 +31,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public abstract void Attack(); public abstract void Move(GameTime gameTime); + + public void TakeDamage(int damage) + { + monster_health -= damage; + if (monster_health <= 0) + { + Death(); + isAlive = false; + } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs index c521c2e..cd00606 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FlameSkull.cs @@ -14,10 +14,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public FlameSkull(Vector2 position) : base(position) { - + Width = 62; + Height = 40; + monster_speed = 3; + name = "Skull"; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FlameSkullMoveLeft", "FlameSkullMoveRight" }, "FlameSkullMoveRight"); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FlameSkullMoveRight" , "FlameSkullMoveLeft"}, "FlameSkullMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs index 0434e4d..b0b3429 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs @@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters Height = 160; GraphicsComponent.StartAnimation("FrankMoveLeft"); monster_speed = 1; - name = "Фрэнк"; + name = "Frank"; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); @@ -35,35 +35,27 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - /* if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20) + var player = AppManager.Instance.GameManager.players[0]; + if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20) { player.Death(name); - } */ - + } + if (isGoRight) - { + { if (GraphicsComponent.GetCurrentAnimation != "FrankMoveRight") { GraphicsComponent.StartAnimation("FrankMoveRight"); - velocity = new Vector2(monster_speed, 0); } + velocity.X = monster_speed; } - else if (!isGoRight) + else { if (GraphicsComponent.GetCurrentAnimation != "FrankMoveLeft") { GraphicsComponent.StartAnimation("FrankMoveLeft"); - velocity = new Vector2(-monster_speed, 0); } - } - - if (_pos.X <= 1) - { - isGoRight = true; - } - else if (_pos.X >= 500) - { - isGoRight = false; + velocity.X = -monster_speed; } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs new file mode 100644 index 0000000..7101da2 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -0,0 +1,41 @@ +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; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class FrankBalls : CoreEnemy + { + public FrankBalls(Vector2 position) : base(position) + { + name = "FrankBalls"; + Width = 40; + Height = 40; + monster_speed = 1; + acceleration = Vector2.Zero; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs index b8827b1..1e47e99 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs @@ -12,11 +12,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public Ghost(Vector2 position) : base(position) { + monster_speed = 1; + name = "Ghost"; + Width = 48; + Height = 62; + GraphicsComponent.StartAnimation("GhostSpawn"); } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, ""); - + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "GhostMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs new file mode 100644 index 0000000..9e616ed --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs @@ -0,0 +1,40 @@ +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; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class HunchmanDagger : CoreEnemy + { + public HunchmanDagger(Vector2 position) : base(position) + { + name = "Hunchman"; + monster_speed = 1; + Width = 9; + Height = 6; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new (new List { "HunchmanDaggerRight", "HunchmanDaggerLeft" }, "HunchmanDaggerLeft"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs index 9513d71..bffa5f6 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Spider.cs @@ -12,15 +12,85 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Spider : CoreEnemy { + protected SpiderWeb web; + protected float delay; + protected int webLength; + protected bool isDown; + protected bool isDownUp; public Spider(Vector2 position) : base(position) { + isDownUp = true; + isDown = true; + web = new SpiderWeb(Pos); + name = "Spider"; + Width = 112; + Height = 24; + delay = 0; + webLength = 0; + monster_speed = 1; + acceleration = Vector2.Zero; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderMoveRight", "SpiderMoveLeft", "SpiderDown", "SpiderUp" }, ""); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderMoveRight", "SpiderMoveLeft", "SpiderOnWeb" }, "SpiderMoveRight"); - public override void Attack() + public override void Update(GameTime gameTime) { + if (isDownUp) + { + Width = 48; + Height = 72; + delay += (float)gameTime.ElapsedGameTime.TotalSeconds; + if (delay > 0.5 && webLength <= 4 && isDown) + { + StartCicycleAnimation("SpiderOnWeb"); + webLength++; + _pos.Y += 25; + web.Height = webLength * 25; + web.SetPosition(new Vector2(_pos.X + Width / 2 - web.Width / 2, Pos.Y - 25 * webLength)); + delay = 0; + if (webLength == 4) + { + isDown = false; + } + } + else if (delay > 0.5 && webLength != 0 && !isDown) + { + StartCicycleAnimation("SpiderOnWeb"); + webLength--; + _pos.Y -= 25; + web.Height = webLength * 25; + web.SetPosition(new Vector2(_pos.X + Width / 2 - web.Width / 2, Pos.Y - 25 * webLength)); + delay = 0; + if (webLength == 0) + { + isDown = true; + } + } + else + { + Width = 112; + Height = 24; + } + } + base.Update(gameTime); + } + public override void Attack() + { //48 72 + + } + + public override void Draw(SpriteBatch spriteBatch) + { + if (GraphicsComponent.GetCurrentAnimation == "SpiderOnWeb") + { + GraphicsComponent.DrawAnimation(new Rectangle((int)Pos.X, (int)Pos.Y, 48, 72), spriteBatch); + + } + else + { + base.Draw(spriteBatch); + } } public override void Death() diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs new file mode 100644 index 0000000..d91ccaf --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/SpiderWeb.cs @@ -0,0 +1,41 @@ +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; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + public class SpiderWeb : CoreEnemy + { + public SpiderWeb(Vector2 position) : base(position) + { + name = "Web"; + monster_speed = 1; + Width = 16; + Height = 0; + acceleration = Vector2.Zero; + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "SpiderWeb" }, "SpiderWeb"); + + public override void Attack() + { + + } + + public override void Death() + { + + } + + public override void Move(GameTime gameTime) + { + + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs index 91af742..9d5acb8 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs @@ -14,9 +14,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public Werewolf(Vector2 position) : base(position) { + name = "Wolf"; + monster_speed = 1; + Width = 78; + Height = 96; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, ""); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, "WolfMoveRight"); public override void Attack() { diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index e120977..dba2deb 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -15,30 +15,23 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters private bool isGoRight = true; int leftBorder; int rightBorder; + bool isAttaking = false; public Zombie(Vector2 position) : base(position) { Width = 72; Height = 120; - monster_speed = 10; - GraphicsComponent.StartAnimation("ZombieLeftAttack"); + monster_speed = 3; name = "Zombie"; - leftBorder = (int)position.X; - rightBorder = (int)position.X + 200; + leftBorder = (int)position.X - 60; + rightBorder = (int)position.X + 120; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); public override void Update(GameTime gameTime) { - if (AppManager.Instance.GameManager.GetPlayer1.Pos.X>Pos.X) - isGoRight = true; - else - isGoRight = false; - Move(gameTime); - - if(Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X) + if (!isAttaking) { - Attack(); - AppManager.Instance.GameManager.GetPlayer1.Death(name); + Move(gameTime); } base.Update(gameTime); @@ -46,16 +39,22 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { + velocity.X = 0; + isAttaking = true; if (isGoRight) { - if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack") - GraphicsComponent.StartAnimation("ZombieRightAttack"); + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { + GraphicsComponent.StartAnimation("ZombieAttackRight"); + } AppManager.Instance.GameManager.players[0].Death(name); } else if (!isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack") - GraphicsComponent.StartAnimation("ZombieLeftAttack"); + { + GraphicsComponent.StartAnimation("ZombieLeftAttack"); + } AppManager.Instance.GameManager.players[0].Death(name); } } @@ -67,26 +66,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - double delta = gameTime.ElapsedGameTime.TotalSeconds; + float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; if (isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") + { GraphicsComponent.StartAnimation("ZombieMoveRight"); + } velocity.X = monster_speed; } else if (!isGoRight) { - if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") + { GraphicsComponent.StartAnimation("ZombieMoveLeft"); + } velocity.X = -monster_speed; } - } - public void TakeDamage(int damage) + if(Pos.X >= rightBorder) + { + isGoRight = false; + } + + else if(Pos.X <= leftBorder) + { + isGoRight = true; + } + } + public override void OnCollision(GameObject gameObject) { - monster_health -= damage; - //play take damage animation + if(gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + } + } + base.OnCollision(gameObject); } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs deleted file mode 100644 index 90266bf..0000000 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs +++ /dev/null @@ -1,31 +0,0 @@ -using DangerousD.GameCore.Graphics; -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DangerousD.GameCore.GameObjects.LivingEntities -{ - public class Player : LivingEntity - { - public Player(Vector2 position) : base(position) - { - Width = 32; - Height = 64; - } - - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");//TODO: Change to player - - public void Kill() - { - - } - - public void Death(string monsterName) - { - //анимация по имени монстра - } - } -} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs new file mode 100644 index 0000000..1867b60 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/DeathRectangle.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects; +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; + +namespace DangerousD.GameCore.GameObjects.PlayerDeath +{ + public class DeathRectangle : GameObject + { + public DeathRectangle(Vector2 pos, string DeathType) : base(pos) + { + Height = 128; + Width = 128; + PlayDeath(DeathType); + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List {"DeathFromZombie"}, + "DeathFromZombie"); + + public GraphicsComponent Gr => GraphicsComponent; + + private void PlayDeath(string deathName) + { + if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie") + { + GraphicsComponent.StartAnimation("DeathFromZombie"); + } + } + + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs new file mode 100644 index 0000000..b194de9 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -0,0 +1,45 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects.PlayerDeath; + +namespace DangerousD.GameCore.GameObjects.LivingEntities +{ + public class Player : LivingEntity + { + bool isAlive = true; + public Player(Vector2 position) : base(position) + { + Width = 32; + Height = 64; + } + public bool IsAlive { get { return isAlive; } } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack", "DeathFromZombie" }, "ZombieMoveLeft");//TODO: Change to player + + public void Kill() + { + + } + + public void Death(string monsterName) + { + if(monsterName == "Zombie") + { + DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName); + deathRectangle.Gr.actionOfAnimationEnd += (a) => + { + if (a == "DeathFrom" + monsterName) + { + AppManager.Instance.ChangeGameState(GameState.GameOver); + } + }; + } + isAlive = false; + } + } +} diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs index 75890aa..5c18831 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntity.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs @@ -23,4 +23,12 @@ public abstract class LivingEntity : Entity } base.Update(gameTime); } + + public virtual void StartCicycleAnimation(string animationName) + { + if (GraphicsComponent.GetCurrentAnimation != animationName) + { + GraphicsComponent.StartAnimation(animationName); + } + } } \ No newline at end of file diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 27c66a0..ca70881 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -8,8 +8,10 @@ using System.Text; namespace DangerousD.GameCore.Graphics { + public class GraphicsComponent { + public event Action actionOfAnimationEnd; private List animations; private List textures; private List texturesNames; @@ -27,13 +29,11 @@ namespace DangerousD.GameCore.Graphics 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(); @@ -114,10 +114,16 @@ namespace DangerousD.GameCore.Graphics { if (!currentAnimation.IsCycle) { + if(actionOfAnimationEnd != null) + { + actionOfAnimationEnd(currentAnimation.Id); + } currentAnimation = neitralAnimation; + } currentFrame = 0; + } buildSourceRectangle(); @@ -196,4 +202,4 @@ namespace DangerousD.GameCore.Graphics } } } -} \ No newline at end of file +} diff --git a/DangerousD/GameCore/InputManager.cs b/DangerousD/GameCore/InputManager.cs index 83e224f..803bd6e 100644 --- a/DangerousD/GameCore/InputManager.cs +++ b/DangerousD/GameCore/InputManager.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; namespace DangerousD.GameCore { public enum ScopeState { Up, Middle, Down } - class InputManager + public class InputManager { public delegate void Delegat(); public event Delegat MovEventJump; diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 67c6644..519a715 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -8,38 +8,53 @@ using DangerousD.GameCore.GUI; using Microsoft.Xna.Framework.Input; using DangerousD.GameCore.Graphics; using DangerousD.GameCore.Network; +using MonogameLibrary.UI.Base; +using DangerousD.GameCore.Managers; namespace DangerousD.GameCore { - public enum GameState { Menu, Options, Lobby, Game, Login } + public enum GameState { Menu, Options, Lobby, Game, Login, GameOver } public class AppManager : Game { public static AppManager Instance { get; private set; } private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; - public Point resolution; + private SpriteBatch _spriteBatch; GameState gameState; IDrawableObject MenuGUI; IDrawableObject OptionsGUI; IDrawableObject LoginGUI; IDrawableObject LobbyGUI; + public Point resolution = new Point(1920, 1080); + public Point inGameResolution = new Point(800, 480); + private RenderTarget2D renderTarget; public GameManager GameManager { get; private set; } = new(); public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder(); public NetworkManager NetworkManager { get; private set; } = new NetworkManager(); + public InputManager InputManager { get; private set; } = new InputManager(); + public SoundManager SoundManager { get; private set; } = new SoundManager(); + public SettingsManager SettingsManager { get; private set; } = new SettingsManager(); public AppManager() { Content.RootDirectory = "Content"; Instance = this; _graphics = new GraphicsDeviceManager(this); IsMouseVisible = true; - resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30); + SettingsManager = new SettingsManager(); + SettingsManager.LoadSettings(); + + resolution = SettingsManager.Resolution; + _graphics.PreferredBackBufferWidth = resolution.X; + _graphics.PreferredBackBufferHeight = resolution.Y; + // _graphics.IsFullScreen = true; gameState = GameState.Menu; MenuGUI = new MenuGUI(); LoginGUI = new LoginGUI(); LobbyGUI = new LobbyGUI(); + UIManager.resolution = resolution; + UIManager.resolutionInGame = inGameResolution; } protected override void Initialize() @@ -60,6 +75,9 @@ namespace DangerousD.GameCore LobbyGUI.LoadContent(); GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); GameObject.debugTexture.SetData(new Color[] { new Color(1, 0,0,0.25f) }); + SoundManager.LoadSounds(); + SoundManager.StartAmbientSound("DoomTestSong"); + renderTarget = new RenderTarget2D(GraphicsDevice, inGameResolution.X, inGameResolution.Y); } protected override void Update(GameTime gameTime) @@ -67,6 +85,8 @@ namespace DangerousD.GameCore if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); + InputManager.Update(); + SoundManager.Update(); switch (gameState) { case GameState.Menu: @@ -94,7 +114,8 @@ namespace DangerousD.GameCore protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); - + + GraphicsDevice.SetRenderTarget(renderTarget); switch (gameState) { case GameState.Menu: @@ -110,13 +131,18 @@ namespace DangerousD.GameCore LobbyGUI.Draw(_spriteBatch); break; case GameState.Game: - _spriteBatch.Begin(SpriteSortMode.Deferred,null,SamplerState.PointClamp); + _spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); GameManager.Draw(_spriteBatch); _spriteBatch.End(); break; default: break; } + GraphicsDevice.SetRenderTarget(null); + _spriteBatch.Begin(); + _spriteBatch.Draw(renderTarget, new Rectangle(0, 0, _graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), Color.White); + _spriteBatch.End(); + base.Draw(gameTime); } @@ -137,6 +163,8 @@ namespace DangerousD.GameCore case GameState.Game: GameManager.mapManager.LoadLevel("lvl"); break; + case GameState.GameOver: + break; default: throw new ArgumentOutOfRangeException(); } diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index a198d08..a83e0e8 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -21,6 +21,7 @@ namespace DangerousD.GameCore public MapManager mapManager; public PhysicsManager physicsManager; public List players; + public List otherObjects = new(); public Player GetPlayer1 { get; private set; } public GameManager() { @@ -44,17 +45,28 @@ namespace DangerousD.GameCore internal void Register(GameObject gameObject) { - if (gameObject is LivingEntity) - livingEntities.Add(gameObject as LivingEntity); - else if (gameObject is Entity) - entities.Add(gameObject as Entity); - else if (gameObject is MapObject) - mapObjects.Add(gameObject as MapObject); - else if (gameObject is Player) + if (gameObject is Player) { + livingEntities.Add(gameObject as LivingEntity); players.Add(gameObject as Player); - GetPlayer1= players[0]; - }else others.Add(gameObject); + GetPlayer1 = players[0]; + } + else if (gameObject is LivingEntity) + { + livingEntities.Add(gameObject as LivingEntity); + } + else if (gameObject is Entity) + { + entities.Add(gameObject as Entity); + } + else if (gameObject is MapObject) + { + mapObjects.Add(gameObject as MapObject); + } + else + { + otherObjects.Add(gameObject); + } } public void Draw(SpriteBatch _spriteBatch) @@ -65,7 +77,7 @@ namespace DangerousD.GameCore item.Draw(_spriteBatch); foreach (var item in livingEntities) item.Draw(_spriteBatch); - foreach (var item in others) + foreach (var item in otherObjects) item.Draw(_spriteBatch); } @@ -77,6 +89,8 @@ namespace DangerousD.GameCore item.Update(gameTime); foreach (var item in livingEntities) item.Update(gameTime); + foreach (var item in otherObjects) + item.Update(gameTime); physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime); diff --git a/DangerousD/GameCore/Managers/SettingsManager.cs b/DangerousD/GameCore/Managers/SettingsManager.cs index ab12904..7a55447 100644 --- a/DangerousD/GameCore/Managers/SettingsManager.cs +++ b/DangerousD/GameCore/Managers/SettingsManager.cs @@ -1,13 +1,88 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using Microsoft.Xna; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Newtonsoft.Json.Serialization; namespace DangerousD.GameCore.Managers { - internal class SettingsManager + public class SettingsManager { + private SettingsContainer settingsContainer= new SettingsContainer(); + public bool IsFullScreen { get => settingsContainer.IsFullScreen; } + public float MainVolume { get => settingsContainer.MainVolume; } + public float MusicVolume { get => settingsContainer.MusicVolume; } + public float SoundEffectsVolume { get => settingsContainer.SoundEffectsVolume; } + public Point Resolution { get => settingsContainer.Resolution; } + public void SetResolution(Point resolution) + { + settingsContainer.Resolution = resolution; + AppManager.Instance.resolution = resolution; + } + public void SetMainVolume(float volume) + { + settingsContainer.MainVolume = MainVolume; + ///AppManager.Instance.SoundManager. + + } + public void SetMusicVolume(float volume) + { + settingsContainer.MusicVolume = MainVolume; + + } + public void SetSoundEffectsVolume(float volume) + { + settingsContainer.SoundEffectsVolume = MainVolume; + + } + public void SetIsFullScreen(bool isFullScreen) + { + settingsContainer.IsFullScreen = isFullScreen; + } + public void LoadSettings() + { + if (!File.Exists("GameSettings.txt")) + { + SaveSettings(); + return; + } + + settingsContainer = JsonConvert.DeserializeObject(File.ReadAllText("GameSettings.txt")); + SetIsFullScreen(settingsContainer.IsFullScreen); + SetMainVolume(settingsContainer.MainVolume); + SetMusicVolume(settingsContainer.MusicVolume); + SetResolution(settingsContainer.Resolution); + SetSoundEffectsVolume(settingsContainer.SoundEffectsVolume); + + + } + public void SaveSettings() + { + using (StreamWriter streamWriter = new StreamWriter("GameSettings.txt")) + { + string _str = JsonConvert.SerializeObject(settingsContainer); + streamWriter.Write(_str); + } + } + + } + [Serializable] + public class SettingsContainer + { + [JsonProperty("IsFullScreen")] + public bool IsFullScreen { get; set; } = false; + [JsonProperty("MainVolume")] + public float MainVolume { get; set; } = 1; + [JsonProperty("MusicVolume")] + public float MusicVolume { get; set; } = 1; + [JsonProperty("SoundEffectsVolume")] + public float SoundEffectsVolume { get; set; } = 1; + [JsonProperty("Resolution")] + public Point Resolution { get; set; } = new Point(1920,1080); } } diff --git a/DangerousD/GameCore/Managers/SoundManager.cs b/DangerousD/GameCore/Managers/SoundManager.cs index 86e6282..9021fa8 100644 --- a/DangerousD/GameCore/Managers/SoundManager.cs +++ b/DangerousD/GameCore/Managers/SoundManager.cs @@ -5,6 +5,9 @@ using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; +using System.Linq; +using DangerousD.GameCore.Graphics; +using Newtonsoft.Json; namespace DangerousD.GameCore { @@ -12,19 +15,19 @@ namespace DangerousD.GameCore { public Dictionary Sounds = new Dictionary(); // словарь со звуками где строка - название файла public List PlayingSounds = new List(); // список со всеми звуками, которые проигрываются - public string SoundDirectory = "Sounds"; // папка со звуками там где exe public float MaxSoundDistance = 1500; // максимальная дальность звука - public void LoadSounds(ContentManager content) // метод для загрузки звуков из папки + public void LoadSounds() // метод для загрузки звуков из папки { - var soundFiles = Directory.GetFiles(SoundDirectory); + string[] soundFiles = Directory.GetFiles("../../../Content").Where(x=>x.EndsWith("mp3")).Select(x=>x.Split("\\").Last().Replace(".mp3", "")).ToArray();// папка со звуками там где exe foreach (var soundFile in soundFiles) { - Sounds.Add(soundFile, content.Load(soundFile)); + Sounds.Add(soundFile, AppManager.Instance.Content.Load(soundFile).CreateInstance()); } + } - public void StartSound(string soundName) // запустить звук у которого нет позиции + public void StartAmbientSound(string soundName) // запустить звук у которого нет позиции { var sound = new Sound(Sounds[soundName]); sound.SoundEffect.IsLooped = false; @@ -39,7 +42,7 @@ namespace DangerousD.GameCore sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; sound.SoundEffect.Play(); PlayingSounds.Add(sound); - }//GameManager.SendSound + } public void StopAllSounds() // остановка всех звуков { foreach (var sound in PlayingSounds) @@ -47,14 +50,21 @@ namespace DangerousD.GameCore PlayingSounds.Clear(); } - public void Update(Vector2 playerPos) // апдейт, тут происходит изменение громкости + + public void Update() // апдейт, тут происходит изменение громкости { - foreach (var sound in PlayingSounds) + + + var player = AppManager.Instance.GameManager.GetPlayer1; + if (player != null) { - if (!sound.isAmbient) - sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; - if (sound.SoundEffect.State == SoundState.Stopped) - PlayingSounds.Remove(sound); + for (int i = 0; i < PlayingSounds.Count; i++) + { + if (!PlayingSounds[i].isAmbient) + PlayingSounds[i].SoundEffect.Volume = (float)PlayingSounds[i].GetDistance(player.Pos) / MaxSoundDistance; + if (PlayingSounds[i].SoundEffect.State == SoundState.Stopped) + PlayingSounds.Remove(PlayingSounds[i]); + } } } } diff --git a/MonogameLibrary/UI/Base/UIManager.cs b/MonogameLibrary/UI/Base/UIManager.cs index 505d012..f8c1178 100644 --- a/MonogameLibrary/UI/Base/UIManager.cs +++ b/MonogameLibrary/UI/Base/UIManager.cs @@ -7,7 +7,7 @@ using MonogameLibrary.UI.Interfaces; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; -using static System.Net.Mime.MediaTypeNames; +using static System.Net.Mime.MediaTypeNames; namespace MonogameLibrary.UI.Base { @@ -28,6 +28,7 @@ namespace MonogameLibrary.UI.Base public KeyboardState GetKeyboardState { get { return keyboardState; } } static MouseState mouseState, prevmouseState; static KeyboardState keyboardState; + public static Point resolutionInGame, resolution; public void LoadContent(ContentManager content, string font) { @@ -48,11 +49,13 @@ namespace MonogameLibrary.UI.Base } } public void Update() - { + { try { keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); + mouseState = new MouseState((int)(mouseState.X*(float)resolutionInGame.X/resolution.X), + (int)(mouseState.Y * (float)resolutionInGame.Y / resolution.Y), mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2); } catch {