diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb
index b90c934..2b4d072 100644
--- a/DangerousD/Content/Content.mgcb
+++ b/DangerousD/Content/Content.mgcb
@@ -21,18 +21,6 @@
/processorParam:TextureFormat=Compressed
/build:ButtonFont.spritefont
-#begin checkboxs_off.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:checkboxs_off.png
-
#begin checkboxs_off-on.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -45,6 +33,18 @@
/processorParam:TextureFormat=Color
/build:checkboxs_off-on.png
+#begin checkboxs_off.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:checkboxs_off.png
+
#begin checkboxs_on.png
/importer:TextureImporter
/processor:TextureProcessor
@@ -93,7 +93,7 @@
/processorParam:TextureFormat=Color
/build:Diamond.png
-#begin doors.png
+#begin door.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@@ -103,7 +103,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
-/build:doors.png
+/build:door.png
#begin Font_12.spritefont
/importer:FontDescriptionImporter
@@ -157,7 +157,7 @@
/processorParam:TextureFormat=Color
/build:menuFon.jpg
-#begin MenuFon2.jpg
+#begin menuFon2.jpg
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@@ -167,7 +167,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
-/build:MenuFon2.jpg
+/build:menuFon2.jpg
#begin menuFon3.jpg
/importer:TextureImporter
@@ -260,7 +260,8 @@
/processorParam:TextureFormat=Color
/build:sliderBackground.png
-#begin SmokeAnimation2.png
+
+#begin smokeAnimation2.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@@ -270,7 +271,31 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
-/build:SmokeAnimation2.png
+/build:smokeAnimation2.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
+/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:textboxbackground1-1.png
#begin sounds/collected_coins.mp3
/importer:Mp3Importer
@@ -302,7 +327,7 @@
/processorParam:Quality=Best
/build:sounds/z3.mp3
-#begin textboxbackground1-1.png
+#begin textboxbackground2-1.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@@ -312,7 +337,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
-/build:textboxbackground1-1.png
+/build:textboxbackground2-1.png
#begin textboxbackground2,5-1.png
/importer:TextureImporter
@@ -326,18 +351,6 @@
/processorParam:TextureFormat=Color
/build:textboxbackground2,5-1.png
-#begin textboxbackground2-1.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:textboxbackground2-1.png
-
#begin textboxbackground6-1.png
/importer:TextureImporter
/processor:TextureProcessor
diff --git a/DangerousD/Content/Door.tsx b/DangerousD/Content/Door.tsx
index 8e5687c..a250dd5 100644
--- a/DangerousD/Content/Door.tsx
+++ b/DangerousD/Content/Door.tsx
@@ -1,4 +1,4 @@
-
+
diff --git a/DangerousD/Content/animations/DeathFromGhost b/DangerousD/Content/animations/DeathFromGhost
new file mode 100644
index 0000000..b4ef48e
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromGhost
@@ -0,0 +1 @@
+{"id":"DeathFromGhost","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":246,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/DeathFromHunchman b/DangerousD/Content/animations/DeathFromHunchman
new file mode 100644
index 0000000..a00ed27
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromHunchman
@@ -0,0 +1 @@
+{"id":"DeathFromHunchman","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":1,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/DeathFromSilasMaster b/DangerousD/Content/animations/DeathFromSilasMaster
new file mode 100644
index 0000000..3f9a76b
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromSilasMaster
@@ -0,0 +1 @@
+{"id":"DeathFromSilasMaster","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":295,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/DeathFromSlime b/DangerousD/Content/animations/DeathFromSlime
new file mode 100644
index 0000000..5a692f6
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromSlime
@@ -0,0 +1 @@
+{"id":"DeathFromSlime","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":50,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/DeathFromSpider b/DangerousD/Content/animations/DeathFromSpider
new file mode 100644
index 0000000..98a08a5
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromSpider
@@ -0,0 +1 @@
+{"id":"DeathFromSpider","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":148,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/DeathFromWerewolf b/DangerousD/Content/animations/DeathFromWerewolf
new file mode 100644
index 0000000..8f0b150
--- /dev/null
+++ b/DangerousD/Content/animations/DeathFromWerewolf
@@ -0,0 +1 @@
+{"id":"DeathFromWerewolf","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":197,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/GhostAttack b/DangerousD/Content/animations/GhostAttack
index 7ada2dc..8425c93 100644
--- a/DangerousD/Content/animations/GhostAttack
+++ b/DangerousD/Content/animations/GhostAttack
@@ -1 +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"}
+{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":50,"framesCount":2,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/playerShootBoomUpLeft b/DangerousD/Content/animations/playerShootBoomUpLeft
new file mode 100644
index 0000000..093eb3c
--- /dev/null
+++ b/DangerousD/Content/animations/playerShootBoomUpLeft
@@ -0,0 +1 @@
+{"id":"playerShootBoomUpLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":267,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"}
diff --git a/DangerousD/Content/animations/playerShootBoomUpRight b/DangerousD/Content/animations/playerShootBoomUpRight
new file mode 100644
index 0000000..3f70e03
--- /dev/null
+++ b/DangerousD/Content/animations/playerShootBoomUpRight
@@ -0,0 +1,24 @@
+{
+ "id": "playerShootBoomUpRight",
+ "textureName": "playerAnimation",
+ "startSpriteRectangle": {
+ "X": 267,
+ "Y": 1,
+ "Width": 24,
+ "Height": 32
+ },
+ "frameSecond": [
+ {
+ "Item1": 0,
+ "Item2": 3
+ },
+ {
+ "Item1": 1,
+ "Item2": 20
+ }
+ ],
+ "textureFrameInterval": 1,
+ "framesCount": 2,
+ "isCycle": false,
+ "offset": "0, 0"
+}
diff --git a/DangerousD/Content/doors.png b/DangerousD/Content/door.png
similarity index 100%
rename from DangerousD/Content/doors.png
rename to DangerousD/Content/door.png
diff --git a/DangerousD/Content/lvl2.tmx b/DangerousD/Content/lvl2.tmx
new file mode 100644
index 0000000..d610a6f
--- /dev/null
+++ b/DangerousD/Content/lvl2.tmx
@@ -0,0 +1,652 @@
+
+
diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx
index 9afca4d..a02975a 100644
--- a/DangerousD/Content/map.tmx
+++ b/DangerousD/Content/map.tmx
@@ -71,5 +71,10 @@
+
+
+
diff --git a/DangerousD/Content/MenuFon2.jpg b/DangerousD/Content/menuFon2.jpg
similarity index 100%
rename from DangerousD/Content/MenuFon2.jpg
rename to DangerousD/Content/menuFon2.jpg
diff --git a/DangerousD/Content/SmokeAnimation2.png b/DangerousD/Content/smokeAnimation2.png
similarity index 100%
rename from DangerousD/Content/SmokeAnimation2.png
rename to DangerousD/Content/smokeAnimation2.png
diff --git a/DangerousD/GameCore/GUI/DeathGUI.cs b/DangerousD/GameCore/GUI/DeathGUI.cs
index 31bff02..ce73850 100644
--- a/DangerousD/GameCore/GUI/DeathGUI.cs
+++ b/DangerousD/GameCore/GUI/DeathGUI.cs
@@ -23,7 +23,7 @@ internal class DeathGUI : AbstractGui
Elements.Add(butMenu);
butMenu.LeftButtonPressed += () =>
{
- AppManager.Instance.ChangeGameState(GameState.Menu);
+ AppManager.Instance.Restart("lvl");
};
foreach (var item in Elements)
{
diff --git a/DangerousD/GameCore/GUI/DebugHUD.cs b/DangerousD/GameCore/GUI/DebugHUD.cs
index c4e3e55..d864f75 100644
--- a/DangerousD/GameCore/GUI/DebugHUD.cs
+++ b/DangerousD/GameCore/GUI/DebugHUD.cs
@@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GUI
public void Draw(SpriteBatch spriteBatch)
{
- var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
+ /*var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
spriteBatch.Begin();
spriteBatch.DrawString(
_spriteFont,
@@ -52,7 +52,7 @@ namespace DangerousD.GameCore.GUI
SpriteEffects.None,
0
);
- spriteBatch.End();
+ spriteBatch.End();*/
}
public void Set(string key, string value)
diff --git a/DangerousD/GameCore/GUI/LobbyGUI.cs b/DangerousD/GameCore/GUI/LobbyGUI.cs
index 90ba3c9..1d8a2e1 100644
--- a/DangerousD/GameCore/GUI/LobbyGUI.cs
+++ b/DangerousD/GameCore/GUI/LobbyGUI.cs
@@ -135,6 +135,7 @@ namespace DangerousD.GameCore.GUI
};
Elements.Add(joinByIpButton);
joinByIpButton.LeftButtonPressed += () => {
+ AppManager.Instance.ChangeGameState(GameState.Game);
AppManager.Instance.NetworkManager.ClientInit(searchBarTextBox.text);
};
}
diff --git a/DangerousD/GameCore/GameObjects/Entities/Door.cs b/DangerousD/GameCore/GameObjects/Entities/Door.cs
index 4f909bb..5a8dd2f 100644
--- a/DangerousD/GameCore/GameObjects/Entities/Door.cs
+++ b/DangerousD/GameCore/GameObjects/Entities/Door.cs
@@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects.Entities
Height = (int)size.Y;
}
- protected override GraphicsComponent GraphicsComponent { get; } = new("doors");
+ protected override GraphicsComponent GraphicsComponent { get; } = new("door");
public override void Update(GameTime gameTime)
{
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs
index 38b1cc0..5f33df9 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/CoreEnemy.cs
@@ -36,9 +36,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public abstract void Move(GameTime gameTime);
- public void TakeDamage(int damage)
+ public virtual void TakeDamage()
{
- monster_health -= damage;
+ monster_health--;
if (monster_health <= 0)
{
Death();
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs
index 9400485..720fd96 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs
@@ -17,6 +17,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
private bool isFlyRight = true;
private bool isFlyUp = true;
private bool isAttacking = false;
+ private int hp;
public Rectangle Collision
{
@@ -32,6 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
monster_speed = 3;
velocity = new Vector2(3,-3);
acceleration = Vector2.Zero;
+ hp = 10;
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight");
@@ -39,7 +41,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Update(GameTime gameTime)
{
Move(gameTime);
- AppManager.Instance.DebugHUD.Set(name, velocity.ToString());
+
+ Death();
+
base.Update(gameTime);
}
public override void Attack()
@@ -60,7 +64,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death()
{
-
+ if (hp <= 0)
+ {
+ AppManager.Instance.GameManager.Remove(this);
+ }
}
public override void Move(GameTime gameTime)
@@ -75,6 +82,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
isFlyRight = false;
velocity.X = -velocity.X;
+ hp--;
}
}
else
@@ -84,6 +92,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
isFlyRight = true;
velocity.X = -velocity.X;
+ hp--;
}
}
if (isFlyUp)
@@ -94,6 +103,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
isFlyUp = false;
velocity.Y = -velocity.Y;
+ hp--;
}
}
else
@@ -103,6 +113,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
isFlyUp = true;
velocity.Y = -velocity.Y;
+ hp--;
}
}
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs
index 214a4c2..57ab2c4 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs
@@ -17,11 +17,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
isGoRight = true;
monster_speed = 3;
name = "Ghost";
- Width = 48;
- Height = 62;
+ Width = 24;
+ Height = 30;
GraphicsComponent.StartAnimation("GhostSpawn");
- acceleration = Vector2.Zero;
-
+ acceleration = new Vector2(0,1);
+ monster_health = 1;
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "GhostMoveRight");
@@ -38,13 +38,32 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Attack()
{
-
+ velocity.X = 0;
+ isAttack = true;
+ if (GraphicsComponent.GetCurrentAnimation != "GhostAttack")
+ {
+ GraphicsComponent.StartAnimation("GhostAttack");
+ }
+
+ AppManager.Instance.GameManager.players[0].Death(name);
}
public override void Death()
{
}
+ public override void OnCollision(GameObject gameObject)
+ {
+ if (gameObject is Player)
+ {
+ if (AppManager.Instance.GameManager.players[0].IsAlive)
+ {
+ Attack();
+
+ }
+ }
+ base.OnCollision(gameObject);
+ }
public override void Move(GameTime gameTime)
{
@@ -64,17 +83,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
velocity.X = -monster_speed;
}
- if (Pos.X >= rightBoarder)
+ var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2));
+ if (isGoRight)
{
- isGoRight = false;
+ getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, Width + 4, 2));
}
- else if (Pos.X <= leftBoarder)
+ else
{
- isGoRight = true;
+ getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 3, (int)Pos.Y + Height / 2 - 2, Width + 3, 2));
}
- if (true)
- {
+
+ foreach (var item in getCols)
+ {
+ if (item is MapObject)
+ {
+ isGoRight = !isGoRight;
+ break;
+ }
}
}
@@ -82,7 +108,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
}
+ public void TakeDamage()
+ {
+ monster_health--;
+
+ if (monster_health <= 0)
+ {
+ Death();
+ }
+ }
public void Target()
{
throw new NotImplementedException();
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs
index 41a2fcc..afdbf9b 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Slime.cs
@@ -173,7 +173,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
public override void Death()
{
+
+ Particle particle = new Particle(Pos);
+
+ AppManager.Instance.GameManager.Remove(this);
}
public override void Move(GameTime gameTime)
@@ -220,7 +224,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
velocity.X = -monster_speed;
}
- var getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); ;
+ var getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2));
if (isGoRight)
{
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 51, 2));
@@ -348,5 +352,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
base.OnCollision(gameObject);
}
+ public void TakeDamage()
+ {
+ monster_health--;
+
+ Particle particle = new Particle(Pos);
+ if (monster_health <= 0)
+ {
+ Death();
+ }
+ }
}
}
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs
index 837932f..bb6cd6f 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Werewolf.cs
@@ -12,24 +12,33 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
public class Werewolf : CoreEnemy
{
- private bool isAttack;
+ private bool isJump;
+ int delay;
public Werewolf(Vector2 position) : base(position)
{
name = "Wolf";
- monster_speed = 4;
- Width = 78;
- Height = 96;
+ monster_speed = 3;
+ Width = 39;
+ Height = 48;
+ delay = 10;
+ monster_health = 3;
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, "WolfMoveRight");
public override void Update(GameTime gameTime)
{
- if (!isAttack)
+ if(!isJump )
+ {
+ Jump();
+ }
+ if(isOnGround)
{
Move(gameTime);
+
}
+
base.Update(gameTime);
}
@@ -41,11 +50,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death()
{
+ for (int i = 0; i < 5; i++)
+ {
+ Particle particle = new Particle(Pos);
+ }
+ AppManager.Instance.GameManager.Remove(this);
}
public override void Move(GameTime gameTime)
{
+ isJump = false;
+
if (isGoRight)
{
if (GraphicsComponent.GetCurrentAnimation != "WolfMoveRight")
@@ -62,23 +78,89 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
velocity.X = -monster_speed;
}
- if (Pos.X >= rightBoarder)
+ var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2));
+ if (isGoRight)
{
- isGoRight = false;
+ getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, Width+4, 2));
}
- else if (Pos.X <= leftBoarder)
+ else
{
- isGoRight = true;
+ getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 3, (int)Pos.Y + Height / 2 - 2, Width +3, 2));
+ }
+
+
+ foreach (var item in getCols)
+ {
+ if (item is MapObject)
+ {
+ isGoRight = !isGoRight;
+ break;
+ }
}
}
public override void Attack(GameTime gameTime)
{
}
-
+ public void Jump()
+ {
+ var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2));
+ if (isGoRight)
+ {
+ getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, Width+100, Height),false);
+ if(getCols.Count > 0)
+ {
+ isJump = true;
+ if (GraphicsComponent.GetCurrentAnimation != "WolfJumpRight")
+ {
+ GraphicsComponent.StartAnimation("WolfJumpRight");
+ }
+ velocity.Y = -7;
+ velocity.X = 6;
+ }
+
+ }
+ else
+ {
+ getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-100, (int)Pos.Y, 100, Height), false);
+ if (getCols.Count > 0)
+ {
+ isJump = true;
+ if (GraphicsComponent.GetCurrentAnimation != "WolfJumpLeft")
+ {
+ GraphicsComponent.StartAnimation("WolfJumpLeft");
+ }
+ velocity.Y = -7;
+ velocity.X = -6;
+ }
+
+ }
+
+ }
+ public override void OnCollision(GameObject gameObject)
+ {
+ /*/if (gameObject is Player)
+ {
+ if (AppManager.Instance.GameManager.players[0].IsAlive)
+ {
+ AppManager.Instance.GameManager.players[0].Death(name);
+ }
+ }
+ base.OnCollision(gameObject);/*/
+ }
public void Target()
{
throw new NotImplementedException();
}
+ public void TakeDamage()
+ {
+ monster_health--;
+
+ Particle particle = new Particle(Pos);
+ if (monster_health <= 0)
+ {
+ Death();
+ }
+ }
}
}
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
index f211ccb..c952e7e 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs
@@ -14,7 +14,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
public class Zombie : CoreEnemy
{
- private bool isAttack;
float leftBorder;
float rightBorder;
@@ -32,6 +31,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
rightBorder = (int)position.X + 100;
physicsManager = new PhysicsManager();
Random random = new Random();
+ monster_health = 2;
if(random.Next(0, 2) == 0)
{
isGoRight = true;
@@ -58,18 +58,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
Target();
Move(gameTime);
}
- fixBorder();
+ //fixBorder();
base.Update(gameTime);
}
public override void Attack()
{
- AppManager.Instance.GameManager.GetPlayer1.Death(name);
+ isAttaking = true;
+ PlayAttackAnimation();
+ AppManager.Instance.GameManager.GetClosestPlayer(Pos).Death(name);
}
public void PlayAttackAnimation()
{
velocity.X = 0;
- isAttaking = true;
if (isGoRight)
{
if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack")
@@ -123,7 +124,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
public override void OnCollision(GameObject gameObject)
{
- if (gameObject.id == AppManager.Instance.GameManager.GetPlayer1.id && AppManager.Instance.GameManager.GetPlayer1.IsAlive)
+ if (gameObject.id == AppManager.Instance.GameManager.GetClosestPlayer(Pos).id && AppManager.Instance.GameManager.GetClosestPlayer(Pos).IsAlive)
{
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.Client)
{
@@ -183,7 +184,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Attack(GameTime gameTime)
{}
- public void TakeDamage()
+ public override void TakeDamage()
{
if (monster_health == 3)
AppManager.Instance.SoundManager.StartSound("z3", Pos, Pos);
@@ -192,7 +193,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (monster_health == 1)
AppManager.Instance.SoundManager.StartSound("z3", Pos, Pos);
monster_health--;
- GraphicsComponent.StartAnimation("ZombieRightAttack");
Particle particle = new Particle(Pos);
if (monster_health <= 0)
{
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs
index 8644b77..e199e4d 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/AnimationRectangle.cs
@@ -25,14 +25,15 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath
private void PlayDeath(string deathName)
{
- if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie")
- {
- GraphicsComponent.StartAnimation("DeathFromZombie");
- }
- if (GraphicsComponent.GetCurrentAnimation != "DeathFromSilasHand")
- {
- GraphicsComponent.StartAnimation("DeathFromSilasHand");
- }
+ //if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie")
+ //{
+ // GraphicsComponent.StartAnimation("DeathFromZombie");
+ //}
+ //if (GraphicsComponent.GetCurrentAnimation != "DeathFromSilasHand")
+ //{
+ // GraphicsComponent.StartAnimation("DeathFromSilasHand");
+ //}
+ GraphicsComponent.StartAnimation(deathName);
}
}
diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
index 0b270a1..b439fc2 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs
@@ -10,6 +10,7 @@ using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using DangerousD.GameCore.GameObjects.LivingEntities.Monsters;
using DangerousD.GameCore.Network;
+using DangerousD.GameCore.GameObjects.MapObjects;
namespace DangerousD.GameCore.GameObjects.LivingEntities
{
@@ -66,6 +67,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{
bullets++;
}
+ if(a == "playerShootBoomUpRight" || a == "playerShootBoomUpLeft")
+ {
+ isShooting = false;
+ }
};
}
@@ -74,7 +79,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",
- "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft"}, "playerReload");
+ "playerJumpRight" , "playerJumpLeft", "playerShootLeft", "playerShootRight", "playerReload", "smokeAfterShoot", "playerShootUpRight", "playerShootUpLeft", "playerShootBoomUpRight",
+ "playerShootBoomUpLeft"}, "playerReload");
public void Attack()
{
@@ -90,10 +96,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
public Rectangle GetShootRectangle(bool isRight)
{
- if (isRight)
+ if (isRight)
return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2);
else
- return new Rectangle((int)Pos.X-shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2);
+ return new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2);
}
public override void Draw(SpriteBatch spriteBatch)
{
@@ -119,7 +125,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
return;
}
isAttacked = true;
- if(monsterName == "Zombie")
+ if (monsterName == "Zombie")
{
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
@@ -130,7 +136,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
};
}
- else if(monsterName == "Spider")
+ else if (monsterName == "Spider")
{
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
@@ -186,41 +192,37 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
bullets--;
if (isRight)
{
- StartCicycleAnimation("playerShootRight");
- var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared());
- if (targets.Count() > 0)
+ if (!isUping)
{
- Zombie targetZombie = (Zombie)targets.First();
- targetZombie.TakeDamage();
-
+ StartCicycleAnimation("playerShootRight");
+ Bullet bullet = new Bullet(new Vector2(Pos.X + 16, Pos.Y));
+ bullet.ShootRight();
+ SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 12, Pos.Y - 8));
}
- targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands)).OrderBy(x => (x.Pos - Pos).LengthSquared());
- if (targets.Count() > 0)
+ else
{
- SilasHands targetHand = (SilasHands)targets.First();
- targetHand.TakeDamage();
+ StartCicycleAnimation("playerShootBoomUpRight");
+ Bullet bullet = new Bullet(new Vector2(Pos.X + 16, Pos.Y));
+ bullet.ShootUpRight();
+ SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 12, Pos.Y - 8));
}
- SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7));
}
- else
+ else if(!isRight)
{
- StartCicycleAnimation("playerShootLeft");
- var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie));
- if (targets != null)
+ if (!isUping)
{
- foreach (var target in targets)
- {
- Zombie targetZombie = (Zombie)target;
- targetZombie.TakeDamage();
- }
+ StartCicycleAnimation("playerShootBoomUpLeft");
+ Bullet bullet = new Bullet(new Vector2(Pos.X, Pos.Y));
+ bullet.ShootLeft();
+ SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 6, Pos.Y - 7));
}
- targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands));
- if (targets.Count() > 0)
+ else
{
- SilasHands targetHand = (SilasHands)targets.First();
- targetHand.TakeDamage();
+ StartCicycleAnimation("playerShootBoomUpLeft");
+ Bullet bullet = new Bullet(new Vector2(Pos.X, Pos.Y));
+ bullet.ShootUpLeft();
+ SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 6, Pos.Y - 7));
}
- SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7));
}
}
}
@@ -241,7 +243,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
FallingThroughPlatform = false;
}
GraphicsComponent.SetCameraPosition(Pos);
- if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
+ if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
{
if (!isShooting)
{
@@ -284,14 +286,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
else if (AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
{
- if(bullets < 5)
- {
- if (GraphicsComponent.GetCurrentAnimation != "playerReload")
- {
- GraphicsComponent.StartAnimation("playerReload");
- }
- }
- else if (isRight)
+ if (isRight)
{
if (isUping)
{
@@ -300,6 +295,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
GraphicsComponent.StartAnimation("playerShootUpRight");
}
}
+ else if (bullets < 5)
+ {
+ if (GraphicsComponent.GetCurrentAnimation != "playerReload")
+ {
+ GraphicsComponent.StartAnimation("playerReload");
+ }
+ }
else
{
GraphicsComponent.StartAnimation("playerRightStay");
@@ -314,6 +316,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
GraphicsComponent.StartAnimation("playerShootUpLeft");
}
}
+ else if (bullets < 5)
+ {
+ if (GraphicsComponent.GetCurrentAnimation != "playerReload")
+ {
+ GraphicsComponent.StartAnimation("playerReload");
+ }
+ }
else
{
GraphicsComponent.StartAnimation("playerStayLeft");
@@ -321,11 +330,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
}
}
- if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)
- {
- NetworkTask task = new NetworkTask(id, Pos);
- AppManager.Instance.NetworkTasks.Add(task);
- }
}
public void MoveDown()
{
@@ -333,13 +337,89 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
isOnGround = false;
}
- public class Bullet : GameObjects.LivingEntity
+ public class Bullet : LivingEntity
{
public Bullet(Vector2 position) : base(position)
{
+ Height = 5;
+ Width = 5;
+ }
+ protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft" }, "playerMoveLeft");
+ Vector2 direction;
+ Vector2 maindirection;
+ public void ShootUpRight()
+ {
+ direction = new Vector2(1, -1);
+ acceleration = Vector2.Zero;
+ velocity = new Vector2(10, 10) * direction;
+ maindirection = velocity;
+ if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
+ {
+ NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
+ AppManager.Instance.NetworkTasks.Add(task);
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ }
+ public void ShootRight()
+ {
+ direction = new Vector2(1, 0);
+ acceleration = Vector2.Zero;
+ velocity = new Vector2(10, 10) * direction;
+ maindirection = velocity;
+ if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
+ {
+ NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
+ AppManager.Instance.NetworkTasks.Add(task);
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ }
+ public void ShootLeft()
+ {
+ direction = new Vector2(-1, 0);
+ acceleration = Vector2.Zero;
+ velocity = new Vector2(10, 10) * direction;
+ maindirection = velocity;
+ if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
+ {
+ NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
+ AppManager.Instance.NetworkTasks.Add(task);
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ }
+ public void ShootUpLeft()
+ {
+ direction = new Vector2(-1, -1);
+ acceleration = Vector2.Zero;
+ velocity = new Vector2(10, 10) * direction;
+ maindirection = velocity;
+ if (AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Client)
+ {
+ NetworkTask task = new NetworkTask(typeof(Bullet), Pos, id, velocity);
+ AppManager.Instance.NetworkTasks.Add(task);
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ }
+ public override void OnCollision(GameObject gameObject)
+ {
+ if (gameObject is not Player)
+ {
+ if (gameObject is CoreEnemy)
+ {
+ CoreEnemy enemy = (CoreEnemy)gameObject;
+ enemy.TakeDamage();
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ base.OnCollision(gameObject);
+ }
+ }
+ public override void Update(GameTime gameTime)
+ {
+ if (maindirection != velocity)
+ {
+ AppManager.Instance.GameManager.Remove(this);
+ }
+ base.Update(gameTime);
}
- protected override GraphicsComponent GraphicsComponent { get; } = new("ZombieMoveLeft");
-
}
}
-}
+}
\ No newline at end of file
diff --git a/DangerousD/GameCore/GameObjects/LivingEntity.cs b/DangerousD/GameCore/GameObjects/LivingEntity.cs
index 78ea17c..72d61f4 100644
--- a/DangerousD/GameCore/GameObjects/LivingEntity.cs
+++ b/DangerousD/GameCore/GameObjects/LivingEntity.cs
@@ -10,6 +10,8 @@ public abstract class LivingEntity : Entity
public Vector2 velocity;
public Vector2 acceleration;
+ public Vector2 Acceleration { get; private set; }
+
public LivingEntity(Vector2 position) : base(position)
{
acceleration = new Vector2(0, 30);
diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs
index 2aa6f40..62c57b8 100644
--- a/DangerousD/GameCore/Managers/AppManager.cs
+++ b/DangerousD/GameCore/Managers/AppManager.cs
@@ -23,7 +23,7 @@ namespace DangerousD.GameCore
public class AppManager : Game
{
public static AppManager Instance { get; private set; }
- public string IpAddress { get; private set; } = "127.0.0.1";
+ public string IpAddress { get; private set; } = "0.0.0.0";
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public GameState gameState { get; private set; }
@@ -39,7 +39,7 @@ namespace DangerousD.GameCore
IDrawableObject HUD;
public DebugHUD DebugHUD;
public List NetworkTasks = new List();
-
+ public string currentMap;
public GameManager GameManager { get; private set; } = new();
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
@@ -77,6 +77,7 @@ namespace DangerousD.GameCore
DebugHUD = new DebugHUD();
UIManager.resolution = resolution;
UIManager.resolutionInGame = inGameResolution;
+ currentMap = "lvl";
}
protected override void Initialize()
@@ -139,6 +140,7 @@ namespace DangerousD.GameCore
case GameState.Game:
HUD.Update(gameTime);
GameManager.Update(gameTime);
+
break;
default:
break;
@@ -206,7 +208,7 @@ namespace DangerousD.GameCore
case GameState.Lobby:
break;
case GameState.Game:
- GameManager.mapManager.LoadLevel("lvl");
+ GameManager.mapManager.LoadLevel(currentMap);
GameManager.FindBorders();
break;
case GameState.Death:
@@ -218,6 +220,7 @@ namespace DangerousD.GameCore
public void NetworkSync(List networkTasks)
{
+ DebugHUD.Log("networksync");
foreach (NetworkTask networkTask in networkTasks)
{
switch (networkTask.operation)
@@ -233,6 +236,12 @@ namespace DangerousD.GameCore
SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos);
break;
case NetworkTaskOperationEnum.CreateEntity:
+ if (networkTask.type == typeof(Player.Bullet))
+ {
+ Player.Bullet bullet = new Player.Bullet(networkTask.position);
+ bullet.id = networkTask.objId;
+ bullet.velocity = networkTask.velocity;
+ }
break;
case NetworkTaskOperationEnum.SendPosition:
if (networkTask.objId != GameManager.GetPlayer1.id )
@@ -322,5 +331,11 @@ namespace DangerousD.GameCore
_graphics.IsFullScreen = fullscrin;
_graphics.ApplyChanges();
}
+ public void Restart(string map)
+ {
+ GameManager = new();
+ ChangeGameState(GameState.Menu);
+ currentMap = map;
+ }
}
}
diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs
index b7a6f84..79fd32d 100644
--- a/DangerousD/GameCore/Managers/GameManager.cs
+++ b/DangerousD/GameCore/Managers/GameManager.cs
@@ -30,6 +30,9 @@ namespace DangerousD.GameCore
public List otherObjects = new();
public Vector4 CameraBorder;
public Player GetPlayer1 { get; private set; }
+ private int _lastUpdate = 0;
+ private int _currTime = 0;
+
public GameManager()
{
others = new List();
@@ -130,10 +133,16 @@ namespace DangerousD.GameCore
public void Update(GameTime gameTime)
{
+ _currTime += gameTime.ElapsedGameTime.Milliseconds;
if (AppManager.Instance.NetworkTasks.Count > 0)
{
- AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList());
- AppManager.Instance.NetworkTasks.Clear();
+ if (_currTime - _lastUpdate > 50)
+ {
+ AppManager.Instance.DebugHUD.Log("sending");
+ AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList());
+ AppManager.Instance.NetworkTasks.Clear();
+ _lastUpdate = _currTime;
+ }
}
foreach (var item in BackgroundObjects)
item.Update(gameTime);
@@ -194,5 +203,10 @@ namespace DangerousD.GameCore
}
}
}
+
+ public Player GetClosestPlayer(Vector2 position)
+ {
+ return players.OrderBy(x => (x.Pos - position).Length()).First();
+ }
}
}
\ No newline at end of file
diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs
index 9087d97..222b897 100644
--- a/DangerousD/GameCore/Managers/MapManager.cs
+++ b/DangerousD/GameCore/Managers/MapManager.cs
@@ -41,7 +41,7 @@ namespace DangerousD.GameCore.Managers
{
InstantiateTiles(layer, tileSize);
}
-
+
foreach (XmlNode layer in xml.DocumentElement.SelectNodes("objectgroup"))
{
InstantiateEntities(layer);
@@ -91,16 +91,20 @@ namespace DangerousD.GameCore.Managers
private void InstantiateEntities(XmlNode group)
{
- string entityGroup = group.Attributes["class"] is not null ? group.Attributes["class"].Value : "";
+ string entityGroup = group.Attributes["class"] is not null ? "." + group.Attributes["class"].Value : "";
+ Debug.Write(entityGroup);
float offsetX = group.Attributes["offsetx"] is not null ? float.Parse(group.Attributes["offsetx"].Value) : 0;
float offsetY = group.Attributes["offsety"] is not null ? float.Parse(group.Attributes["offsety"].Value) : 0;
+
foreach (XmlNode entity in group.ChildNodes)
{
string entityType = entity.Attributes["type"] is not null ? "." + entity.Attributes["type"].Value : "";
- Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityGroup}{entityType}");
+ Type type = Type.GetType($"DangerousD.GameCore.GameObjects{entityGroup}{entityType}");
+
Vector2 pos =
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)))
{
@@ -111,6 +115,30 @@ namespace DangerousD.GameCore.Managers
int gid = entity.Attributes["gid"] is not null ? int.Parse(entity.Attributes["gid"].Value) : 0;
inst = (Entity)Activator.CreateInstance(type, pos, new Vector2(32, 48), new Rectangle((gid - 872)*32, 0, 32, 48));
}
+ else if (type.Equals(typeof(TeleportingDoor)))
+ {
+ int gid = entity.Attributes["gid"] is not null ? int.Parse(entity.Attributes["gid"].Value) : 0;
+ XmlNode node = entity.SelectSingleNode("properties/property[@name = 'nextLevel']");
+
+ bool resetLevel = node is not null ? bool.Parse(node.Attributes["value"].Value) : false;
+ if (resetLevel)
+ {
+ inst = (Entity)Activator.CreateInstance(type, pos, new Vector2(32, 48), new Rectangle((gid - 872) * 32, 0, 32, 48),
+ new Vector2(0,0),
+ () => { });
+ }
+ else
+ {
+ node = entity.SelectSingleNode("properties/property[@name = 'destination']");
+ string target = node is not null ? node.Attributes["value"].Value : "0";
+ XmlNode dest = group.SelectSingleNode($"object[@id = '{target}']");
+
+ inst = (Entity)Activator.CreateInstance(type, pos, new Vector2(32, 48), new Rectangle((gid - 872) * 32, 0, 32, 48),
+ new Vector2(float.Parse(dest.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX,
+ float.Parse(dest.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale,
+ () => { });
+ }
+ }
else
{
inst = (Entity)Activator.CreateInstance(type, pos);
diff --git a/DangerousD/GameCore/Network/NetworkManager.cs b/DangerousD/GameCore/Network/NetworkManager.cs
index 56ac3a1..41b48f1 100644
--- a/DangerousD/GameCore/Network/NetworkManager.cs
+++ b/DangerousD/GameCore/Network/NetworkManager.cs
@@ -21,27 +21,19 @@ namespace DangerousD.GameCore.Network
private void Init(string IpAddress)
{
- try
- {
- socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- IPAddress address = IPAddress.Parse(IpAddress);
- int port = 51873;
- endPoint = new IPEndPoint(address, port);
- }
- catch { }
+ socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ IPAddress address = IPAddress.Parse(IpAddress);
+ int port = 51873;
+ endPoint = new IPEndPoint(address, port);
}
private void AcceptSockets()
{
while (true)
{
- try
- {
- Socket clientSocket = socket.Accept();
- clientSockets.Add(clientSocket);
- Thread receiveThread = new Thread(BeginHostReceive);
- receiveThread.Start(clientSocket);
- }
- catch { }
+ Socket clientSocket = socket.Accept();
+ clientSockets.Add(clientSocket);
+ Thread receiveThread = new Thread(BeginHostReceive);
+ receiveThread.Start(clientSocket);
}
}
@@ -50,46 +42,41 @@ namespace DangerousD.GameCore.Network
Socket clientSocket = clSocket as Socket;
while (clientSocket != null)
{
- try
+ byte[] bytesCount = new byte[4];
+ clientSocket.Receive(bytesCount);
+ int length = BitConverter.ToInt32(bytesCount);
+ byte[] Data = new byte[length];
+ StateObject so = new StateObject(clientSocket, Data);
+ while (so.UploadedBytesCount < length)
{
- byte[] bytesCount = new byte[4];
- clientSocket.Receive(bytesCount);
- byte[] Data = new byte[BitConverter.ToInt32(bytesCount)];
- StateObject so = new StateObject(clientSocket, Data);
- IAsyncResult count = clientSocket.BeginReceive(so.buffer, 0, so.bufferSize, SocketFlags.None, AsyncReceiveCallback, so);
+ int count = clientSocket.Receive(so.buffer, so.UploadedBytesCount, length - so.UploadedBytesCount, SocketFlags.None);
+ so.UploadedBytesCount += count;
}
- catch { }
+ List tasks = JsonConvert.DeserializeObject>(Encoding.Unicode.GetString(so.buffer, 0, length));
+ GetReceivingMessages(tasks);
}
}
public void HostInit(string IpAddress)
{
- try
- {
- Init(IpAddress);
- socket.Bind(endPoint);
- socket.Listen(4);
- Thread acceptThread = new Thread(AcceptSockets);
- acceptThread.Start();
- state = "Host";
- AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.Host);
- }
- catch { }
+ Init(IpAddress);
+ socket.Bind(endPoint);
+ socket.Listen(4);
+ Thread acceptThread = new Thread(AcceptSockets);
+ acceptThread.Start();
+ state = "Host";
+ AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.Host);
}
public void ClientInit(string IpAddress)
{
- try
- {
- Init(IpAddress);
- socket.Connect(endPoint);
- state = "Client";
- Thread.Sleep(10);
- Thread ReceivingThread = new Thread(ReceiveMsgFromHost);
- ReceivingThread.Start();
- NetworkTask connectionTask = new NetworkTask("Player");
- AppManager.Instance.NetworkTasks.Add(connectionTask);
- AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.Client);
- }
- catch { }
+ Init(IpAddress);
+ socket.Connect(endPoint);
+ state = "Client";
+ Thread.Sleep(10);
+ Thread ReceivingThread = new Thread(ReceiveMsgFromHost);
+ ReceivingThread.Start();
+ NetworkTask connectionTask = new NetworkTask("Player");
+ AppManager.Instance.NetworkTasks.Add(connectionTask);
+ AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.Client);
}
public void SendMsg(List networkTask, Socket ignoreSocket = null)
{
@@ -97,65 +84,38 @@ namespace DangerousD.GameCore.Network
int count = Data.Length;
if (state == "Host")
{
- try
+ foreach (Socket socket in clientSockets)
{
- foreach (Socket socket in clientSockets)
+ if (!(socket == ignoreSocket))
{
- if (!(socket == ignoreSocket))
- {
- socket.Send(BitConverter.GetBytes(count));
- socket.Send(Data);
- }
+ socket.Send(BitConverter.GetBytes(count));
+ socket.Send(Data);
}
}
- catch { }
}
else
{
- try
- {
- socket.Send(BitConverter.GetBytes(count));
- socket.Send(Data);
- }
- catch { }
+ socket.Send(BitConverter.GetBytes(count));
+ socket.Send(Data);
}
}
private void ReceiveMsgFromHost()
{
while (true)
{
- try
+ byte[] bytesCount = new byte[4];
+ socket.Receive(bytesCount);
+ int length = BitConverter.ToInt32(bytesCount);
+ byte[] Data = new byte[length];
+ StateObject so = new StateObject(socket, Data);
+ while (so.UploadedBytesCount < length)
{
- byte[] bytesCount = new byte[4];
- socket.Receive(bytesCount);
- byte[] Data = new byte[BitConverter.ToInt32(bytesCount)];
- StateObject so = new StateObject(socket, Data);
- IAsyncResult count = socket.BeginReceive(so.buffer, 0, so.bufferSize, SocketFlags.None, AsyncReceiveCallback, so);
+ int count = socket.Receive(so.buffer, so.UploadedBytesCount, length-so.UploadedBytesCount, SocketFlags.None);
+ so.UploadedBytesCount += count;
}
- catch { }
+ List tasks = JsonConvert.DeserializeObject>(Encoding.Unicode.GetString(so.buffer, 0, length));
+ GetReceivingMessages(tasks);
}
}
-
- private void AsyncReceiveCallback(IAsyncResult ar)
- {
- try
- {
- StateObject so = ar.AsyncState as StateObject;
- Socket clientSocket = so.workSocket;
- int readCount = clientSocket.EndReceive(ar);
- so.UploadedBytesCount += readCount;
- so.sb.Append(Encoding.Unicode.GetString(so.buffer, 0, readCount));
- if (so.UploadedBytesCount < so.bufferSize)
- {
- clientSocket.BeginReceive(so.buffer, 0, so.bufferSize, SocketFlags.None, new AsyncCallback(AsyncReceiveCallback), so);
- }
- else
- {
- List tasks = JsonConvert.DeserializeObject>(so.sb.ToString());
- GetReceivingMessages(tasks);
- }
- }
- catch { }
- }
}
}
diff --git a/DangerousD/GameCore/Network/NetworkTask.cs b/DangerousD/GameCore/Network/NetworkTask.cs
index f9b6072..17bf92b 100644
--- a/DangerousD/GameCore/Network/NetworkTask.cs
+++ b/DangerousD/GameCore/Network/NetworkTask.cs
@@ -38,11 +38,12 @@ namespace DangerousD.GameCore.Network
///
///
///
- public NetworkTask(Type EntityType, Vector2 EntityPosition, int ParentId)
+ public NetworkTask(Type EntityType, Vector2 EntityPosition, int ParentId, Vector2 velocity)
{
operation = NetworkTaskOperationEnum.CreateEntity;
type = EntityType;
position = EntityPosition;
+ this.velocity = velocity;
objId = ParentId;
}
diff --git a/DangerousD/GameCore/Network/StateObject.cs b/DangerousD/GameCore/Network/StateObject.cs
index f98170b..3648ad1 100644
--- a/DangerousD/GameCore/Network/StateObject.cs
+++ b/DangerousD/GameCore/Network/StateObject.cs
@@ -12,7 +12,6 @@ namespace DangerousD.GameCore.Network
public Socket workSocket;
public int bufferSize;
public byte[] buffer;
- public StringBuilder sb = new StringBuilder();
public int UploadedBytesCount;
public StateObject(Socket socket, byte[] buffer)