Ejemplo n.º 1
0
        private void CreateTouchListener()
        {
            var touchListener = new CCEventListenerTouchAllAtOnce();

            touchListener.OnTouchesBegan = HandleTouchesBegan;
            gameplayLayer.AddEventListener(touchListener);
        }
Ejemplo n.º 2
0
        override protected void AddedToScene()
        {
            var touchListener = new CCEventListenerTouchAllAtOnce();

            touchListener.OnTouchesBegan = OnTouchesBeganHandler;
            layer.AddEventListener(touchListener);
        }
Ejemplo n.º 3
0
        private void HandleViewCreated(object sender, EventArgs e)
        {
            if (!(sender is CCGameView gameView))
            {
                return;
            }

            // This sets the game "world" resolution to 100x100:
            gameView.DesignResolution = _viewResolution;

            // GameScene is the root of the CocosSharp rendering hierarchy:
            CCScene gameScene = new CCScene(gameView);

            SetupGameScene(gameScene);

            // Register for touch events
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan += OnTouchBegan;
            touchListener.OnTouchMoved += OnTouchMoved;

            _layer.AddEventListener(touchListener, _layer);

            // Starts CocosSharp:
            gameView.RunWithScene(gameScene);
        }
        public TouchScreenInput(CCLayer owner)
        {
            this.owner = owner;

            touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesMoved = HandleTouchesMoved;
            touchListener.OnTouchesBegan = HandleTouchesBegan;
            owner.AddEventListener(touchListener);
        }
Ejemplo n.º 5
0
        public TouchScreenInput(CCLayer owner, ButtonJumpLarge designatedButton, Player player)
        {
            this.designatedButton = designatedButton;
            this.owner            = owner;
            this.player           = player;

            analogStick       = new TouchScreenAnalogStick();
            analogStick.Owner = owner;

            touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesMoved = HandleTouchesMoved;
            touchListener.OnTouchesBegan = HandleTouchesBegan;
            owner.AddEventListener(touchListener);
        }
Ejemplo n.º 6
0
        public Button(CCLayer layer)
        {
            // Give it a default texture, may get changed in ButtonStyle
            sprite = new CCSprite("ui/buttonup.png");
            sprite.IsAntialiased = false;
            this.AddChild(sprite);

            label = new CCLabel("", "fonts/alphbeta.ttf", 24, CCLabelFormat.SystemFont);
            label.IsAntialiased = false;
            this.AddChild(label);

            var touchListener = new CCEventListenerTouchAllAtOnce();

            touchListener.OnTouchesBegan = HandleTouchesBegan;
            layer.AddEventListener(touchListener);
        }
Ejemplo n.º 7
0
        public GameOverScene(CCWindow window, int score)
            : base(window)
        {
            var gameoverLayer = new CCLayer();

            AddChild(gameoverLayer);

            var endGameLabel = new CCLabel("Game Over\nFinal Score:" + score, "Arial", 40, CCLabelFormat.SystemFont)
            {
                Color     = CCColor3B.White,
                PositionX = gameoverLayer.ContentSize.Width / 2.0f,
                PositionY = gameoverLayer.ContentSize.Height / 2.0f
            };

            var touchListener = new CCEventListenerTouchAllAtOnce
            {
                OnTouchesBegan = (touches, @event) => Director.ReplaceScene(new GameScene(Window))
            };

            gameoverLayer.AddChild(endGameLabel);
            gameoverLayer.AddEventListener(touchListener);
        }
Ejemplo n.º 8
0
        public TitleScene(CCWindow window)
            : base(window)
        {
            var layer = new CCLayer();

            AddChild(layer);

            var label = new CCLabel("Tap to begin", "Arial", 30, CCLabelFormat.SystemFont)
            {
                PositionX = layer.ContentSize.Width / 2.0f,
                PositionY = layer.ContentSize.Height / 2.0f,
                Color     = CCColor3B.White
            };

            var touchListener = new CCEventListenerTouchAllAtOnce
            {
                OnTouchesBegan = (touches, @event) => Director.ReplaceScene(new GameScene(this.Window))
            };

            layer.AddChild(label);
            layer.AddEventListener(touchListener);
        }
Ejemplo n.º 9
0
        void HandleViewCreated(object sender, EventArgs e)
        {
            //loads the view
            var ccGView            = sender as CCGameView;
            var contentSearchPaths = new List <string>()
            {
                "Resources", "Assets"
            };

            ccGView.ContentManager.SearchPaths = contentSearchPaths;

            if (ccGView != null)
            {
                //if the view is created then load all the assets
                ccGView.DesignResolution = new CCSizeI(App.Width, App.Height);
                _scene = new CCScene(ccGView);
                _layer = new CCLayer();
                _scene.AddLayer(_layer);

                //ship
                ship           = new Ship(this);
                ship.PositionX = ((App.Width) / 2);
                ship.PositionY = ((App.Height) / 4);

                _layer.AddChild(ship);

                //starts are generated as particles
                var stars = new CCParticleRain(new CCPoint(200, App.Height))
                {
                    StartSize      = 1,
                    Color          = CCColor3B.White,
                    Speed          = 250,
                    SourcePosition = new CCPoint(0.0f, -10.0f),
                };
                stars.StartColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
                _layer.AddChild(stars);


                var faststars = new CCParticleRain(new CCPoint(200, App.Height))
                {
                    StartSize      = 1,
                    Speed          = 500,
                    SourcePosition = new CCPoint(0.0f, -10.0f),
                };
                faststars.StartColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
                _layer.AddChild(faststars);

                var slowstars = new CCParticleRain(new CCPoint(200, App.Height))
                {
                    TotalParticles = 1,
                    StartSize      = 2,
                    Color          = CCColor3B.Blue,
                    Speed          = 50,
                    SourcePosition = new CCPoint(0.0f, -10.0f),
                };
                faststars.StartColor = new CCColor4F(0.0f, 0.0f, 1.0f, 1.0f);
                _layer.AddChild(slowstars);
                //the fire trailing the rocket
                fire = new CCParticleFire(new CCPoint(((App.Width) / 2), ((App.Height) / 4)))
                {
                    StartSize      = 1,
                    Angle          = 270,
                    Speed          = 100,
                    SourcePosition = new CCPoint(0.0f, -10.0f),
                };
                _layer.AddChild(fire);
                //the handlers for the screne being touched
                var touchEvent = new CCEventListenerTouchAllAtOnce();
                touchEvent.OnTouchesEnded = OnTouchesEnded;
                _layer.AddEventListener(touchEvent);

                //asteroid
                asteroids = new List <Asteroid>();
                void HandleAsteroidCreated(Asteroid newAsteroid)
                {
                    _layer.AddChild(newAsteroid);
                    asteroids.Add(newAsteroid);
                }

                AsteroidFactory.Self.AsteroidCreated += HandleAsteroidCreated;

                //psyche

                psyche           = new Psyche();
                psyche.PositionX = 200;
                psyche.PositionY = 4000;
                psyche.VelocityY = -50;
                _layer.AddChild(psyche);
                ccGView.RunWithScene(_scene);
            }
        }