Esempio n. 1
0
        public override void Tick(float dt)
        {
            //base.Tick(dt);
            if (Player.Instance == null)
            {
            }
            else
            {
                setCameraPosition();
            }

            //check bullet delay
            if (Bullet.bulletDelay > 0)
            {
                Bullet.bulletDelay--;
            }

            //check buttons
            if (Input2.GamePad0.Cross.Down || Input2.GamePad0.R.Down)
            {
                if (Bullet.bulletDelay == 0 && Player.Instance.ammo > 0)
                {
                    SoundSystem.Instance.Play("shot.wav");
                    Bullet bullet = new Bullet();
                    bulletList.Add(bullet);
                    World.AddChild(bullet);
                    Bullet.bulletDelay = 2;
                    Player.Instance.ammo--;

                    //update player's sprite
                    Player.Instance.playerBodySprite.TileIndex1D = Player.Instance.animationFrame;
                    Player.Instance.animationFrame = (Player.Instance.animationFrame + 1) % Player.Instance.playerBodySprite.TextureInfo.NumTiles.X;
                }
            }

            //check buttons
            if (Input2.GamePad0.Cross.Release || Input2.GamePad0.R.Release)
            {
                //update player's sprite
                Player.Instance.playerBodySprite.TileIndex1D = 0;
            }


            //check start button(for pause menu)
            if (Input2.GamePad0.Start.Press)
            {
                this.paused = true;
                SceneManager.Instance.pushScene(PauseScene.Instance);
            }

            // pinch-to-zoom
            //only check for multitouch points if device supports more than one touch point
            if (Input2.Touch.MaxTouch > 1)
            {
                //only proceed if the user is actually touching both points
                if (Input2.Touch.GetData(0)[0].Down && Input2.Touch.GetData(0)[1].Down)
                {
                    //first touch point
                    Vector2 touch1 = Director.Instance.CurrentScene.GetTouchPos(0);

                    //second touch point
                    Vector2 touch2 = Director.Instance.CurrentScene.GetTouchPos(1);

                    //reset the distance measure if the screen has just been touched
                    if (Input2.Touch.GetData(0)[0].Press || Input2.Touch.GetData(0)[1].Press)
                    {
                        multitouchDistance = touch1.Distance(touch2);
                    }
                    else
                    {
                        var newDistance = touch1.Distance(touch2);

                        cameraHeight += (multitouchDistance - newDistance);
                        this.Camera2D.SetViewFromHeightAndCenter(cameraHeight, Player.Instance.Position);
                    }
                }
            }


            //check if the player has collected any ammo packs
            AmmoItem ammoItemToRemove;

            if (Collisions.checkAmmoPackCollisions(Player.Instance, ammoList, out ammoItemToRemove))
            {
                Game.Instance.EffectsLayer.AddChild(new ammoMarker(ammoItemToRemove.Position));
                SoundSystem.Instance.Play("ammoclip.wav");
                World.RemoveChild(ammoItemToRemove, true);
                ammoList.Remove(ammoItemToRemove);

                Player.Instance.ammo = (int)FMath.Clamp((Player.Instance.ammo + 50), 100, 100);

                ammoItemToRemove.Die();
            }



            if (Player.Instance.Health <= 0)
            {
                Background.RemoveAllChildren(true);
                Foreground.RemoveAllChildren(true);
                EffectsLayer.RemoveAllChildren(true);
                World.RemoveAllChildren(true);
                Interface.RemoveAllChildren(true);



                SceneManager.Instance.changeSceneTo(GameOverScene.Instance);
                //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Unschedule(Scene, gameTick);
                //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(Scene, gameoverTick, 0.0f, false);
            }
        }