示例#1
0
 protected override void LoadContent()
 {
     #region Globalization
     Screen.Batch          = new Batch(GraphicsDevice);
     Globe.Form            = (Form)Control.FromHandle(Window.Handle);
     Globe.GameWindow      = Window;
     Globe.ContentManager  = Content;
     Globe.GraphicsDevice  = GraphicsDevice;
     Globe.Viewport        = GraphicsDevice.Viewport;
     Globe.GraphicsAdapter = GraphicsDevice.Adapter;
     #endregion
     #region Initialization
     Sound.Initialize(256);
     Textures.RootDirectory        = "Textures";
     Sound.RootDirectory           = "Sounds";
     Font.RootDirectory            = "Fonts";
     Performance.UpdateFPS         = new Buffer(20);
     Performance.DrawFPS           = new Buffer(20);
     Network.OnConnectionApproval += Multiplayer.OnConnectionApproval;
     Network.OnStatusChanged      += Multiplayer.OnStatusChanged;
     Network.OnData += Multiplayer.OnData;
     #endregion
     Screen.Set(1920, 1080, true);
     IsFixedTimeStep = false;
     Screen.Expand(true);
     IsMouseVisible = true;
     if (!Settings.Get("Name").IsNullOrEmpty())
     {
         MenuState = MenuStates.HostConnect;
     }
     MenuWorld          = World.Generate(1200, 400);
     CamPos             = new Vector2((MenuWorld.Spawn.X * Tile.Size), (MenuWorld.Spawn.Y * Tile.Size));
     MenuWorld.Position = new Vector2((int)Math.Round(CamPos.X), (int)Math.Round(CamPos.Y));
     Sound.CompileOggs();
     _orbisLogo       = Textures.Load("Logo.png");
     _orbisFont       = Font.Load("Orbis");
     MenuMusicChannel = Sound.PlayRaw("Glacier.wav", true, .04f, false);
 }
示例#2
0
 protected override void Draw(GameTime time)
 {
     Performance.DrawFPS.Record(1 / time.ElapsedGameTime.TotalSeconds);
     GraphicsDevice.Clear(Color.Black);
     Profiler.Start("Game Draw");
     #region Menu/Connecting
     if (Frame == Frames.Menu)
     {
         MenuWorld.Draw();
         Screen.Cease();
         MenuWorld.DrawLightMap();
         Screen.Setup(SpriteSortMode.Deferred, SamplerState.PointClamp);
         Screen.Draw(_orbisLogo, new Vector2(Screen.BackBufferWidth / 2f, 160 * Scale.Y), (float)(.1f * Math.Cos(time.TotalGameTime.TotalSeconds)), Textures.Origin.Center, ((float)(1 + (.2f * Math.Sin(time.TotalGameTime.TotalSeconds))) * Scale));
         Screen.DrawString("Developed by Dcrew & Pyroglyph", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight - Screen.BackBufferHeight / 8f), Color.Gray * .5f, Textures.Origin.Center, Scale * .5f);
         if (MenuState == MenuStates.UsernameEntry)
         {
             Screen.DrawString("Enter your name!", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f - 35 * Scale.Y), Color.Gray * .75f, new Textures.Origin(.5f, 1, true), Scale * .75f);
             Screen.DrawString(Settings.Get("Name") + ((BlinkTimer <= .3f) && IsActive ? "|" : string.Empty), _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f - 30 * Scale.Y), Color.Black * .75f,
                               new Textures.Origin(.5f, 0, true), Scale * .75f);
             Screen.DrawString("Press 'enter' to proceed!", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f + 35 * Scale.Y), Color.DimGray * .5f, new Textures.Origin(.5f, 1, true), Scale * .5f);
         }
         else if (MenuState == MenuStates.HostConnect)
         {
             var scale = Scale * .5f;
             var size  = _orbisFont.MeasureString("Welcome, ") * scale;
             Screen.DrawString("Welcome, ", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f - _orbisFont.MeasureString("Welcome, " + Settings.Get("Name") + "!").X *scale.X / 2f, Screen.BackBufferHeight / 2f - size.Y * 3), Color.Gray * .75f, null, 0,
                               new Textures.Origin(0, .5f, true), scale);
             Screen.DrawString(Settings.Get("Name"), _orbisFont,
                               new Vector2(Screen.BackBufferWidth / 2f - _orbisFont.MeasureString("Welcome, " + Settings.Get("Name") + "!").X *scale.X / 2f + _orbisFont.MeasureString("Welcome, ").X *scale.X, Screen.BackBufferHeight / 2f - size.Y * 3), Color.Green * .75f,
                               new Textures.Origin(0, .5f, true), scale);
             Screen.DrawString("!", _orbisFont,
                               new Vector2(Screen.BackBufferWidth / 2f - _orbisFont.MeasureString("Welcome, " + Settings.Get("Name") + "!").X *scale.X / 2f + _orbisFont.MeasureString("Welcome, " + Settings.Get("Name")).X *scale.X,
                                           Screen.BackBufferHeight / 2f - size.Y * 3), Color.Gray * .75f, new Textures.Origin(0, .5f, true), scale);
             var mouse = new Rectangle(Mouse.X, Mouse.Y, 1, 1);
             scale = Scale * .75f;
             size  = _orbisFont.MeasureString("Host") * scale;
             var button = new Rectangle((int)(Screen.BackBufferWidth / 2f - size.X / 2f), (int)(Screen.BackBufferHeight / 2f - size.Y), (int)size.X, (int)size.Y);
             var color  = Color.Silver;
             if (mouse.Intersects(button))
             {
                 scale += new Vector2(.35f);
                 color  = Color.White;
             }
             Screen.DrawString("Host", _orbisFont, new Vector2(button.X + button.Width / 2f, button.Y + button.Height / 2f), color, Color.Black * .5f, Textures.Origin.Center, scale);
             scale  = Scale * .75f;
             size   = _orbisFont.MeasureString("Connect") * scale;
             button = new Rectangle((int)(Screen.BackBufferWidth / 2f - size.X / 2f), (int)(Screen.BackBufferHeight / 2f + size.Y * .25f), (int)size.X, (int)size.Y);
             color  = Color.Silver;
             if (mouse.Intersects(button))
             {
                 scale += new Vector2(.35f);
                 color  = Color.White;
             }
             Screen.DrawString("Connect", _orbisFont, new Vector2(button.X + button.Width / 2f, button.Y + button.Height / 2f), color, Color.Black * .5f, Textures.Origin.Center, scale);
         }
         else if (MenuState == MenuStates.IPEntry)
         {
             Screen.DrawString("Server IP:", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f - 35 * Scale.Y), Color.Gray * .75f, new Textures.Origin(.5f, 1, true), Scale * .75f);
             Screen.DrawString(Settings.Get("IP") + ((BlinkTimer <= .3f) && IsActive ? "|" : string.Empty), _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f - 30 * Scale.Y), Color.Black * .75f,
                               new Textures.Origin(.5f, 0, true), Scale * .75f);
             Screen.DrawString("Press 'enter' to proceed!", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f + 130 * Scale.Y), Color.DimGray * .5f, new Textures.Origin(.5f, 1, true), Scale * .5f);
             Screen.DrawString("Press 'tab' to go back!", _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f + 190 * Scale.Y), Color.DimGray * .5f, new Textures.Origin(.5f, 1, true), Scale * .5f);
         }
         Screen.Cease();
     }
     else if (Frame == Frames.Connecting)
     {
         MenuWorld.Draw();
         Screen.Cease();
         MenuWorld.DrawLightMap();
         Screen.Setup();
         Screen.DrawString("Connecting to " + Settings.Get("IP") + new string('.', 4 - (int)Math.Ceiling(BlinkTimer * 4)), _orbisFont, new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f), Color.White,
                           Textures.Origin.Center, Scale * .5f);
         Screen.Cease();
     }
     #endregion
     #region LoadGame/Game
     else if (Frame == Frames.LoadGame)
     {
         MenuWorld.Draw();
         Screen.Cease();
         MenuWorld.DrawLightMap();
         Screen.Setup();
         if (!string.IsNullOrEmpty(LoadingText))
         {
             Screen.DrawString((LoadingText + new string('.', 4 - (int)Math.Ceiling(BlinkTimer * 4)) + " " + Math.Round(LoadingPercentage) + "%"), _orbisFont,
                               new Vector2(Screen.BackBufferWidth / 2f, Screen.BackBufferHeight / 2f), Color.White, Textures.Origin.Center, Scale * .5f);
         }
         Screen.Cease();
     }
     else if (Frame == Frames.Game)
     {
         GameWorld.Draw();
         foreach (var t in Players)
         {
             t?.Draw();
         }
         Screen.Draw(World._tilesTexture, new Rectangle(MouseTileX * Tile.Size, MouseTileY * Tile.Size, Tile.Size, Tile.Size), Tile.Source(1, 1), Color.White * (float)(.3f + (.25f * Math.Sin(time.TotalGameTime.TotalSeconds * 5))));
         Screen.Cease();
         GameWorld.DrawLightMap();
         var invSlot = Textures.Load("Inventory Slot.png");
         Screen.Setup();
         const int itemsPerRow = 7;
         var       invScale = 1f; var invPos = new Vector2((Screen.BackBufferWidth - (((invSlot.Width * invScale) * itemsPerRow) + (itemsPerRow - 1)) - 5), 5);
         Self.DrawInventory(invPos, itemsPerRow, invScale);
         if (Settings.IsDebugMode)
         {
             var rows = (int)Math.Ceiling(Inventory.PlayerInvSize / (float)itemsPerRow);
             invPos.Y += (rows * (invSlot.Height * invScale)) + 5;
             invScale  = .5f;
             invPos.X  = (Screen.BackBufferWidth - (((invSlot.Width * invScale) * itemsPerRow) + (itemsPerRow - 1)) - 5);
             foreach (var t in Players.Where(player => !player.Matches(null, Self)))
             {
                 t.DrawInventory(invPos, itemsPerRow, invScale);
                 invPos.Y += (rows * (invSlot.Height * invScale)) + 10;
             }
         }
         Screen.Cease();
         if (Settings.IsDebugMode)
         {
             Screen.Setup();
             Screen.DrawString(("Zoom: " + GameWorld.Zoom + " - Direction: " + Self.Direction + " - Inputs: " + Self.LastInput), Font.Load("Orbis"), new Vector2(2), Color.White, Color.Black, new Vector2(DebugTextScale));
             Screen.DrawString(("IsFalling: " + Self.IsFalling + " - IsOnGround: " + Self.IsOnGround), Font.Load("Orbis"), new Vector2(2, (2 + ((DebugTextScale * 100) * 1))), Color.White, Color.Black, new Vector2(DebugTextScale));
             Screen.DrawString(("TilePos: " + Self.TileX + "," + Self.TileY + " - MoveSpeed: " + Self.MovementSpeed + " - MoveResistance: " + Self.MovementResistance +
                                " - Velocity: " + Math.Round(Self.Velocity.X, 1) + "," + Math.Round(Self.Velocity.Y, 1)), Font.Load("Orbis"), new Vector2(2, (2 + ((DebugTextScale * 100) * 2))), Color.White, Color.Black,
                               new Vector2(DebugTextScale));
             Screen.Cease();
         }
         if (BufferedStrings.Count > 0)
         {
             Screen.Setup(GameWorld.Matrix);
             foreach (var v in BufferedStrings.Values)
             {
                 var bString = (v as BufferedString);
                 Screen.DrawString(bString.Text, _orbisFont, new Vector2(Self.WorldPosition.X, (Self.WorldPosition.Y - BufferedString.PlayerYOffset + bString.Offset)), (Color.White * MathHelper.Clamp((float)bString.Life, 0, 1)),
                                   Textures.Origin.Center, new Vector2(BufferedString.Scale));
             }
             Screen.Cease();
         }
     }
     #endregion
     Profiler.Stop("Game Draw");
     Profiler.Start("Profiler");
     if (Profiler.Enabled)
     {
         Profiler.Draw(430);
     }
     Profiler.Stop("Profiler");
     base.Draw(time);
 }