Ejemplo n.º 1
0
        public static void Main()
        {
            //Create collections to hold leaderboard, packet count and server list
            _leaderboard = new List<LeaderboardPlayer>();
            _packetCount = new Dictionary<int, int>();
            _serverList = new List<Server>();

            _showPopup = true;

            //Open the game window
            SwinGame.OpenGraphicsWindow("Petri", 1024, 800);

            //Load the Arial font
            Font _gameFont = SwinGame.LoadFont("Arial", 14);

            Rectangle background = new Rectangle(SwinGame.RGBAColor(0, 0, 0, 155), (SwinGame.ScreenWidth() / 2) - (300 / 2), 
                                                                                   (SwinGame.ScreenHeight() / 2) - (200 / 2), 300, 150, false);

            //Create a textbox to get the nick name
            TextBox nameEntry = new TextBox(_gameFont, (SwinGame.ScreenWidth() / 2) - (190 / 2), background.Y + 30, 190, 20, 16);

            //Create a combobox to select the server 
            _box = new ComboBox(_gameFont, nameEntry.X, background.Y + 70, 190, 20);
            _box.ItemSelected += box_ItemSelected;
            _box.Text = "Loading servers...";

            Rectangle connectRect = new Rectangle(Color.DarkGray, _box.X, background.Y + background.Height - 30, 190, 20, false);

            while (!SwinGame.WindowCloseRequested())
            {
                //Init the server info on load
                if (!_startup)
                {
                    _startup = true;
                    LoadData(_box);
                }

                //Check for any clicks/key presses
                SwinGame.ProcessEvents();

                //Clear the screen
                SwinGame.ClearScreen(Color.White);

                //Draw the world and contents within
                if (_agarWorld != null)
                    _agarWorld.Draw();

                //Draw menu
                if (_showPopup)
                {
                    background.Draw();
                    
                    SwinGame.DrawTextOnScreen("Name:", Color.White, nameEntry.X, nameEntry.Y - 10);
                    SwinGame.DrawTextOnScreen("Server:", Color.White, _box.X, _box.Y - 10);
                    nameEntry.Draw();

                    if (_connected)
                    {
                        connectRect.Draw();
                        SwinGame.DrawTextOnScreen("Play", Color.White, connectRect.X + (connectRect.Width / 2) - 16, connectRect.Y + 6);

                        if (SwinGame.MouseClicked(MouseButton.LeftButton) && connectRect.IsAt(SwinGame.MousePosition()) && !_box.DroppedDown)
                        {
                            Play(nameEntry.Text);
                        }
                    }

                    _box.Draw();
                }
                else
                {
                    if (SwinGame.KeyTyped(KeyCode.vk_SPACE))
                    {
                        PushMessage(17);
                    }
                    else if (SwinGame.KeyTyped(KeyCode.vk_w))
                    {
                        PushMessage(21);
                    }
                    else
                    {
                        Movement();
                    }
                }



                //Draw server info
                SwinGame.DrawTextOnScreen(string.Format("{0} FPS", SwinGame.GetFramerate()), Color.Black, 0, 0);

                if (_agarWorld != null)
                    SwinGame.DrawTextOnScreen(string.Format("{0},{1}", Math.Round(_agarWorld.CameraX), Math.Round(_agarWorld.CameraY)), Color.Black, 0, 10);

                SwinGame.DrawTextOnScreen(_packetText, Color.Black, 0, 20);
                SwinGame.DrawTextOnScreen(_ipAddress, Color.Black, 0, 30);

                //Draw Leaderboard Info
                string players = "";
                foreach (LeaderboardPlayer p in _leaderboard)
                {
                    players += string.Format("{0}. {1} ", p.Rank, p.Name);
                }
                SwinGame.DrawTextOnScreen(players, Color.Black, _leaderboardMarquee, SwinGame.ScreenHeight() - 10);
                if (players.Length * 8 > SwinGame.ScreenWidth())
                {
                    _leaderboardMarquee += 1;
                }
                else
                {
                    _leaderboardMarquee = 0;
                }
                if (_leaderboardMarquee > SwinGame.ScreenWidth())
                {
                    _leaderboardMarquee = -(players.Length * 8);
                }



                //Refresh the screen at ~60 fps
                SwinGame.RefreshScreen(60);
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            //Create collections to hold leaderboard, packet count and server list
            _leaderboard = new List <LeaderboardPlayer>();
            _packetCount = new Dictionary <int, int>();
            _serverList  = new List <Server>();

            _showPopup = true;

            //Open the game window
            SwinGame.OpenGraphicsWindow("Petri", 1024, 800);

            //Load the Arial font
            Font _gameFont = SwinGame.LoadFont("Arial", 14);

            Rectangle background = new Rectangle(SwinGame.RGBAColor(0, 0, 0, 155), (SwinGame.ScreenWidth() / 2) - (300 / 2),
                                                 (SwinGame.ScreenHeight() / 2) - (200 / 2), 300, 150, false);

            //Create a textbox to get the nick name
            TextBox nameEntry = new TextBox(_gameFont, (SwinGame.ScreenWidth() / 2) - (190 / 2), background.Y + 30, 190, 20, 16);

            //Create a combobox to select the server
            _box = new ComboBox(_gameFont, nameEntry.X, background.Y + 70, 190, 20);
            _box.ItemSelected += box_ItemSelected;
            _box.Text          = "Loading servers...";

            Rectangle connectRect = new Rectangle(Color.DarkGray, _box.X, background.Y + background.Height - 30, 190, 20, false);

            while (!SwinGame.WindowCloseRequested())
            {
                //Init the server info on load
                if (!_startup)
                {
                    _startup = true;
                    LoadData(_box);
                }

                //Check for any clicks/key presses
                SwinGame.ProcessEvents();

                //Clear the screen
                SwinGame.ClearScreen(Color.White);

                //Draw the world and contents within
                if (_agarWorld != null)
                {
                    _agarWorld.Draw();
                }

                //Draw menu
                if (_showPopup)
                {
                    background.Draw();

                    SwinGame.DrawTextOnScreen("Name:", Color.White, nameEntry.X, nameEntry.Y - 10);
                    SwinGame.DrawTextOnScreen("Server:", Color.White, _box.X, _box.Y - 10);
                    nameEntry.Draw();

                    if (_connected)
                    {
                        connectRect.Draw();
                        SwinGame.DrawTextOnScreen("Play", Color.White, connectRect.X + (connectRect.Width / 2) - 16, connectRect.Y + 6);

                        if (SwinGame.MouseClicked(MouseButton.LeftButton) && connectRect.IsAt(SwinGame.MousePosition()) && !_box.DroppedDown)
                        {
                            Play(nameEntry.Text);
                        }
                    }

                    _box.Draw();
                }
                else
                {
                    if (SwinGame.KeyTyped(KeyCode.vk_SPACE))
                    {
                        PushMessage(17);
                    }
                    else if (SwinGame.KeyTyped(KeyCode.vk_w))
                    {
                        PushMessage(21);
                    }
                    else
                    {
                        Movement();
                    }
                }



                //Draw server info
                SwinGame.DrawTextOnScreen(string.Format("{0} FPS", SwinGame.GetFramerate()), Color.Black, 0, 0);

                if (_agarWorld != null)
                {
                    SwinGame.DrawTextOnScreen(string.Format("{0},{1}", Math.Round(_agarWorld.CameraX), Math.Round(_agarWorld.CameraY)), Color.Black, 0, 10);
                }

                SwinGame.DrawTextOnScreen(_packetText, Color.Black, 0, 20);
                SwinGame.DrawTextOnScreen(_ipAddress, Color.Black, 0, 30);

                //Draw Leaderboard Info
                string players = "";
                foreach (LeaderboardPlayer p in _leaderboard)
                {
                    players += string.Format("{0}. {1} ", p.Rank, p.Name);
                }
                SwinGame.DrawTextOnScreen(players, Color.Black, _leaderboardMarquee, SwinGame.ScreenHeight() - 10);
                if (players.Length * 8 > SwinGame.ScreenWidth())
                {
                    _leaderboardMarquee += 1;
                }
                else
                {
                    _leaderboardMarquee = 0;
                }
                if (_leaderboardMarquee > SwinGame.ScreenWidth())
                {
                    _leaderboardMarquee = -(players.Length * 8);
                }



                //Refresh the screen at ~60 fps
                SwinGame.RefreshScreen(60);
            }
        }
Ejemplo n.º 3
0
 public override bool IsAt(Point2D pt)
 {
     return(_rect.IsAt(pt));
 }