Trying to make a server

This commit is contained in:
2022-10-23 20:58:01 +02:00
parent 9d04246d75
commit 7a60703eb8
9 changed files with 125 additions and 16 deletions
+28 -5
View File
@@ -1,9 +1,10 @@
using LiteNetLib;
using System;
using System.Collections.Generic;
using LiteNetLib;
using LiteNetLib.Utils;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using shared;
namespace client
{
@@ -13,6 +14,7 @@ namespace client
EventBasedNetListener listener = new();
NetManager client;
NetPeer server;
NetPacketProcessor processor = new();
// Game instances
private Player pl1;
@@ -57,6 +59,7 @@ namespace client
// TODO: Replace by a error message :)
Exit();
}
processor.SubscribeReusable<Assignation>(AssignationHandler);
// Window
Window.Title = "Pong";
@@ -70,7 +73,7 @@ namespace client
15,
100,
100f
).SetControllable(true);
);
pl2 = new Player(
new Vector2(_graphics.PreferredBackBufferWidth - 30, _graphics.PreferredBackBufferHeight / 2 - 50),
@@ -83,7 +86,7 @@ namespace client
ball = new Ball(
new Vector2(_graphics.PreferredBackBufferWidth / 2 - 5, _graphics.PreferredBackBufferHeight / 2 - 5),
10,
0.2f
1f
);
// KILLZONE
@@ -143,5 +146,25 @@ namespace client
_spriteBatch.End();
base.Draw(gameTime);
}
private void AssignationHandler(Assignation assignation)
{
if (assignation != null)
{
if (assignation.controller == 0) {
pl1.SetControllable(true);
pl2.SetControllable(false);
}
else
{
pl1.SetControllable(false);
pl2.SetControllable(true);
}
}
else
{
Console.Error.WriteLine("Packet malformed!");
}
}
}
}