using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Input; //Contact Katinka at ka.m.kalkman@gmail.com, if there are any questions //Modified by: Zepharis Lubrano & Luciano van der Veekens. It's working now ( the menu ). //added animation to the menu by Zepharis, overlay added (can't find server) + duck flying around dead. class Menu { GameWorld gameWorld; MenuButton single, host, join; SoundEffect Gun; SpriteGameObject background, background2, title, noServer, clientLost, helpSingle, helpMulti, helpControl, dog, quit; Duck duck1, duck2, duck3, duck4; bool noServerFound, lostConnection; Vector2 deadduckposition; //startposition for the flying dead duck. double r = 8;//radius double angle = 0;//angle float quitpositionx; public Menu(GameWorld gw, ContentManager Content, int screenWidth, int screenHeight) { gameWorld = gw; single = new MenuButton(gameWorld, "Sprites/Single", 4, "Single"); host = new MenuButton(gameWorld, "Sprites/Host", 4, "Host"); join = new MenuButton(gameWorld, "Sprites/Join", 4, "Join"); dog = new SpriteGameObject(gameWorld, "Sprites/Dog", 1, "Dog"); dog.position = new Vector2(350, 300); quit = new SpriteGameObject(gameWorld, "Sprites/Quit", 50, "quit"); duck1 = new Duck(gameWorld, 3, "Duck1"); duck2 = new Duck(gameWorld, 3, "Duck2"); duck3 = new Duck(gameWorld, 3, "Duck3"); duck4 = new Duck(gameWorld, 3, "Duck4"); Gun = gameWorld.ResourceManager.getSound("Sounds/Gunshot"); background = gameWorld.Find("Background") as SpriteGameObject; background2 = gameWorld.Find("Background2") as SpriteGameObject; helpSingle = new SpriteGameObject(gameWorld, "Sprites/helpSingle", 3, "HelpSingle"); helpSingle.position = new Vector2(110, 580); helpMulti = new SpriteGameObject(gameWorld, "Sprites/helpMulti", 3, "HelpMulti"); helpMulti.position = new Vector2(680, 580); helpControl = new SpriteGameObject(gameWorld, "Sprites/helpControl", 3, "HelpControl"); helpControl.position = new Vector2(50, 0); duck1.LoadAnimation(gameWorld, "Sprites/Duck/BlackDuckIdle", "blackidle", true); duck2.LoadAnimation(gameWorld, "Sprites/Duck/RedDuckIdle", "redidle", true); duck3.LoadAnimation(gameWorld, "Sprites/Duck/Idle", "idle", true); duck3.LoadAnimation(gameWorld, "Sprites/Duck/Falling", "falling", true); duck4.LoadAnimation(gameWorld, "Sprites/Duck/Die", "die", false); title = new SpriteGameObject(gameWorld, "Sprites/Title", 4, "Title"); noServer = new SpriteGameObject(gameWorld, "Overlays/CouldNotFindServer", 101, "noServer"); clientLost = new SpriteGameObject(gameWorld, "Overlays/LostConnectionWithClient", 101, "LostConnection"); deadduckposition = new Vector2(620, 550); quit.Position = new Vector2(640, 720 - quit.Center.Y) - quit.Center; quitpositionx = quit.Position.X + quit.Center.X; duck4.Position = new Vector2(quitpositionx, quit.Position.Y); noServer.Position = new Vector2(640, 360) - noServer.Center; clientLost.Position = new Vector2(640, 360) - clientLost.Center; } public void HandleInput(InputHelper inputHelper) { Player player = gameWorld.Find("Cursor") as Player; if (noServerFound) { if (inputHelper.MouseLeftButtonPressed() || inputHelper.MouseRightButtonPressed() || inputHelper.KeyPressed(Keys.Escape)) { noServer.Visible = false; noServerFound = false; } } if (lostConnection) { if (inputHelper.MouseLeftButtonPressed() || inputHelper.MouseRightButtonPressed() || inputHelper.KeyPressed(Keys.Escape)) { clientLost.Visible = false; lostConnection = false; } } if (!noServerFound || !lostConnection) { single.HandleInput(inputHelper, gameWorld); host.HandleInput(inputHelper, gameWorld); join.HandleInput(inputHelper, gameWorld); GameModeHandler gmHandler = gameWorld.Find("gmHandler") as GameModeHandler; if (inputHelper.MouseLeftButtonPressed() && inputHelper.MouseBoundingRectangle.Intersects(duck1.BoundingRectangle)) { gmHandler.CurrentGameMode = GameModeHandler.GameMode.Single; Duck duck = gameWorld.Find("Duck") as Duck; duck.Reset2(gameWorld); player.Reset(); } if (inputHelper.MouseLeftButtonPressed() && inputHelper.MouseBoundingRectangle.Intersects(duck4.BoundingRectangle) || inputHelper.MouseLeftButtonPressed() && inputHelper.MouseBoundingRectangle.Intersects(quit.BoundingRectangle)) { Gun.Play(); Environment.Exit(0); } if (inputHelper.MouseLeftButtonPressed() && inputHelper.MouseBoundingRectangle.Intersects(duck2.BoundingRectangle)) { SpriteGameObject waiting = gameWorld.Find("waiting") as SpriteGameObject; if (waiting != null) waiting.Visible = true; gmHandler.CurrentGameMode = GameModeHandler.GameMode.Host; } if (inputHelper.MouseLeftButtonPressed() && inputHelper.MouseBoundingRectangle.Intersects(duck3.BoundingRectangle)) gmHandler.CurrentGameMode = GameModeHandler.GameMode.IP; } //Handles the cursor input. player.Position = inputHelper.MousePosition - player.Center; //Plays sound whenever the player hits the left mouse button. if (inputHelper.MouseLeftButtonPressed()) Gun.Play(); } public void Update(GameTime gameTime) { if (noServerFound || lostConnection) { duck3.PlayAnimation("falling"); duck3.AnimPlayer.Update(gameTime); deadduckposition.X += (float)(r * Math.Cos(angle)); deadduckposition.Y += (float)(r * Math.Sin(angle)); duck3.Position = deadduckposition; angle -= 0.05; } else { duck4.PlayAnimation("die"); duck4.AnimPlayer.Update(gameTime); title.Position = new Vector2(500, 100); single.Position += single.Velocity; if (single.Position.X < 0 || single.Position.X > 1280 - single.BoundingRectangle.Width) //the singleplayer button is moving towards the side of the screen and bounces. { single.Velocity *= -1; duck1.Velocity *= -1; } duck1.Position = single.Position + new Vector2(single.Center.X, -single.Center.Y); duck1.Velocity = single.Velocity; duck1.PlayAnimation("blackidle"); Duck duck = gameWorld.Find("Duck") as Duck; duck.Instance.Play(); duck1.AnimPlayer.Mirror = duck1.Velocity.X < 0; duck1.AnimPlayer.Update(gameTime); single.Update(gameTime, gameWorld); host.Position += host.Velocity; if (host.Position.X < 0 || host.Position.X > 1280 - host.BoundingRectangle.Width) //host multiplayer button moves etc. { host.Velocity *= -1; duck2.Velocity *= -1; } duck2.Position = host.Position + new Vector2(host.Center.X, -host.Center.Y); duck2.Velocity = host.Velocity; duck2.PlayAnimation("redidle"); duck2.AnimPlayer.Mirror = duck2.Velocity.X < 0; duck2.AnimPlayer.Update(gameTime); host.Update(gameTime, gameWorld); join.Position += join.Velocity; if (join.Position.X < 0 || join.Position.X > 1280 - join.BoundingRectangle.Width) //join button moves etc. { join.Velocity *= -1; duck3.Velocity *= -1; } duck3.Position = join.Position + new Vector2(join.Center.X, -join.Center.Y); duck3.Velocity = join.Velocity; duck3.PlayAnimation("idle"); duck3.AnimPlayer.Mirror = duck3.Velocity.X < 0; duck3.AnimPlayer.Update(gameTime); join.Update(gameTime, gameWorld); } } public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { background.Draw(gameTime, spriteBatch); //draws the background of the game dog.Draw(gameTime, spriteBatch); background2.Draw(gameTime, spriteBatch); //same, but the other part of it duck3.Draw(gameTime, spriteBatch); noServer.Draw(gameTime, spriteBatch); clientLost.Draw(gameTime, spriteBatch); duck4.Draw(gameTime, spriteBatch); quit.Draw(gameTime, spriteBatch); if (noServerFound) { noServer.Visible = true; clientLost.Visible = false; } else if (lostConnection) { noServer.Visible = false; clientLost.Visible = true; } else { noServer.Visible = false; clientLost.Visible = false; title.Draw(gameTime, spriteBatch); single.Draw(gameTime, spriteBatch); host.Draw(gameTime, spriteBatch); join.Draw(gameTime, spriteBatch); duck1.Draw(gameTime, spriteBatch); duck2.Draw(gameTime, spriteBatch); helpSingle.Draw(gameTime, spriteBatch); helpMulti.Draw(gameTime, spriteBatch); helpControl.Draw(gameTime, spriteBatch); } //Draws the cursor. Player player = gameWorld.Find("Cursor") as Player; player.Draw(gameTime, spriteBatch); } public bool NoServerFound { get { return noServerFound; } set { noServerFound = value; } } public bool LostConnection { get { return lostConnection; } set { lostConnection = value; } } }