Exemplo 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;
        }
 private void Update(Event e)
 {
     if (currentScreen != null)
     {
         currentScreen.Update(Application.deltaTime);
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 private void Update(Event e)
 {
     for (int i = 0; i < bgLayers.Length; ++i)
     {
         var layer = bgLayers[i];
         layer.X -= LAYER_DEPTHS[i];
         if (layer.X <= -layer.Width / 2)
         {
             layer.X += layer.Width / 2;
         }
     }
 }
Exemplo n.º 5
0
        private void Initialize(Event e)
        {
            RemoveEventListener(Event.ADDED_TO_STAGE, Initialize);

            // Глобальный масштаб и размер экрана
            mainScale = stage.StageHeight / 128;
            screenSize = new Vector2(stage.StageWidth, stage.StageHeight) / mainScale;

            screenManager = new ScreenManager();
            screenManager.ScaleX = screenManager.ScaleY = mainScale;
            AddChild(screenManager);

            // Запуск начального экрана
            screenManager.LoadScreen(new MenuScreen());
        }
Exemplo n.º 6
0
        public void DispatchEvent(Event e)
        {
            if (!handlers.ContainsKey(e.type))
            {
                return;
            }

            if (e.target == null)
            {
                e.target = this;
            }
            e.currentTarget = this;

            for (int i = 0; i < handlers[e.type].Count; i++)
            {
                EventHandler handler = handlers[e.type].ElementAt(i);
                handler(e);
            }
        }
Exemplo n.º 7
0
        private void Initialize(Event e)
        {
            RemoveEventListener(Event.ADDED_TO_STAGE, Initialize);

            fire = new Bitmap(Assets.GetBitmapData("fire"));
            left = new Bitmap(Assets.GetBitmapData("left"));
            right = new Bitmap(Assets.GetBitmapData("right"));
            up = new Bitmap(Assets.GetBitmapData("up"));

            AddChild(fire);
            fire.X = stage.StageWidth / GameMain.mainScale - fire.Width / GameMain.mainScale - 20;
            fire.Y = stage.StageHeight / GameMain.mainScale - fire.Height / GameMain.mainScale - 13;
            AddChild(left);
            left.X = 10;
            left.Y = fire.Y;
            AddChild(right);
            right.X = left.X + left.Width + 10;
            right.Y = fire.Y;
            AddChild(up);
            up.X = fire.X - up.Width / GameMain.mainScale - 20;
            up.Y = fire.Y;

            //            AddEventListener(Event.ENTER_FRAME, Update);
        }
Exemplo n.º 8
0
 private void onAddedToStage(Event e)
 {
     foreach (var cC in children)
     {
         cC.stage = stage;
     }
 }
 void onRotateEnd(Event e)
 {
     inputX = 0;
 }
Exemplo n.º 10
0
 void onRotateBegin(Event e)
 {
     if (e.currentTarget == leftButton)
         inputX = -1;
     if (e.currentTarget == rightButton)
         inputX = 1;
 }
Exemplo n.º 11
0
 void onFireBegin(Event e)
 {
     CreateLocalShot();
 }
Exemplo n.º 12
0
 void onDecelerateEnd(Event e)
 {
     inputY = 1;
 }
Exemplo n.º 13
0
 void onDecelerateBegin(Event e)
 {
     inputY = -1;
 }
Exemplo n.º 14
0
        private void buttonTouchBegin(Event e)
        {
            if (e.target == gameInterface.left)
            {
                inputX = -1;
            }
            else if (e.target == gameInterface.right)
            {
                inputX = 1;
            }
            else
            {
                inputX = 0;
            }

            if (e.target == gameInterface.up)
            {
                inputY = -1;
            }

            if (e.target == gameInterface.fire)
            {
                var b = player.Shoot();
                if (b != null)
                {
                    bullets.Add(b);
                    gameContainer.AddChildAt(b, gameContainer.GetChildIndex(player) - 1);
                }
            }
        }
Exemplo n.º 15
0
 private void DispatchEventToClickedChildren(Event e)
 {
     for (int i = 0; i < children.Count; ++i)
     {
         var child = children[i];
         if (child == null)
         {
             continue;
         }
         if (child.isClicked)
         {
             var touchEvent = new Event(e.type);
             touchEvent.position = child.GlobalToLocal(this.LocalToGlobal(e.position));
             child.isClicked = false;
             child.DispatchEvent(touchEvent);
         }
     }
 }
Exemplo n.º 16
0
 private void AddedToStage(Event e)
 {
     stage = parent.stage;
 }
 void onTouchUp(Event e)
 {
     var field = e.target as HostLabel;
     if (!field.IsSelected)
     {
         foreach (var currentHost in hosts)
         {
             if (currentHost.IsSelected)
                 currentHost.IsSelected = false;
         }
     }
     field.IsSelected = !field.IsSelected;
     connectButton.textColor = (field.IsSelected) ? Color.White : Color.DarkGray;
     Debug.WriteLine(field.IsSelected);
 }
 void onButtonDown(Event e)
 {
     var field = e.target as TextField;
     if (field == connectButton)
     {
         if (field.textColor != Color.DarkGray)
         {
             int index = hosts.FindIndex(item => item.IsSelected);
             Debug.WriteLine(index);
             JoinGameRequest(index);
         }
     }
     if (field == refreshButton)
     {
         RefreshHostList();
     }
 }
Exemplo n.º 19
0
 void UpdateMousePosition(Event e)
 {
     MouseX = e.position.X;
     MouseY = e.position.Y;
 }
Exemplo n.º 20
0
 private void buttonTouchEnd(Event e)
 {
     if (e.target == gameInterface.left && inputX < 0)
     {
         inputX = 0;
     }
     else if (e.target == gameInterface.right && inputX > 0)
     {
         inputX = 0;
     }
     if (e.target == gameInterface.up && inputY < 0)
     {
         inputY = 0;
     }
 }
Exemplo n.º 21
0
 private void DispatchEventToHitChildren(Event e)
 {
     for (int i = 0; i < children.Count; i++)
     {
         var child = children[i];
         var touchEvent = new Event(e.type);
         touchEvent.position = child.GlobalToLocal(this.LocalToGlobal(e.position));
         if (child.HitTestPoint(touchEvent.position))
         {
             child.isClicked = true;
             child.DispatchEvent(touchEvent);
         }
     }
 }
Exemplo n.º 22
0
 void joinGameEvent(Event e)
 {
     Debug.WriteLine("Joining Game!");
     //            #if DEBUG
     //            GameMain.screenManager.LoadScreen(new GameScreen(null, NickGenerator.GenerateNick(DateTime.Now.Ticks), "", false));
     //            return;
     //            #endif
     GameMain.screenManager.LoadScreen(new JoinGameScreen());
 }
Exemplo n.º 23
0
 private void levelButtonClick(Event e)
 {
     if (e.target == Levels[0])
     {
         GameMain.screenManager.LoadScreen(new GameScreen());
     }
 }
Exemplo n.º 24
0
 private void changeLevels(Event e)
 {
     GameMain.screenManager.LoadScreen(new ChangeLevelsScreen());
 }
Exemplo n.º 25
0
 private void Update(Event e)
 {
 }
Exemplo n.º 26
0
 void backToMenu(Event e)
 {
     GameMain.screenManager.LoadScreen(new MenuScreen());
 }
Exemplo n.º 27
0
        protected override void Update(GameTime gameTime)
        {
            deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            #if __MOBILE__ || DEBUG
            elapsedTime += gameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate = frameCounter;
                frameCounter = 0;
            }
            #endif

            #if !__IOS__
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();
            #endif
            base.Update(gameTime);

            // Mouse input
            lastMouseState = currentMouseState;
            currentMouseState = Mouse.GetState();

            if (currentMouseState.Position.X >= 0 && currentMouseState.Position.Y >= 0 &&
                currentMouseState.Position.X <= stage.StageWidth && currentMouseState.Position.Y <= stage.StageHeight)
            {
                // Dispatch Event.TOUCH_BEGIN on stage when left button is pressed
                if (lastMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    var mouseDownEvent = new Event(Event.TOUCH_BEGIN);
                    mouseDownEvent.position = currentMouseState.Position.ToVector2();
                    stage.DispatchEvent(mouseDownEvent);
                }
                // Dispatch Event.TOUCH_END on stage when left button is released
                if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                {
                    var mouseUpEvent = new Event(Event.TOUCH_END);
                    mouseUpEvent.position = currentMouseState.Position.ToVector2();
                    stage.DispatchEvent(mouseUpEvent);
                }
                // Dispatch Event.TOUCH_MOVE on stage when mouse is moved
                if (lastMouseState.Position != currentMouseState.Position && currentMouseState.LeftButton == ButtonState.Pressed
                    && lastMouseState.LeftButton == ButtonState.Pressed)
                {
                    var mouseMoveEvent = new Event(Event.TOUCH_MOVE);
                    mouseMoveEvent.position = currentMouseState.Position.ToVector2();
                    stage.DispatchEvent(mouseMoveEvent);
                }
            }

            // Touch input
            #if __MOBILE__
            TouchCollection touches = TouchPanel.GetState();
            foreach (TouchLocation touch in touches)
            {
                var pos = touch.Position;
            #if __IOS__
                pos = new Vector2(pos.X * stage.StageWidth / TouchPanel.DisplayWidth,
                                  pos.Y * stage.StageHeight / TouchPanel.DisplayHeight);
            #endif
                if (touch.State == TouchLocationState.Pressed)
                {
                    var touchBeginEvent = new Event(Event.TOUCH_BEGIN);
                    touchBeginEvent.position = pos;
                    stage.DispatchEvent(touchBeginEvent);
                }
                else if (touch.State == TouchLocationState.Released)
                {
                    var touchEndEvent = new Event(Event.TOUCH_END);
                    touchEndEvent.position = pos;
                    stage.DispatchEvent(touchEndEvent);
                }
                else if (touch.State == TouchLocationState.Moved)
                {
                    var touchMoveEvent = new Event(Event.TOUCH_MOVE);
                    touchMoveEvent.position = pos;
                    stage.DispatchEvent(touchMoveEvent);
                }
            }
            #endif
        }
Exemplo n.º 28
0
 void hostGameEvent(Event e)
 {
     Debug.WriteLine("Hosting game!");
     GameMain.screenManager.LoadScreen(new HostGameScreen());
 }