Пример #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);
     }
 }
Пример #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);
        }
Пример #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;
         }
     }
 }
Пример #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());
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #8
0
 private void onAddedToStage(Event e)
 {
     foreach (var cC in children)
     {
         cC.stage = stage;
     }
 }
 void onRotateEnd(Event e)
 {
     inputX = 0;
 }
Пример #10
0
 void onRotateBegin(Event e)
 {
     if (e.currentTarget == leftButton)
         inputX = -1;
     if (e.currentTarget == rightButton)
         inputX = 1;
 }
Пример #11
0
 void onFireBegin(Event e)
 {
     CreateLocalShot();
 }
Пример #12
0
 void onDecelerateEnd(Event e)
 {
     inputY = 1;
 }
Пример #13
0
 void onDecelerateBegin(Event e)
 {
     inputY = -1;
 }
Пример #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);
                }
            }
        }
Пример #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);
         }
     }
 }
Пример #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();
     }
 }
Пример #19
0
 void UpdateMousePosition(Event e)
 {
     MouseX = e.position.X;
     MouseY = e.position.Y;
 }
Пример #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;
     }
 }
Пример #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);
         }
     }
 }
Пример #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());
 }
Пример #23
0
 private void levelButtonClick(Event e)
 {
     if (e.target == Levels[0])
     {
         GameMain.screenManager.LoadScreen(new GameScreen());
     }
 }
Пример #24
0
 private void changeLevels(Event e)
 {
     GameMain.screenManager.LoadScreen(new ChangeLevelsScreen());
 }
Пример #25
0
 private void Update(Event e)
 {
 }
Пример #26
0
 void backToMenu(Event e)
 {
     GameMain.screenManager.LoadScreen(new MenuScreen());
 }
Пример #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
        }
Пример #28
0
 void hostGameEvent(Event e)
 {
     Debug.WriteLine("Hosting game!");
     GameMain.screenManager.LoadScreen(new HostGameScreen());
 }