using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; //Class for the IP-input screen class IPClass { SpriteFont spriteFont; SpriteGameObject background, background2, back; SpriteGameObject JoinButton, IPborder; Duck duck2, duck3; string IP; GameWorld gameWorld; float duck2positionx, duck3positionx; public IPClass (GameWorld gameWorld) { this.gameWorld = gameWorld; spriteFont = gameWorld.ResourceManager.Content.Load("Fonts/Hud"); background = gameWorld.Find("Background") as SpriteGameObject; background2 = gameWorld.Find("Background2") as SpriteGameObject; IPborder = new SpriteGameObject(gameWorld, "Sprites/IP", 4, "IPBorder"); duck3 = new Duck(gameWorld, 3, "Duck3"); duck2 = new Duck(gameWorld, 3, "Duck2"); back = new SpriteGameObject(gameWorld, "Sprites/Back", 4, "back"); JoinButton = new SpriteGameObject(gameWorld, "Sprites/JoinButton", 4, "JoinButton"); JoinButton.Position = new Vector2(1200, 600) - JoinButton.Center; duck2.LoadAnimation(gameWorld, "Sprites/Duck/BlackDuckIdle", "blackidle", true); back.Position = new Vector2(30, JoinButton.Position.Y); duck3positionx = JoinButton.Position.X + JoinButton.Center.X; duck2positionx = back.Position.X + back.Center.X; duck3.Position = new Vector2(duck3positionx, JoinButton.Position.Y); duck2.Position = new Vector2(duck2positionx, back.Position.Y); IPborder.Position = new Vector2(640, 360) - IPborder.Center; } public void HandleInput(InputHelper inputHelper) { GameModeHandler gmHandler = gameWorld.Find("gmHandler") as GameModeHandler; if (IP == null || IP.Length < 15) { if (inputHelper.KeyPressed(Keys.NumPad0) || inputHelper.KeyPressed(Keys.D0)) IP += '0'; if (inputHelper.KeyPressed(Keys.NumPad1) || inputHelper.KeyPressed(Keys.D1)) IP += '1'; if (inputHelper.KeyPressed(Keys.NumPad2) || inputHelper.KeyPressed(Keys.D2)) IP += '2'; if (inputHelper.KeyPressed(Keys.NumPad3) || inputHelper.KeyPressed(Keys.D3)) IP += '3'; if (inputHelper.KeyPressed(Keys.NumPad4) || inputHelper.KeyPressed(Keys.D4)) IP += '4'; if (inputHelper.KeyPressed(Keys.NumPad5) || inputHelper.KeyPressed(Keys.D5)) IP += '5'; if (inputHelper.KeyPressed(Keys.NumPad6) || inputHelper.KeyPressed(Keys.D6)) IP += '6'; if (inputHelper.KeyPressed(Keys.NumPad7) || inputHelper.KeyPressed(Keys.D7)) IP += '7'; if (inputHelper.KeyPressed(Keys.NumPad8) || inputHelper.KeyPressed(Keys.D8)) IP += '8'; if (inputHelper.KeyPressed(Keys.NumPad9) || inputHelper.KeyPressed(Keys.D9)) IP += '9'; if (inputHelper.KeyPressed(Keys.OemPeriod)) IP += '.'; } if (IP != null) { if (IP.Length > 0) { if (inputHelper.KeyPressed(Keys.Back)) { IP = IP.Substring(0, IP.Length - 1); } } } if (IP != null) { if (inputHelper.KeyPressed(Keys.Enter) || inputHelper.MouseBoundingRectangle.Intersects(duck3.BoundingRectangle) && inputHelper.MouseLeftButtonPressed() || inputHelper.MouseBoundingRectangle.Intersects(JoinButton.BoundingRectangle) && inputHelper.MouseLeftButtonPressed()) gmHandler.CurrentGameMode = GameModeHandler.GameMode.Join; } if (inputHelper.MouseBoundingRectangle.Intersects(duck2.BoundingRectangle) && inputHelper.MouseLeftButtonPressed() || inputHelper.MouseBoundingRectangle.Intersects(back.BoundingRectangle) && inputHelper.MouseLeftButtonPressed()) gmHandler.CurrentGameMode = GameModeHandler.GameMode.Menu; Player player = gameWorld.Find("Cursor") as Player; player.HandleInput(inputHelper, gameWorld); } public void Update(GameTime gameTime) { duck3.PlayAnimation("idle"); duck3.Velocity = new Vector2(5, 0); duck3.AnimPlayer.Mirror = duck2.Velocity.X < 0; duck3.AnimPlayer.Update(gameTime); duck2.PlayAnimation("blackidle"); duck2.Velocity = new Vector2(-5, 0); duck2.AnimPlayer.Mirror = duck2.Velocity.X < 0; duck2.AnimPlayer.Update(gameTime); } public string IPAddress { get { return IP; } } public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { background.Draw(gameTime, spriteBatch); background2.Draw(gameTime, spriteBatch); duck3.Draw(gameTime, spriteBatch); duck2.Draw(gameTime, spriteBatch); back.Draw(gameTime, spriteBatch); IPborder.Draw(gameTime, spriteBatch); Player player = gameWorld.Find("Cursor") as Player; player.Draw(gameTime, spriteBatch); JoinButton.Draw(gameTime, spriteBatch); if (IP != null) spriteBatch.DrawString(spriteFont, IP, new Vector2(730, 385) - IPborder.Center, Color.Blue); } }