Merge pull request #97 from progtime-net/NetworkMultiplyPlayers2
Network multiply players2
This commit is contained in:
commit
bbec3cdc58
10 changed files with 29 additions and 22 deletions
|
@ -18,6 +18,7 @@ namespace MonogameLibrary.UI.Base
|
|||
public string textureName = "";
|
||||
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
|
||||
public Color mainColor = Color.White;
|
||||
public bool sus = true;
|
||||
|
||||
public DrawableUIElement(UIManager manager, int layerIndex = 0, string textureName = "")
|
||||
{
|
||||
|
@ -29,6 +30,7 @@ namespace MonogameLibrary.UI.Base
|
|||
{
|
||||
if (textureName == "")
|
||||
{
|
||||
sus = false;
|
||||
texture = new Texture2D(Manager.GraphicsDevice, 1, 1);
|
||||
texture.SetData<Color>(new Color[] { mainColor });
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class Bar : DrawableUIElement
|
|||
public float percent = 0.5f;
|
||||
private DrawableUIElement barInside;
|
||||
public Color inColor;
|
||||
public string inTextureName;
|
||||
public string inTextureName = "";
|
||||
|
||||
public Bar(UIManager manager, int layerIndex = 0, string textureName = "") : base(manager, layerIndex, textureName)
|
||||
{
|
||||
|
@ -30,8 +30,7 @@ public class Bar : DrawableUIElement
|
|||
{
|
||||
rectangle = new Rectangle(rectangle.X + rectangle.Height / 8, rectangle.Y + rectangle.Height / 8,
|
||||
(int)((rectangle.Width - rectangle.Height / 4) * percent), rectangle.Height / 8 * 7),
|
||||
mainColor = inColor,
|
||||
textureName = inTextureName
|
||||
mainColor = inColor
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ public class HUD : AbstractGUI
|
|||
int height = AppManager.Instance.CurentScreenResolution.Y;
|
||||
|
||||
Button pauseButton = new Button(Manager)
|
||||
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
|
||||
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"};
|
||||
Elements.Add(pauseButton);
|
||||
pauseButton.LoadTexture(AppManager.Instance.Content);
|
||||
pauseButton.LeftButtonPressed += () =>
|
||||
{
|
||||
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
|
||||
|
@ -36,8 +37,9 @@ public class HUD : AbstractGUI
|
|||
overlayGUI.LoadContent();
|
||||
};
|
||||
Button invButton = new Button(Manager)
|
||||
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "inv", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 15 + width / 40, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
|
||||
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "inv", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 15 + width / 40, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"};
|
||||
Elements.Add(invButton);
|
||||
invButton.LoadTexture(AppManager.Instance.Content);
|
||||
invButton.LeftButtonPressed += () =>
|
||||
{
|
||||
overlayGUI = new InventoryGUI();
|
||||
|
|
|
@ -72,6 +72,7 @@ public class WaitingForPlayersGUI : AbstractGUI
|
|||
waitButton.LeftButtonPressed += () =>
|
||||
{
|
||||
// start
|
||||
AppManager.Instance.SetGUI(new HUD());
|
||||
// ваш код здесь
|
||||
};
|
||||
Elements.Add(waitButton);
|
||||
|
|
|
@ -141,6 +141,8 @@ namespace ZoFo.GameCore.GameManagers
|
|||
switch (gamestate)
|
||||
{
|
||||
case GameState.ClientPlaying:
|
||||
client.Draw(_spriteBatch);
|
||||
break;
|
||||
case GameState.HostPlaying:
|
||||
client.Draw(_spriteBatch);
|
||||
break;
|
||||
|
|
|
@ -83,7 +83,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
if (AppManager.Instance.gamestate != GameState.HostPlaying)
|
||||
{
|
||||
AppManager.Instance.ChangeState(GameState.ClientPlaying);
|
||||
AppManager.Instance.SetGUI(new HUD());
|
||||
}
|
||||
SendAcknowledgement(Dgramm.DatagrammId);
|
||||
}
|
||||
|
@ -215,7 +214,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public void JoinRoom(string ip, int port) // multyplayer
|
||||
{
|
||||
sendingEP = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||
AppManager.Instance.ChangeState(GameState.ClientPlaying);
|
||||
SendData();
|
||||
Thread listen = new Thread(StartListening);
|
||||
listen.IsBackground = true;
|
||||
|
|
|
@ -117,20 +117,20 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
List<UpdateData> dataToSend;
|
||||
if (importantUpdates.Count > 0)
|
||||
{
|
||||
dataToSend = new List<UpdateData>();
|
||||
for (int j = 0; j < datapackSize && j < importantUpdates.Count; j++)
|
||||
dataToSend.Add(importantUpdates[j]);
|
||||
for (int i = 0; i < clientsEP.Count; i++)
|
||||
{
|
||||
dataToSend = new List<UpdateData>();
|
||||
for (int j = 0; j < datapackSize && j < importantUpdates.Count; j++)
|
||||
dataToSend.Add(importantUpdates[j]);
|
||||
Datagramm impDgramm = new Datagramm();
|
||||
impDgramm.DatagrammId = currentDatagrammId;
|
||||
impDgramm.updateDatas = dataToSend;
|
||||
impDgramm.isImportant = true;
|
||||
impDgramm.PlayerId = i + 1;
|
||||
sendedData.Add(impDgramm);
|
||||
for (int j = 0; j < datapackSize && j < dataToSend.Count; j++)
|
||||
importantUpdates.RemoveAt(0);
|
||||
}
|
||||
for (int j = 0; j < datapackSize && j < dataToSend.Count; j++)
|
||||
importantUpdates.RemoveAt(0);
|
||||
currentDatagrammId++;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,15 @@ namespace ZoFo.GameCore.GameObjects
|
|||
|
||||
public void StartAnimation(string animationId)
|
||||
{
|
||||
(graphicsComponent as Graphics.AnimatedGraphicsComponent).StartAnimation(animationId);
|
||||
AppManager.Instance.server.AddData(new GameManagers.NetworkManager.Updates.ServerToClient.UpdateAnimation()
|
||||
if (AppManager.Instance.gamestate == GameState.HostPlaying)
|
||||
{
|
||||
animationId = animationId,
|
||||
IdEntity = Id
|
||||
});
|
||||
(graphicsComponent as Graphics.AnimatedGraphicsComponent).StartAnimation(animationId);
|
||||
AppManager.Instance.server.AddData(new GameManagers.NetworkManager.Updates.ServerToClient.UpdateAnimation()
|
||||
{
|
||||
animationId = animationId,
|
||||
IdEntity = Id
|
||||
});
|
||||
}
|
||||
}
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
|
|
@ -92,14 +92,15 @@ namespace ZoFo.GameCore.GameObjects
|
|||
|
||||
}
|
||||
public void EndAttack(string a)
|
||||
{
|
||||
{
|
||||
if (AppManager.Instance.gamestate != GameState.HostPlaying) return;
|
||||
var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position));
|
||||
//TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ
|
||||
if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a);
|
||||
foreach (var item in damagedPlayers)
|
||||
item.TakeDamage(1);
|
||||
item.TakeDamage(1);
|
||||
}
|
||||
isAttacking = false;
|
||||
|
||||
}
|
||||
|
||||
public override void Die()
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
networkManager = new ServerNetworkManager();
|
||||
collisionManager = new CollisionManager();
|
||||
|
||||
players = new List<Player>();
|
||||
}
|
||||
#region server logic as App
|
||||
|
||||
|
@ -120,7 +120,6 @@ namespace ZoFo.GameCore
|
|||
collisionManager = new CollisionManager();
|
||||
gameObjects = new List<GameObject>();
|
||||
entities = new List<Entity>();
|
||||
players = new List<Player>();
|
||||
networkManager.StartGame();
|
||||
new MapManager().LoadMap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue