Hello Codeproject,
I've been working on a game of mine for a few days now. And I want to get the basic things Online, I currently have a few classes;
Entity,
Entity Player : Entity,
World.
All the things going on in my game are being controlled by my World class:
public class World
{
public List<Entity> Entities { get; set;}
public Entity Player;
public World()
{
Entities = new List<Entity>();
Player = new EntityPlayer();
Player.SetMovingSpeed(4);
}
}
Which then is drawn via:
public static void DrawWorld(SpriteBatch Batch)
{
Batch.Draw(Main.World.Player.Sprite, PlayerRectangle, null, Color.White, Main.World.Player.GetAngle(), new Vector2(PlayerRectangle.Width / 2, PlayerRectangle.Height / 2), SpriteEffects.None, 0);
long X = 0;
long Y = 0;
Rectangle Rectangle;
foreach (Entity Entity in Main.World.Entities)
{
if (Entity.GetDistanceFromEntity(Main.World.Player) < Main.BiggestSize)
{
X = (Entity.PositionX - Main.World.Player.PositionX) + Main.WindowWidth / 2;
Y = (Entity.PositionY - Main.World.Player.PositionY) + Main.WindowHeight / 2;
Rectangle = new Rectangle((int)X,(int)Y,Entity.Sprite.Width, Entity.Sprite.Height);
Batch.Draw(Entity.Sprite, Rectangle, null , Color.White, Entity.GetAngle(), new Vector2(Rectangle.Width / 2, Rectangle.Height / 2), SpriteEffects.None, 0);
}
}
}
So, clearing everything up, this is everything I currently need for my game. So, summing up, I only need to be able to Control the List<entity> Entities of my world in order to get multiplayer working for right now. But how would I do that?
Server:
1. Listen for TcpClient.
2. If TcpClient connects, we create a new Entity in the server's World class.
3. Then, if anything goes on, moving, shooting(Not yet created), we update it in the current entity which then is send to all clients.
4. Player logs out, entity is removed.
That is basically how it would work, but I have no clue on how to send these sort of packets without using an XML Serializer to send the whole class via string converted to a byte array. This is the correct solution for me, but I am really sure that there is a better way on doing it, and I would love to know where to get started.