Merge branch 'main' into MapManager

This commit is contained in:
Mootfrost777 2023-08-16 19:29:16 +03:00
commit e7e18468f4
26 changed files with 527 additions and 84 deletions

View file

@ -11,7 +11,7 @@ with.
<!-- <!--
Modify this string to change the font that will be imported. Modify this string to change the font that will be imported.
--> -->
<FontName>Handjet-ExtraLight.ttf</FontName> <FontName>RubikWetPaint-Regular.ttf</FontName>
<!-- <!--
Size is a float value, measured in points. Modify this value to change Size is a float value, measured in points. Modify this value to change

Binary file not shown.

View file

@ -26,12 +26,13 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:animation1.png /build:animation1.png
#begin File.spritefont
#begin ButtonFont.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True /processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:File.spritefont /build:ButtonFont.spritefont
#begin Font_25.spritefont #begin Font_25.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
@ -40,6 +41,13 @@
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:Font_25.spritefont /build:Font_25.spritefont
#begin Font_30.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Font_30.spritefont
#begin Font2.spritefont #begin Font2.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
@ -47,6 +55,7 @@
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:Font2.spritefont /build:Font2.spritefont
#begin MonstersAnimations.png #begin MonstersAnimations.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -59,6 +68,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:MonstersAnimations.png /build:MonstersAnimations.png
#begin menuFon.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:menuFon.jpg
#begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png #begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

Binary file not shown.

View file

@ -1 +1 @@
{"id":"ZombieLeftAttack","textureName":"animation1","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":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"}

View file

@ -1 +1 @@
{"id":"ZombieMoveLeft","textureName":"animation1","startSpriteRectangle":{"X":1,"Y":50,"Width":24,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":4,"isCycle":true} {"id":"ZombieMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":50,"Width":24,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":4,"isCycle":true}

View file

@ -1 +1 @@
{"id":"ZombieRightAttack","textureName":"animation1","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":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

View file

@ -26,7 +26,7 @@ public abstract class AbstractGui : IDrawableObject
public virtual void LoadContent() public virtual void LoadContent()
{ {
Manager.LoadContent(AppManager.Instance.Content, "Font"); Manager.LoadContent(AppManager.Instance.Content, "Font2");
} }
public virtual void Update(GameTime gameTime) public virtual void Update(GameTime gameTime)

View file

@ -0,0 +1,117 @@
using Microsoft.Xna.Framework;
using MonogameLibrary.UI.Elements;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DangerousD.GameCore.GUI
{
class LobbyGUI : AbstractGui
{
public LobbyGUI()
{
}
protected override void CreateUI()
{
int screenWidth = AppManager.Instance.resolution.X;
int screenHeight = AppManager.Instance.resolution.Y;
// CheckBoxs
Elements.Add(new Label(Manager) { rectangle = new Rectangle(screenWidth / 30 * 2, screenHeight / 30 * 5,
screenWidth / 30 * 26, screenHeight / 15 * 10) });
// Buttons
{
Button backButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 30, screenHeight / 30, 60, 50),
text = "<-",
scale = 0.3f,
fontColor = Color.Black,
fontName = "font2"
};
backButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Menu);
};
Button hostButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 30, screenHeight / 15 * 13, 120, 50),
text = "Host",
scale = 0.2f,
fontColor = Color.Black,
fontName = "font2"
};
hostButton.LeftButtonPressed += () => {
};
Button refreshButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 30 * 6, screenHeight / 15 * 13, 120, 50),
text = "Refresh",
scale = 0.2f,
fontColor = Color.Black,
fontName = "font2"
};
refreshButton.LeftButtonPressed += () => {
};
Button joinSelectedButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 30 * 25, screenHeight / 15 * 13, 120, 50),
text = "Join",
scale = 0.2f,
fontColor = Color.Black,
fontName = "font2"
};
joinSelectedButton.LeftButtonPressed += () => {
};
Button joinByIpButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 30 * 25, screenHeight / 30, 120, 50),
text = "JoinByIp",
scale = 0.2f,
fontColor = Color.Black,
fontName = "font2"
};
joinByIpButton.LeftButtonPressed += () => {
};
}
// SearchBar
{
TextBox searchBarTextBox = new TextBox(Manager) {
rectangle = new Rectangle(screenWidth / 30 * 14, screenHeight / 30,
screenWidth / 30 * 10, screenHeight / 30 * 3),
text = "ip",
scale = 0.16f,
fontColor = Color.Gray,
fontName = "font2",
textAligment = TextAligment.Left
};
searchBarTextBox.TextChanged += input => {
if (searchBarTextBox.fontColor == Color.Gray)
{
searchBarTextBox.text = ""; searchBarTextBox.fontColor = Color.Black;
}
};
searchBarTextBox.StopChanging += input => {
if (input.Length == 0)
{
searchBarTextBox.fontColor = Color.Gray;
searchBarTextBox.text = "ip";
}
};
}
}
}
}

View file

@ -12,6 +12,12 @@ namespace DangerousD.GameCore.GUI
{ {
class LoginGUI : AbstractGui class LoginGUI : AbstractGui
{ {
private string username;
private string password;
public string Username { get => username; }
public string Password { get => password; }
protected override void CreateUI() protected override void CreateUI()
{ {
int screenWidth = AppManager.Instance.resolution.X; int screenWidth = AppManager.Instance.resolution.X;
@ -34,7 +40,7 @@ namespace DangerousD.GameCore.GUI
text = "NickName", text = "NickName",
scale = 0.16f, scale = 0.16f,
fontColor = Color.Gray, fontColor = Color.Gray,
fontName = "font2", fontName = "Font2",
textAligment = TextAligment.Left textAligment = TextAligment.Left
}; };
loginTextBox.TextChanged += input => { loginTextBox.TextChanged += input => {
@ -43,6 +49,13 @@ namespace DangerousD.GameCore.GUI
loginTextBox.text = ""; loginTextBox.fontColor = Color.Black; loginTextBox.text = ""; loginTextBox.fontColor = Color.Black;
} }
}; };
loginTextBox.StopChanging += input => {
if (input.Length == 0)
{
loginTextBox.text = "NickName";
loginTextBox.fontColor = Color.Gray;
}
};
TextBox passwordTextBox = new TextBox(Manager) TextBox passwordTextBox = new TextBox(Manager)
{ {
@ -59,6 +72,13 @@ namespace DangerousD.GameCore.GUI
passwordTextBox.text = ""; passwordTextBox.fontColor = Color.Black; passwordTextBox.text = ""; passwordTextBox.fontColor = Color.Black;
} }
}; };
passwordTextBox.StopChanging += input => {
if (input.Length == 0)
{
passwordTextBox.text = "Password";
passwordTextBox.fontColor = Color.Gray;
}
};
} }
// Кнопки // Кнопки
@ -71,7 +91,10 @@ namespace DangerousD.GameCore.GUI
fontName = "font2" fontName = "font2"
}; };
logButton.LeftButtonPressed += () => { logButton.LeftButtonPressed += () => {
if (CheckUser())
{
AppManager.Instance.ChangeGameState(GameState.Lobby); AppManager.Instance.ChangeGameState(GameState.Lobby);
}
}; };
Button regButton = new Button(Manager) Button regButton = new Button(Manager)
@ -102,5 +125,9 @@ namespace DangerousD.GameCore.GUI
{ {
// TODO // TODO
} }
private bool CheckUser()
{
return true;
}
} }
} }

View file

@ -1,6 +1,8 @@
using DangerousD.GameCore.Managers; using DangerousD.GameCore.Managers;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements; using MonogameLibrary.UI.Elements;
using System.Diagnostics;
namespace DangerousD.GameCore.GUI; namespace DangerousD.GameCore.GUI;
@ -10,29 +12,39 @@ internal class MenuGUI : AbstractGui
{ {
int wigth = AppManager.Instance.Window.ClientBounds.Width; int wigth = AppManager.Instance.Window.ClientBounds.Width;
int height = AppManager.Instance.Window.ClientBounds.Height; int height = AppManager.Instance.Window.ClientBounds.Height;
var butSingle = new Button(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 130, 300, 50), text = "Singleplayer", fontName = "File" }; 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 });
var butSingle = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 130, 300, 50), text = "Singleplayer", fontName = "ButtonFont" };
Elements.Add(butSingle); Elements.Add(butSingle);
butSingle.LeftButtonPressed += () => butSingle.LeftButtonPressed += () =>
{ {
AppManager.Instance.ChangeGameState(GameState.Game); AppManager.Instance.ChangeGameState(GameState.Game);
}; };
var butMulti = new Button(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 190, 300, 50), text = "Multiplayer", fontName = "File" }; var butMulti = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 190, 300, 50), text = "Multiplayer", fontName = "ButtonFont" };
Elements.Add(butMulti); Elements.Add(butMulti);
butMulti.LeftButtonPressed += () => butMulti.LeftButtonPressed += () =>
{ {
AppManager.Instance.ChangeGameState(GameState.Login); AppManager.Instance.ChangeGameState(GameState.Login);
}; };
var butOption = new Button(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 250, 300, 50), text = "Option", fontName = "File" }; var butOption = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 250, 300, 50), text = "Option", fontName = "ButtonFont" };
Elements.Add(butOption); Elements.Add(butOption);
butOption.LeftButtonPressed += () => butOption.LeftButtonPressed += () =>
{ {
// открытие настроек // открытие настроек
}; };
var butExit = new Button(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 310, 300, 50), text = "Exit", fontName = "File" }; var butExit = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 310, 300, 50), text = "Exit", fontName = "ButtonFont" };
Elements.Add(butExit); Elements.Add(butExit);
butExit.LeftButtonPressed += () => butExit.LeftButtonPressed += () =>
{ {
AppManager.Instance.Exit(); AppManager.Instance.Exit();
}; };
} }
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
} }

View file

@ -30,7 +30,7 @@ namespace DangerousD.GameCore
AppManager.Instance.GameManager.Register(this); AppManager.Instance.GameManager.Register(this);
} }
public virtual void OnCollision() public virtual void OnCollision(GameObject gameObject)
{ {
} }
@ -48,9 +48,12 @@ namespace DangerousD.GameCore
GraphicsComponent.Update(); GraphicsComponent.Update();
} }
public static Texture2D debugTexture;
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
{ {
GraphicsComponent.DrawAnimation(Rectangle, spriteBatch); GraphicsComponent.DrawAnimation(Rectangle, spriteBatch);
//debug
// spriteBatch.Draw(debugTexture, Rectangle, Color.White);
} }
} }
} }

View file

@ -15,10 +15,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
private bool isGoRight = false; private bool isGoRight = false;
public Frank(Vector2 position) : base(position) public Frank(Vector2 position) : base(position)
{ {
Width = 56; Width = 112;
Height = 80; Height = 160;
GraphicsComponent.StartAnimation("FrankMoveLeft"); GraphicsComponent.StartAnimation("FrankMoveLeft");
monster_speed = 50; monster_speed = 1;
name = "Фрэнк";
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight");
@ -34,11 +35,17 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
{ {
/* if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20)
{
player.Death(name);
} */
if (isGoRight) if (isGoRight)
{ {
if (GraphicsComponent.GetCurrentAnimation != "FrankMoveRight") if (GraphicsComponent.GetCurrentAnimation != "FrankMoveRight")
{ {
GraphicsComponent.StartAnimation("FrankMoveRight"); GraphicsComponent.StartAnimation("FrankMoveRight");
velocity = new Vector2(monster_speed, 0);
} }
} }
else if (!isGoRight) else if (!isGoRight)
@ -46,7 +53,17 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (GraphicsComponent.GetCurrentAnimation != "FrankMoveLeft") if (GraphicsComponent.GetCurrentAnimation != "FrankMoveLeft")
{ {
GraphicsComponent.StartAnimation("FrankMoveLeft"); GraphicsComponent.StartAnimation("FrankMoveLeft");
} velocity = new Vector2(-monster_speed, 0);
}
}
if (_pos.X <= 1)
{
isGoRight = true;
}
else if (_pos.X >= 500)
{
isGoRight = false;
} }
} }
} }

View file

@ -48,13 +48,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
if (isGoRight) if (isGoRight)
{ {
GraphicsComponent.StopAnimation(); if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack")
GraphicsComponent.StartAnimation("ZombieRightAttack"); GraphicsComponent.StartAnimation("ZombieRightAttack");
AppManager.Instance.GameManager.players[0].Death(name); AppManager.Instance.GameManager.players[0].Death(name);
} }
else if (!isGoRight) else if (!isGoRight)
{ {
GraphicsComponent.StopAnimation(); if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack")
GraphicsComponent.StartAnimation("ZombieLeftAttack"); GraphicsComponent.StartAnimation("ZombieLeftAttack");
AppManager.Instance.GameManager.players[0].Death(name); AppManager.Instance.GameManager.players[0].Death(name);
} }
@ -72,14 +72,14 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
GraphicsComponent.StartAnimation("ZombieMoveRight"); GraphicsComponent.StartAnimation("ZombieMoveRight");
velocity = new Vector2(monster_speed, 0); velocity.X = monster_speed;
} }
else if (!isGoRight) else if (!isGoRight)
{ {
if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
GraphicsComponent.StartAnimation("ZombieMoveLeft"); GraphicsComponent.StartAnimation("ZombieMoveLeft");
velocity = new Vector2(-monster_speed, 0); velocity.X = -monster_speed;
} }
} }

View file

@ -9,7 +9,7 @@ public abstract class LivingEntity : Entity
public Vector2 acceleration; public Vector2 acceleration;
public LivingEntity(Vector2 position) : base(position) public LivingEntity(Vector2 position) : base(position)
{ {
acceleration = new Vector2(0, 10); acceleration = new Vector2(0, 30);
} }
public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine

View file

@ -146,6 +146,28 @@ namespace DangerousD.GameCore.Graphics
} }
_spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White);
}
public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
{
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
float scale;
if (currentAnimation.Offset.X != 0)
{
destinationRectangle.X -= (int)currentAnimation.Offset.X;
scale = destinationRectangle.Height / sourceRectangle.Height;
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
}
else if (currentAnimation.Offset.Y != 0)
{
destinationRectangle.Y -= (int)currentAnimation.Offset.Y;
scale = destinationRectangle.Width / sourceRectangle.Width;
destinationRectangle.Height = (int)(sourceRectangle.Height * scale);
}
_spriteBatch.Draw(texture, _spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White); destinationRectangle, sourceRectangle, Color.White);
} }

View file

@ -7,6 +7,7 @@ using System.Text;
using DangerousD.GameCore.GUI; using DangerousD.GameCore.GUI;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using DangerousD.GameCore.Graphics; using DangerousD.GameCore.Graphics;
using DangerousD.GameCore.Network;
namespace DangerousD.GameCore namespace DangerousD.GameCore
{ {
@ -23,8 +24,9 @@ namespace DangerousD.GameCore
IDrawableObject LoginGUI; IDrawableObject LoginGUI;
IDrawableObject LobbyGUI; IDrawableObject LobbyGUI;
public GameManager GameManager { get; private set; } public GameManager GameManager { get; private set; } = new GameManager();
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder(); public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
public AppManager() public AppManager()
{ {
Instance = this; Instance = this;
@ -34,10 +36,10 @@ namespace DangerousD.GameCore
TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30); TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30);
resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight);
GameManager = new GameManager();
gameState = GameState.Menu; gameState = GameState.Menu;
MenuGUI = new MenuGUI(); MenuGUI = new MenuGUI();
LoginGUI = new LoginGUI(); LoginGUI = new LoginGUI();
LobbyGUI = new LobbyGUI();
} }
protected override void Initialize() protected override void Initialize()
@ -45,6 +47,7 @@ namespace DangerousD.GameCore
AnimationBuilder.LoadAnimations(); AnimationBuilder.LoadAnimations();
MenuGUI.Initialize(GraphicsDevice); MenuGUI.Initialize(GraphicsDevice);
LoginGUI.Initialize(GraphicsDevice); LoginGUI.Initialize(GraphicsDevice);
LobbyGUI.Initialize(GraphicsDevice);
base.Initialize(); base.Initialize();
} }
@ -53,6 +56,9 @@ namespace DangerousD.GameCore
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
MenuGUI.LoadContent(); MenuGUI.LoadContent();
LoginGUI.LoadContent(); LoginGUI.LoadContent();
LobbyGUI.LoadContent();
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
} }
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)

View file

@ -20,12 +20,6 @@ namespace DangerousD.GameCore.Managers
item.velocity = item.velocity + item.acceleration * delta; item.velocity = item.velocity + item.acceleration * delta;
} }
//SD setting positions before check
foreach (var item in livingEntities)
{
item.SetPosition(item.Pos + item.velocity);
}
CheckCollisions(livingEntities, mapObjects); CheckCollisions(livingEntities, mapObjects);
OnCollision(entities, livingEntities); OnCollision(entities, livingEntities);
OnCollision(livingEntities); OnCollision(livingEntities);
@ -44,38 +38,65 @@ namespace DangerousD.GameCore.Managers
{ {
for (int i = 0; i < livingEntities.Count; i++) for (int i = 0; i < livingEntities.Count; i++)
{ {
var currentEntity = livingEntities[i];
Rectangle oldRect = currentEntity.Rectangle;
bool isXNormalise = true;
bool isYNormalise = true;
oldRect.Offset((int)currentEntity.velocity.X / 2, 0);
for (int j = 0; j < mapObjects.Count; j++) for (int j = 0; j < mapObjects.Count; j++)
{ {
if (livingEntities[i].Rectangle.Intersects(mapObjects[j].Rectangle)) if (oldRect.Intersects(mapObjects[j].Rectangle))
{
if (livingEntities[i].Rectangle.Right > mapObjects[j].Rectangle.Left)
{ {
isXNormalise = false;
oldRect.Offset(-(int)currentEntity.velocity.X / 2, 0);
break;
}
//livingEntities[i].SetPosition(livingEntities[i].Pos- new Vector2(livingEntities[i].velocity.X));
livingEntities[i].velocity.X = 0;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X - (livingEntities[i].Rectangle.Right - mapObjects[j].Rectangle.Left),
livingEntities[i].Pos.Y));
} }
if (livingEntities[i].Rectangle.Left < mapObjects[j].Rectangle.Right) if (isXNormalise)
{ {
livingEntities[i].velocity.X = 0; oldRect.Offset((int)currentEntity.velocity.X / 2, 0);
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X + mapObjects[j].Rectangle.Right - livingEntities[i].Rectangle.Left, for (int j = 0; j < mapObjects.Count; j++)
livingEntities[i].Pos.Y));
}
if (livingEntities[i].Rectangle.Bottom > mapObjects[j].Rectangle.Top)
{ {
livingEntities[i].velocity.Y = 0; if (oldRect.Intersects(mapObjects[j].Rectangle))
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X,
livingEntities[i].Pos.Y - (livingEntities[i].Rectangle.Bottom - mapObjects[j].Rectangle.Top)));
}
if (livingEntities[i].Rectangle.Top < mapObjects[j].Rectangle.Bottom)
{ {
livingEntities[i].velocity.Y = 0; isXNormalise = false;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X, oldRect.Offset(-(int)currentEntity.velocity.X / 2, 0);
livingEntities[i].Pos.Y + (mapObjects[j].Rectangle.Bottom - livingEntities[i].Rectangle.Top))); break;
} }
} }
} }
if (!isXNormalise)
currentEntity.velocity.X = 0;
oldRect.Offset(0, (int)currentEntity.velocity.Y/2);
for (int j = 0; j < mapObjects.Count; j++)
{
if (oldRect.Intersects(mapObjects[j].Rectangle))
{
isYNormalise = false;
oldRect.Offset(0, -(int)currentEntity.velocity.Y / 2);
break;
}
}
if (isYNormalise)
{
oldRect.Offset(0, (int)currentEntity.velocity.Y / 2);
for (int j = 0; j < mapObjects.Count; j++)
{
if (oldRect.Intersects(mapObjects[j].Rectangle))
{
isYNormalise = false;
oldRect.Offset(0, -(int)currentEntity.velocity.Y / 2);
break;
}
}
}
if (!isYNormalise)
currentEntity.velocity.Y = 0;
currentEntity.SetPosition(new Vector2(oldRect.X, oldRect.Y));
} }
} }
@ -87,8 +108,8 @@ namespace DangerousD.GameCore.Managers
{ {
if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle)) if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle))
{ {
livingEntities[j].OnCollision(); livingEntities[j].OnCollision(entities[i]);
entities[i].OnCollision(); entities[i].OnCollision(livingEntities[j]);
} }
} }
} }
@ -102,8 +123,8 @@ namespace DangerousD.GameCore.Managers
{ {
if (livingEntities[i].Rectangle.Intersects(livingEntities[j].Rectangle)) if (livingEntities[i].Rectangle.Intersects(livingEntities[j].Rectangle))
{ {
livingEntities[i].OnCollision(); livingEntities[i].OnCollision(livingEntities[j]);
livingEntities[j].OnCollision(); livingEntities[j].OnCollision(livingEntities[i]);
} }
} }
} }
@ -123,11 +144,30 @@ namespace DangerousD.GameCore.Managers
{ {
rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X); rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X);
rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y); rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y);
}
//if (rectangle.Intersects(GameManager.Rectangle)) for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++)
//{ {
// return game if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
//} {
return AppManager.Instance.GameManager.entities[i];
}
}
for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++)
{
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
{
return AppManager.Instance.GameManager.mapObjects[i];
}
}
for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++)
{
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
{
return AppManager.Instance.GameManager.livingEntities[i];
}
} }
return gameObject; return gameObject;
} }
@ -135,23 +175,35 @@ namespace DangerousD.GameCore.Managers
{ {
Rectangle rectangle; Rectangle rectangle;
Vector2 direction = entity1.Pos - targetCast; Vector2 direction = entity1.Pos - targetCast;
rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y, 1, 1); rectangle = new Rectangle((int)targetCast.X, (int)targetCast.Y, 1, 1);
GameObject gameObject = null;
double k = direction.Length(); double k = direction.Length();
for (int i = 0; i < k; i++) for (int i = 0; i < k; i++)
{ {
rectangle.X = (int)(entity1.Pos.X + (i / k) * direction.X); rectangle.X = (int)(targetCast.X + (i / k) * direction.X);
rectangle.Y = (int)(entity1.Pos.Y + (i / k) * direction.X); rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X);
if (gameObject != null) }
for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++)
{ {
break; if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
return gameObject; {
return AppManager.Instance.GameManager.entities[i];
}
}
for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++)
{
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
{
return AppManager.Instance.GameManager.mapObjects[i];
}
}
for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++)
{
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
{
return AppManager.Instance.GameManager.livingEntities[i];
} }
} }
return null; return null;
} }
} }

View file

@ -4,12 +4,13 @@ using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System; using System;
using Newtonsoft.Json;
namespace DangerousD.GameCore.Network namespace DangerousD.GameCore.Network
{ {
public class NetworkManagerTest public class NetworkManager
{ {
public delegate void ReceivingHandler(string jsonMessage); public delegate void ReceivingHandler(NetworkTask networkTask);
public event ReceivingHandler GetReceivingMessages; public event ReceivingHandler GetReceivingMessages;
@ -68,9 +69,9 @@ namespace DangerousD.GameCore.Network
Thread ReceivingThread = new Thread(ReceiveMsgFromHost); Thread ReceivingThread = new Thread(ReceiveMsgFromHost);
ReceivingThread.Start(); ReceivingThread.Start();
} }
public void SendMsg(string jsonMessage) public void SendMsg(NetworkTask networkTask)
{ {
byte[] Data = Encoding.Unicode.GetBytes(jsonMessage); byte[] Data = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(networkTask));
int count = Data.Length; int count = Data.Length;
if (state == "Host") if (state == "Host")
{ {
@ -111,7 +112,7 @@ namespace DangerousD.GameCore.Network
} }
else else
{ {
GetReceivingMessages(so.sb.ToString()); GetReceivingMessages(JsonConvert.DeserializeObject<NetworkTask>(so.sb.ToString()));
} }
} }
} }

View file

@ -0,0 +1,106 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DangerousD.GameCore.Network
{
[Serializable]
public class NetworkTask
{
public NetworkTaskOperationEnum operation { get; set; }
public string name { get; set; }
public int value { get; set; }
public int objId { get; set; }
public Vector2 position { get; set; }
public Vector2 velocity { get; set; }
public Type type { get; set; }
/// <summary>
/// Нанести урон сущности
/// </summary>
/// <param name="LivingEntityId"></param>
/// <param name="Damage"></param>
public NetworkTask(int LivingEntityId, int Damage)
{
operation = NetworkTaskOperationEnum.TakeDamage;
objId = LivingEntityId;
value = Damage;
}
/// <summary>
/// Проиграть звук на позиции
/// </summary>
/// <param name="SoundPosition"></param>
/// <param name="SoundName"></param>
public NetworkTask(Vector2 SoundPosition, string SoundName)
{
operation = NetworkTaskOperationEnum.SendSound;
position = SoundPosition;
name = SoundName;
}
/// <summary>
/// Создать сущность на позиции с заданной скоростью и присвоить её родительской сущности
/// </summary>
/// <param name="EntityType"></param>
/// <param name="EntityPosition"></param>
/// <param name="EntityVelocity"></param>
/// <param name="ParentId"></param>
public NetworkTask(Type EntityType, Vector2 EntityPosition, Vector2 EntityVelocity, int ParentId)
{
operation = NetworkTaskOperationEnum.CreateEntity;
type = EntityType;
position = EntityPosition;
velocity = EntityVelocity;
objId = ParentId;
}
/// <summary>
/// Изменить позицию сущности со сложной логикой(игрок)
/// </summary>
/// <param name="EntityId"></param>
/// <param name="EntityPosition"></param>
public NetworkTask(int EntityId, Vector2 EntityPosition)
{
operation = NetworkTaskOperationEnum.SendPosition;
objId = EntityId;
position = EntityPosition;
}
/// <summary>
/// Изменяет состояние и/или скорость сущности
/// </summary>
/// <param name="EntityId"></param>
/// <param name="StateName"></param>
/// <param name="EntityVelocity"></param>
public NetworkTask(int EntityId, string StateName, Vector2 EntityVelocity)
{
operation = NetworkTaskOperationEnum.ChangeState;
objId = EntityId;
name = StateName;
velocity = EntityVelocity;
}
/// <summary>
/// Подключается к хосту и передаёт своё имя
/// </summary>
/// <param name="PlayerName"></param>
public NetworkTask(string PlayerName)
{
operation = NetworkTaskOperationEnum.ConnectToHost;
name = PlayerName;
}
/// <summary>
/// Получает id игрока на клиенте от хоста
/// </summary>
/// <param name="PlayerId"></param>
public NetworkTask(int PlayerId)
{
operation = NetworkTaskOperationEnum.GetClientPlayerId;
objId = PlayerId;
}
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DangerousD.GameCore.Network
{
[Serializable]
public enum NetworkTaskOperationEnum
{
TakeDamage, SendSound, CreateEntity, SendPosition, ChangeState, ConnectToHost, GetClientPlayerId
}
}

View file

@ -15,7 +15,7 @@ namespace MonogameLibrary.UI.Base
protected Texture2D texture; protected Texture2D texture;
protected int layerIndex; protected int layerIndex;
protected UIManager Manager; protected UIManager Manager;
protected string textureName; public string textureName;
public Rectangle rectangle = new Rectangle(0, 0, 10, 10); public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
public Color mainColor = Color.White; public Color mainColor = Color.White;

View file

@ -22,7 +22,7 @@ namespace MonogameLibrary.UI.Elements
{ {
} }
public bool InteractUpdate(MouseState mouseState, MouseState prevmouseState) public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
{ {
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero))) if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
{ {
@ -61,11 +61,19 @@ namespace MonogameLibrary.UI.Elements
public override void Draw(SpriteBatch _spriteBatch) public override void Draw(SpriteBatch _spriteBatch)
{ {
if (hoverState == HoverState.None) if (hoverState == HoverState.None)
{
_spriteBatch.Draw(texture, rectangle, Color.White); _spriteBatch.Draw(texture, rectangle, Color.White);
}
else if (hoverState == HoverState.Hovering) else if (hoverState == HoverState.Hovering)
{
_spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211)); _spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211));
}
else else
{
_spriteBatch.Draw(texture, rectangle, new Color(112, 128, 144)); _spriteBatch.Draw(texture, rectangle, new Color(112, 128, 144));
}
DrawText(_spriteBatch); DrawText(_spriteBatch);
} }
} }

View file

@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Enums;
using MonogameLibrary.UI.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using static MonogameLibrary.UI.Elements.Button;
namespace MonogameLibrary.UI.Elements
{
public class ButtonText : Button
{
public ButtonText(UIManager manager, int layerIndex = 0) : base(manager, layerIndex)
{
}
public override void Draw(SpriteBatch _spriteBatch)
{
if (hoverState == HoverState.None)
{
fontColor = Color.White;
}
else if (hoverState == HoverState.Hovering)
{
fontColor = new Color(211, 211, 211);
}
else
{
fontColor = new Color(112, 128, 144);
}
DrawText(_spriteBatch);
}
}
}