示例#1
0
        public override void Load()
        {
            // Создаем фон
            bgContainer = new Sprite();
            bgLayers    = new Sprite[3];
            AddChild(bgContainer);
            for (int i = 0; i < 3; ++i)
            {
                bgLayers[i] = new Sprite();

                var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
                var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));

                bmp2.X = bmp1.Width;

                bgLayers[i].AddChild(bmp1);
                bgLayers[i].AddChild(bmp2);

                bgContainer.AddChild(bgLayers[i]);
            }
            // Интерфейс Меню
            guiContainer = new Sprite();
            AddChild(guiContainer);
            // Лого
            logo = new Bitmap(Assets.GetBitmapData("assets/logo", true));
//            logo.font = Assets.GetFont("assets/MainFont");
//            logo.text = "MULTIPLANES";
            logo.X = GameMain.ScreenWidth / 2 - logo.Width / 2;
            logo.Y = 10 / GameMain.mainScale;
            time   = 0;
            guiContainer.AddChild(logo);
            // Кнопка join
            joinButton        = new TextField();
            joinButton.font   = Assets.GetFont("assets/MainFont");
            joinButton.text   = "Join game";
            joinButton.ScaleX = joinButton.ScaleY = 0.5f;
            joinButton.X      = GameMain.ScreenWidth / 2 - joinButton.Width / 2;
            joinButton.Y      = GameMain.ScreenHeight / 2 + joinButton.Height;
            guiContainer.AddChild(joinButton);
            // Самолетик
            plane   = new Bitmap(Assets.GetBitmapData("assets/plane_red"));
            plane.Y = (joinButton.Y + (logo.Y + logo.Height)) / 2 - plane.Height / 2;
            plane.X = GameMain.ScreenWidth / 2 - plane.Width / 2;
            guiContainer.AddChild(plane);
            // Кнопка host
            hostButton        = new TextField();
            hostButton.font   = joinButton.font;
            hostButton.text   = "Host game";
            hostButton.ScaleX = hostButton.ScaleY = 0.5f;
            hostButton.X      = GameMain.ScreenWidth / 2 - hostButton.Width / 2;
            hostButton.Y      = joinButton.Y + joinButton.Height;
            guiContainer.AddChild(hostButton);
            joinButton.AddEventListener(Event.TOUCH_END, joinGameEvent);
            hostButton.AddEventListener(Event.TOUCH_END, hostGameEvent);
        }
示例#2
0
        public override void Load()
        {
            // Background
            bgContainer = new Sprite();
            bgLayers    = new Sprite[3];
            AddChild(bgContainer);
            for (int i = 0; i < 3; ++i)
            {
                bgLayers[i] = new Sprite();

                var bmp1 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));
                var bmp2 = new Bitmap(Assets.GetBitmapData("assets/background/1/" + (i + 1).ToString(), true));

                bmp2.X = bmp1.Width;

                bgLayers[i].AddChild(bmp1);
                bgLayers[i].AddChild(bmp2);

                bgContainer.AddChild(bgLayers[i]);
            }
            // GUI
            guiContainer = new Sprite();
            AddChild(guiContainer);

            hosts = new List <HostLabel>();

            font = Assets.GetFont("assets/MainFont");

            var screenNameLabel = new TextField();

            screenNameLabel.font = font;
            screenNameLabel.text = "JOIN GAME";
            screenNameLabel.X    = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
            screenNameLabel.Y    = 10 / GameMain.mainScale;
            guiContainer.AddChild(screenNameLabel);

            pointerLabel        = new TextField();
            pointerLabel.font   = screenNameLabel.font;
            pointerLabel.text   = "Select a game to join";
            pointerLabel.ScaleX = pointerLabel.ScaleY = 0.4f;
            pointerLabel.X      = GameMain.ScreenWidth / 2 - pointerLabel.Width / 2;
            pointerLabel.Y      = screenNameLabel.Y + screenNameLabel.Height;
            guiContainer.AddChild(pointerLabel);

            connectButton           = new TextField();
            connectButton.font      = font;
            connectButton.text      = "Connect";
            connectButton.ScaleX    = connectButton.ScaleY = 0.5f;
            connectButton.X         = GameMain.ScreenWidth * 0.25f - connectButton.Width / 2;
            connectButton.Y         = GameMain.ScreenHeight - connectButton.Height;
            connectButton.textColor = Color.DarkGray;
            guiContainer.AddChild(connectButton);

            refreshButton        = new TextField();
            refreshButton.font   = font;
            refreshButton.text   = "Refresh";
            refreshButton.ScaleX = refreshButton.ScaleY = 0.5f;
            refreshButton.X      = GameMain.ScreenWidth * 0.75f - refreshButton.Width / 2;
            refreshButton.Y      = connectButton.Y;
            guiContainer.AddChild(refreshButton);

            connectButton.AddEventListener(Event.TOUCH_END, onButtonDown);
            refreshButton.AddEventListener(Event.TOUCH_END, onButtonDown);

            NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");

            client = new NetClient(config);
            client.Start();
            nick = NickGenerator.GenerateNick((client.UniqueIdentifier));
            client.DiscoverLocalPeers(14242);
            client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);
        }