public void Update(Control control, Map map, Player player, GameTime time, Package package) { UpdatePlayers(control, map); NetOutgoingMessage msgout = NetClient.CreateMessage(); msgout.Write(BuildCommand(player)); NetClient.SendMessage(msgout, NetDeliveryMethod.Unreliable); NetIncomingMessage msg; while ((msg = NetClient.ReadMessage()) != null) { switch(msg.MessageType) { case NetIncomingMessageType.DiscoveryResponse: NetClient.Connect(msg.SenderEndpoint); Player newplayer = new Player(); newplayer.Initialize(PlayerTexture, BarsTexture, package, map.Spawn); Messages.Add("new player"); Players.Add(newplayer); break; case NetIncomingMessageType.Data: HandleData(msg); break; default: // Messages.Add(msg.ReadString()); break; } } }
public void Update(Control control, Map map, Player player, GameTime time, Package package) { UpdatePlayers(control, map); NetOutgoingMessage msgout = NetServer.CreateMessage(); msgout.Write(BuildCommand(player)); NetServer.SendToAll(msgout, NetDeliveryMethod.Unreliable); Time = time; NetIncomingMessage msg; while ((msg = NetServer.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.DiscoveryRequest: NetServer.SendDiscoveryResponse(null, msg.SenderEndpoint); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); if (status == NetConnectionStatus.Connected) { Player newplayer = new Player(); newplayer.Initialize(PlayerTexture, BarsTexture, package, map.Spawn); Players.Add(newplayer); Message(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " connected!"); } else if(status == NetConnectionStatus.Disconnected) { Message(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier) + " disconnected!"); } break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Messages.Add(new ChatMessage(msg.ReadString(), time)); break; case NetIncomingMessageType.Data: HandleData(msg); break; default: Messages.Add(new ChatMessage("Unhandled request ("+msg.MessageType+"): " + msg.ReadString(), time)); break; } NetServer.Recycle(msg); } }
public BlueprintGame(string[] args) { // Graphics Setup graphics = new GraphicsDeviceManager(this); this.graphics.PreferredBackBufferWidth = 1280; this.graphics.PreferredBackBufferHeight = 720; this.graphics.SynchronizeWithVerticalRetrace = true; Content.RootDirectory = "Content"; this.Window.AllowUserResizing = true; this.Window.ClientSizeChanged += new EventHandler<EventArgs>(Window_ClientSizeChanged); // Setup a few classes Config = new Config(args); Package = new Package(Config); Lighting = new Lighting(this); Loading = new Loading(); }
public void Initialize(ContentManager content, Package package, Texture2D uiTexture) { UiTexture = uiTexture; // Ai Ai[0] = new NpcAiDummy(); Ai[1] = new NpcAiChase(); // Races Races[0] = new NpcRace("Lynch", content.Load<Texture2D>("Npcs/Sprites/lynch"), package.LocalString("c:/blueprint/lynch.xml", false)); // Npcs Types[0] = new NpcType("The Lynch", Races[0], Ai[1]); Types[0].Dialog.Add("Hello {playername}", NpcInteraction.NpcInteractionState.Intro); Types[0].Dialog.Add("Here is some interesting information {playername}", NpcInteraction.NpcInteractionState.Gossip); // Active Npcs ActiveNpc npc = new ActiveNpc(Types[0], new Vector2(200, -50)); ActiveNpcs.Add(npc); }
public void Initialize(Texture2D playerTexture, Texture2D barsTexture, Package package, Vector2 position) { BarsTexture = barsTexture; PlayerTexture = playerTexture; Health = 100; Mana = 100; Speed = 4f; Name = "Firebolt"; Inventory = new Inventory(); // Animation Animation = new Animations(package.LocalString("C:\\blueprint\\player.xml", false)); Movement = new Movement(position, 32, 44); }
public void Initialize( Texture2D mapTexture, Package package, Config config, GraphicsDevice graphics, ContentManager content ) { // Setup Liquids Fluids.Initialize(SizeX, SizeY, content.Load<Texture2D>("Blocks/blocks")); BlockTexture = mapTexture; BlockState = content.Load<Texture2D>("Blocks/blocks"); WallTexture = content.Load<Texture2D>("Blocks/wall"); Entities.Initialize(content); Flora.Initialize(this, content.Load<Texture2D>("flora")); // Gather Map Data string data = package.RemoteString("maps/manifest/" + config.MapId); XmlDocument xml = new XmlDocument(); xml.LoadXml(data); Spawn = new Vector2(Int32.Parse(xml.DocumentElement.Attributes["spawnx"].Value) * 24, Int32.Parse(xml.DocumentElement.Attributes["spawny"].Value) * 24); #region Xml Parsing foreach (XmlNode node in xml.DocumentElement.ChildNodes) { if (node.Name == "BlockType") { int upto = 0; foreach (XmlNode blocktype in node.ChildNodes) { Types[upto] = new BlockType(blocktype.Attributes["name"].Value, Int32.Parse(blocktype.Attributes["id"].Value), 100); foreach (XmlNode slice in blocktype.ChildNodes) { Types[upto].Slices[int.Parse(slice.Attributes["i"].Value)] = new Rectangle(int.Parse(slice.Attributes["x"].Value) * 24, int.Parse(slice.Attributes["y"].Value) * 24, 24, 24); } upto++; } } else if (node.Name == "Block") { foreach (XmlNode block in node.ChildNodes) { Blocks[Int32.Parse(block.Attributes["x"].Value), Int32.Parse(block.Attributes["y"].Value)] = new Block(GetBlockType(Int32.Parse(block.Attributes["type"].Value))); } } else if (node.Name == "Liquid") { foreach (XmlNode liquid in node.ChildNodes) { if(byte.Parse(liquid.Attributes["type"].Value) == 1){ Fluids.Water.Blocks[Int32.Parse(liquid.Attributes["x"].Value), int.Parse(liquid.Attributes["y"].Value)] = 24; } else if (byte.Parse(liquid.Attributes["type"].Value) == 1) { // lava } } } else if (node.Name == "EntityType") { //Entities.Types = new EntityType[node.ChildNodes.Count]; int i = 0; foreach (XmlNode entitytype in node.ChildNodes) { /*Entities.Types[i] = new EntityType( int.Parse(entitytype.Attributes["id"].Value), entitytype.Attributes["name"].Value, package.RemoteTexture(entitytype.Attributes["sprite"].Value, graphics), int.Parse(entitytype.Attributes["width"].Value), int.Parse(entitytype.Attributes["height"].Value), true );*/ i++; } } else if (node.Name == "Entity") { foreach (XmlNode entity in node.ChildNodes) { //EntityType type = Entities.getType(); //EntityType type = Entities.getType(int.Parse(entity.Attributes["type"].Value)); // int.Parse(entity.Attributes["width"].Value) /* Entities.Entities.Add( new Entity(type, int.Parse(entity.Attributes["x"].Value), int.Parse(entity.Attributes["y"].Value)) );*/ } } } #endregion // Autogenerate //MapGenerator generator = new MapGenerator(); //generator.Setup(SizeX, SizeY); //generator.Generate(this); }