/// <summary> /// Load initial game data and assets once. /// </summary> public override void LoadContent() { //Load XNA Components. spriteBatch = ScreenManager.SpriteBatch; content = new ContentManager(ScreenManager.Game.Services, "Content"); Random random = new Random(); //Load Textures playerTexture = content.Load<Texture2D>("Textures/player"); Texture2D pickupTexture = content.Load<Texture2D>("Textures/pickup"); Texture2D boundaryTexture = content.Load<Texture2D>("Textures/boundary"); //Create This Player players = new List<PlayerObject>(); thisPlayer = new PlayerObject(Connection.Instance.loadedPlayer.name, //"PLAYER " + random.Next(0, 100), //"PLAYER " + random.Next(0, 100), new ClientInput(), ScreenManager.GraphicsDevice.Viewport, new Vector2(Connection.Instance.loadedPlayer.posX, Connection.Instance.loadedPlayer.posY), new Color(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), playerTexture, random.Next(48, 52)); //Create Pickups //Check for existing players to load pickups from: worldObjects = new List<IGameObject>(); while (Connection.Instance.PickupList == null) { } foreach(Vector2 pickupPos in Connection.Instance.PickupList) { Console.Write("x: " + pickupPos.X + " y: " + pickupPos.Y + " , "); worldObjects.Add(new WorldObject( new Rectangle((int)pickupPos.X, (int)pickupPos.Y, 20, 20), pickupTexture)); } /* for(int i = 0; i < noOfPickups; i++) { worldObjects.Add(new WorldObject( new Rectangle(random.Next(0, ScreenManager.GraphicsDevice.Viewport.Width), random.Next(0, ScreenManager.GraphicsDevice.Viewport.Height), 20, 20), pickupTexture)); } */ //Draw World Boundaries worldObjects.Add( new WorldObject( new Rectangle(0, 0, 5, ScreenManager.GraphicsDevice.Viewport.Height), boundaryTexture)); worldObjects.Add( new WorldObject( new Rectangle(ScreenManager.GraphicsDevice.Viewport.Width - 5, 0, 5, ScreenManager.GraphicsDevice.Viewport.Height), boundaryTexture)); worldObjects.Add( new WorldObject( new Rectangle(0, 0, ScreenManager.GraphicsDevice.Viewport.Width, 5), boundaryTexture)); worldObjects.Add( new WorldObject( new Rectangle(0, ScreenManager.GraphicsDevice.Viewport.Height - 5, ScreenManager.GraphicsDevice.Viewport.Width, 5), boundaryTexture)); }
protected void login() { Console.WriteLine("Login clicked"); //Loging in player Connection connection = Connection.Instance; if (connection.ConnectToServer("127.0.0.1", 8888) == 0) { if (inputBox.text != "") { textMessage.text = "Logging in..."; PlayerObject player = new PlayerObject( inputBox.text, null, ScreenManager.GraphicsDevice.Viewport, new Vector2(0, 0), Color.Blue, null, 50); connection.loadedPlayer = new PlayerState() { name = inputBox.text }; //player.Name = inputBox.text; Task task = new Task(connection.Initialize); task.Start(); task.Wait(); ServerMessage joinMessage = MessageBuilder.ServerMessageBuilder("Join", player.Name); connection.SendMessage(joinMessage); connection.SendMessage(MessageBuilder.ServerMessageBuilder("PlayerList", "")); /* JavaScriptSerializer ser = new JavaScriptSerializer(); string testMessage = ser.Serialize(new PlayerList { type = "PlayerList", players = new string[] { "Elmo", "Tom" } }); Console.WriteLine(testMessage); */ //connection.SendServerMessage("playerlist"); //connection.SendMessage(player); ScreenManager.Transition(typeof(MatchmakingScreen), inputBox.text); } else textMessage.text = "Error: Name not valid."; } else textMessage.text = "Error: Unable to connect to server."; /* if (inputBox.text != "") { textMessage.text = "Logging in..."; ScreenManager.Transition(typeof(MatchmakingScreen), inputBox.text); //Go to Matchmaiking } else textMessage.text = "Error: Name not valid"; */ }