Пример #1
0
        public EmbarkLayer() : base(CCColor4B.Gray)
        {
            // Nodes
            label    = new CCLabel("Option 1", "fonts/MarkerFelt", 22, CCLabelFormat.SpriteFont);
            drawNode = new CCDrawNode();
            AddChild(label);
            AddChild(drawNode);

            mouseLabel = new CCLabel($"X: 0 Y: 0", "fonts/MarkerFelt", 22, CCLabelFormat.SpriteFont);
            AddChild(mouseLabel);

            yesNo = new YesNoControl();
            drawNode.AddChild(yesNo);

            startButton = new UIButton(new CCSprite("UI/start"))
            {
                SpriteAnchorPoint = CCPoint.AnchorMiddle, Position = new CCPoint(VisibleBoundsWorldspace.MidX, 200)
            };
            startButton.OnClick = Start;
            AddChild(startButton);

            //Events
            var moveListener = new CCEventListenerMouse();

            moveListener.OnMouseMove = (ev) =>
            {
                mouseLabel.Text     = $"X: {ev.CursorX} Y: {VisibleBoundsWorldspace.MaxY - ev.CursorY}";
                mouseLabel.Position = new CCPoint(ev.CursorX, VisibleBoundsWorldspace.MaxY - ev.CursorY);
            };
            AddEventListener(moveListener);
        }
Пример #2
0
        void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (touches.Count > 0)
            {
                _line.DrawLine(touches[0].StartLocation, touches[0].Location, LINE_WIDTH, CCColor4B.Yellow, CCLineCap.Round);

                _lastLineStartPoint = new CCPoint(touches[0].Location);

                _ball.AddChild(_glow);
                _ball.ReorderChild(_glow, 1);
            }
        }
Пример #3
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // Use the bounds to layout the positioning of our drawable assets
            _bounds = VisibleBoundsWorldspace;

            //var background = new CCSprite("background");
            //AddChild(background);

            _targetZone          = new CCDrawNode();
            _targetZone.Position = new CCPoint(_bounds.MaxX - 100, _bounds.MaxY - 100);
            _targetZone.DrawRect(new CCPoint(0, 0), 50, CCColor4B.Transparent);
            AddChild(_targetZone);

            var coinSprite = new CCSprite("coin");

            _targetZone.AddChild(coinSprite);

            _line = new CCDrawNode();
            AddChild(_line);

            _ball          = new CCDrawNode();
            _ball.Position = new CCPoint(100, 100);
            _ball.DrawCircle(new CCPoint(0, 0), 50, CCColor4B.Transparent);
            AddChild(_ball);
            ReorderChild(_ball, 2);

            var ballSprite = new CCSprite("ball");

            _ball.AddChild(ballSprite);
            //ballSprite.Scale = 0.15f;
            _ball.ReorderChild(ballSprite, 2);

            _glow             = new CCParticleSun(new CCPoint(0, 0), CCEmitterMode.Radius);
            _glow.StartColor  = new CCColor4F(CCColor3B.Orange);
            _glow.EndColor    = new CCColor4F(CCColor3B.Yellow);
            _glow.StartRadius = _ball.ContentSize.Width * 0.4f;
            _glow.EndRadius   = _ball.ContentSize.Width * 0.5f;

            Schedule(RunGameLogic);

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

            touchListener.OnTouchesBegan = OnTouchesBegan;
            touchListener.OnTouchesEnded = OnTouchesEnded;
            touchListener.OnTouchesMoved = HandleTouchesMoved;
            AddEventListener(touchListener, _ball);
        }
Пример #4
0
        public override void OnEnter()
        {
            base.OnEnter();

            var effect = new CCSequence(new CCDelayTime(2.0f), new CCShaky3D(5.0f, new CCGridSize(5, 5), 16, false));

            // cleanup
            contentLayer.RemoveChild(bgNode, true);

            // background
            var layer = new CCDrawNode();

            layer.Color   = CCColor3B.Red;
            layer.Opacity = 255;

            layer.DrawRect(VisibleBoundsWorldspace);

            AddChild(layer, -10);

            var sprite = new CCSprite("Images/grossini");

            sprite.Position = new CCPoint(50, 80);
            layer.AddChild(sprite, 10);

            // foreground
            var layer2BaseGrid = new CCNodeGrid();
            var layer2         = new CCDrawNode();

            layer2.Color   = CCColor3B.Green;
            layer2.Opacity = 255;

            layer2.DrawRect(VisibleBoundsWorldspace);

            var fog = new CCSprite("Images/Fog");

            var bf = new CCBlendFunc {
                Source = CCOGLES.GL_SRC_ALPHA, Destination = CCOGLES.GL_ONE_MINUS_SRC_ALPHA
            };

            fog.BlendFunc = bf;
            layer2.AddChild(fog, 1);
            AddChild(layer2BaseGrid, 1);
            layer2BaseGrid.AddChild(layer2);

            layer2BaseGrid.RepeatForever(effect);
        }
Пример #5
0
        void AddShip(CCRect bounds)
        {
            ship = new CCDrawNode();

            CCPoint[] points =
            {
                new CCPoint(0,  25),
                new CCPoint(50,  0),
                new CCPoint(0, -25)
            };

            ship.DrawPolygon(points, points.Length, CCColor4B.White, 1.0f, CCColor4B.Orange);
            ship.Position = new CCPoint(bounds.MinX + 100.0f, bounds.MidY);
            AddChild(ship);

            var fire = new CCParticleFire(new CCPoint(-10.0f, 0.0f));

            fire.Rotation = -90.0f;
            fire.Scale    = 0.5f;
            ship.AddChild(fire);
        }
Пример #6
0
        /// <summary>
        /// Evaluates the lines we have in the buffer
        /// </summary>
        /// <param name="lines">Lines</param>
        /// <remarks>
        /// We keep a buffer of lines. If a list of lines cannot be
        /// evaluated we wait for another second or so to allow for more lines.
        /// When that times out and no shape can be determined, then
        /// we clear the buffer.
        /// </remarks>
        private void EvaluateLines(List <Line> lines)
        {
            _clearTTL = _clearTTLResetValue;
            _buffer.AddRange(lines);

            var result = _patternEvaluator.Evaluate(_buffer);

            if (!result.IsValid)
            {
                return;
            }

            Debug.WriteLine("evaluation succeeded: " + result.Key);

            switch (result.Key)
            {
            case "button":
                var rectShape = new RectangleShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };
                _shapeNode.AddChild(new ShapeNode(rectShape));
                _recognizerCanvasNode.Clear();
                break;

            case "image":
                var imageShape = new ImageShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };
                _shapeNode.AddChild(new ShapeNode(imageShape));
                _recognizerCanvasNode.Clear();
                break;

            case "text":
                var textShape = new TextShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };
                _shapeNode.AddChild(new ShapeNode(textShape));
                _recognizerCanvasNode.Clear();
                break;

            case "entry":
                var entryShape = new EntryShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };
                _shapeNode.AddChild(new ShapeNode(entryShape));
                _recognizerCanvasNode.Clear();
                break;

            case "lineoftext":

                var lineoftext = new LineOfTextShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };
                _shapeNode.AddChild(new ShapeNode(lineoftext));
                _recognizerCanvasNode.Clear();
                break;


            case "delete":
                var deleteShape = new DeleteShape()
                {
                    P1 = result.UpperLeft.ToCCPoint(),
                    P2 = result.LowerRight.ToCCPoint()
                };

                var victims = IsShapeOverOtherShapes(deleteShape);
                foreach (var victim in victims)
                {
                    _shapeNode.RemoveChild(victim);
                }
                _recognizerCanvasNode.Clear();
                break;
            }

            _canvasNode.Clear();
            _buffer.Clear();
        }