Ejemplo n.º 1
0
        private void Initialize(Event e)
        {
            RemoveEventListener(Event.ADDED_TO_STAGE, Initialize);

            var bg = new Bitmap(Assets.GetBitmapData("background"));
            AddChild(bg);
            bg.ScaleX = bg.ScaleY = stage.StageWidth;

            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(String.Format("layer{0}", i + 1)));
                var bmp2 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1)));

                bmp2.X = bmp1.Width;

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

                bgContainer.AddChild(bgLayers[i]);
            }
            bgLayers[0].Y -= bgLayers[0].Height * 0.2f;
            bgLayers[0].ScaleY *= 1.2f;
        }
Ejemplo n.º 2
0
        private void Initialize(Event e)
        {
            RemoveEventListener(Event.ADDED_TO_STAGE, Initialize);

            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(String.Format("layer{0}", i + 1)));
                var bmp2 = new Bitmap(Assets.GetBitmapData(String.Format("layer{0}", i + 1)));

                bmp2.X = bmp1.Width;

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

                bgContainer.AddChild(bgLayers[i]);
            }

            AddEventListener(Event.ENTER_FRAME, Update);
        }
Ejemplo n.º 3
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);
        }
        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]);
            }
            // GUI
            guiContainer = new Sprite();
            AddChild(guiContainer);

            NetPeerConfiguration config = new NetPeerConfiguration("multiplanes-network");
            client = new NetClient(config);
            client.Start();
            client.DiscoverLocalPeers(14242);
            client.DiscoverKnownPeer(GameClient.NET_ADRESS, GameClient.NET_PORT);

            nick = NickGenerator.GenerateNick(client.UniqueIdentifier);

            var screenNameLabel = new TextField();
            screenNameLabel.font = Assets.GetFont("assets/MainFont");
            screenNameLabel.text = "HOST GAME";
            screenNameLabel.X = GameMain.ScreenWidth / 2 - screenNameLabel.Width / 2;
            screenNameLabel.Y = 10 / GameMain.mainScale;
            guiContainer.AddChild(screenNameLabel);

            var roomNameLabel = new TextField();
            roomNameLabel.font = screenNameLabel.font;
            roomNameLabel.text = "Room name: " + nick;
            roomNameLabel.X = GameMain.ScreenWidth * 0.1f;
            roomNameLabel.Y = GameMain.ScreenHeight / 2 - roomNameLabel.Height / 2;
            roomNameLabel.ScaleX = roomNameLabel.ScaleY = 0.5f;
            guiContainer.AddChild(roomNameLabel);

            waitLabel = new TextField();
            waitLabel.font = roomNameLabel.font;
            waitLabel.text = "Waiting for other player to connect. . .";
            waitLabel.X = roomNameLabel.X;
            waitLabel.Y = roomNameLabel.Y + roomNameLabel.Height;
            waitLabel.ScaleX = waitLabel.ScaleY = 0.25f;
            guiContainer.AddChild(waitLabel);
        }
Ejemplo n.º 5
0
        void LoadBackground(int levelNumber)
        {
            levelNumber += 1;
            if (levelNumber > 4)
                throw new IndexOutOfRangeException();

            // Удаляем старый фон
            for (int i = 0; i < 3; ++i)
            {
                bgContainer.RemoveChild(bgLayers[i]);
                bgLayers[i] = null;
            }

            for (int i = 0; i < 3; ++i)
            {
                bgLayers[i] = new Sprite();

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

                bmp2.X = bmp1.Width;
                bgLayers[i].AddChild(bmp1);
                bgLayers[i].AddChild(bmp2);
                bgContainer.AddChild(bgLayers[i]);
            }
        }
Ejemplo n.º 6
0
        public override void Load()
        {
            worldContainer = new Sprite();
            AddChild(worldContainer);

            bullets = new List<Bullet>();
            reloadTime = 0;

            // Фон
            bgLayers = new Sprite[3];
            bgContainer = new Sprite();
            worldContainer.AddChild(bgContainer);

            LoadBackground(levelNumber);

            // Игра
            gameContainer = new Sprite();
            worldContainer.AddChild(gameContainer);

            localPlayer = new Player(localNick, true);
            remotePlayer = new Player(remoteNick, false);
            if (isHost)
            {
                localPlayer.X = localPlayer.Y = remotePlayer.Y = 10;
                remotePlayer.X = WORLD_WIDTH - GameMain.ScreenWidth / 2;
                remotePlayer.Rotation = 180;
                remotePlayer.ScaleY = -1;
            }
            else
            {
                remotePlayer.X = remotePlayer.Y = localPlayer.Y = 10;
                localPlayer.X = WORLD_WIDTH - GameMain.ScreenWidth / 2;
                localPlayer.Rotation = 180;
                localPlayer.ScaleY = -1;
            }
            gameContainer.AddChild(localPlayer);
            gameContainer.AddChild(remotePlayer);

            // Интерфейс
            guiContainer = new Sprite();
            AddChild(guiContainer);

            #if __MOBILE__
            // Кнопка тормоза
            decelerateButton = new Bitmap(Assets.GetBitmapData("assets/ui/down"));
            decelerateButton.Y = GameMain.ScreenHeight - decelerateButton.Height;
            guiContainer.AddChild(decelerateButton);
            decelerateButton.AddEventListener(Event.TOUCH_MOVE, onDecelerateBegin);
            decelerateButton.AddEventListener(Event.TOUCH_END, onDecelerateEnd);
            // Кнопка вправо
            rightButton = new Bitmap(Assets.GetBitmapData("assets/ui/right"));
            rightButton.X = GameMain.ScreenWidth - rightButton.Width;
            rightButton.Y = decelerateButton.Y;
            guiContainer.AddChild(rightButton);
            rightButton.AddEventListener(Event.TOUCH_MOVE, onRotateBegin);
            rightButton.AddEventListener(Event.TOUCH_END, onRotateEnd);
            // Кнопка вправо
            leftButton = new Bitmap(Assets.GetBitmapData("assets/ui/left"));
            leftButton.X = rightButton.X - leftButton.Width;
            leftButton.Y = rightButton.Y;
            guiContainer.AddChild(leftButton);
            leftButton.AddEventListener(Event.TOUCH_MOVE, onRotateBegin);
            leftButton.AddEventListener(Event.TOUCH_END, onRotateEnd);
            // Кнопка стрельбы
            fireButton = new Bitmap(Assets.GetBitmapData("assets/ui/fire"));
            fireButton.X = decelerateButton.X + decelerateButton.Width;
            fireButton.Y = decelerateButton.Y;
            guiContainer.AddChild(fireButton);
            fireButton.AddEventListener(Event.TOUCH_END, onFireBegin);
            leftButton.color = rightButton.color = decelerateButton.color = fireButton.color = new Color(Color.DarkGray, 20);
            #endif

            if (isHost)
                ChangeLevel();

            resultLabel = new TextField();
            resultLabel.font = Assets.GetFont("assets/MainFont");
            resultLabel.visible = false;

            countLabel = new TextField();
            countLabel.font = resultLabel.font;
            countLabel.visible = false;

            guiContainer.AddChild(resultLabel);
            guiContainer.AddChild(countLabel);
        }
Ejemplo n.º 7
0
        public override void Load()
        {
            random = new Random();

            background = new GameBackground();
            AddChild(background);
            background.Y += GameMain.ScreenHeight * 0.2f;
            gameContainer = new Sprite();
            AddChild(gameContainer);

            player = new Player();
            player.X = 5 * Level.TILE_SIZE;
            player.Y = 5 * Level.TILE_SIZE;

            objects = new List<MovingObject>();
            objects.Add(player);
            bullets = new List<Bullet>();

            particleTexture = Assets.GetBitmapData("blood");
            particles = new List<Particle>();

            level = new Level(1);

            gameContainer.AddChild(level);

            gameInterface = new GameInterface();
            #if __MOBILE__
            AddChild(gameInterface);
            gameInterface.left.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.right.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.up.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            gameInterface.left.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.right.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.up.AddEventListener(Event.TOUCH_END, buttonTouchEnd);
            gameInterface.fire.AddEventListener(Event.TOUCH_BEGIN, buttonTouchBegin);
            #endif
            inputX = 0;
            inputY = 0;

            tutorText = new TextField();
            tutorText.font = Assets.GetFont("MainFont");
            tutorText.text = "JUMP!!!";
            tutorText.X = (PHYS_BEGIN + 1) * Level.TILE_SIZE;
            tutorText.Y = 5 * Level.TILE_SIZE;

            gameContainer.AddChild(player);

            var zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 5 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 10 * Level.TILE_SIZE;
            zombie.Y = 6 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 11 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            var zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 7 * Level.TILE_SIZE;
            zombie2.Y = 4 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 15 * Level.TILE_SIZE;
            zombie2.Y = 9 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 30 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 32 * Level.TILE_SIZE;
            zombie.Y = 6 * Level.TILE_SIZE;

            zombie = new Zombie(player);
            gameContainer.AddChild(zombie);
            objects.Add(zombie);
            zombie.X = 35 * Level.TILE_SIZE;
            zombie.Y = 5 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 40 * Level.TILE_SIZE;
            zombie2.Y = 8 * Level.TILE_SIZE;

            zombie2 = new Bug(player);
            gameContainer.AddChild(zombie2);
            objects.Add(zombie2);
            zombie2.X = 55 * Level.TILE_SIZE;
            zombie2.Y = 9 * Level.TILE_SIZE;

            gameContainer.AddChild(tutorText);
        }