Exemplo n.º 1
0
        public override void OnEnter()
        {
            base.OnEnter();


            QUERY_START = new cpVect(320, 240);

            font          = GetDefaultFontTtf("TEST");
            font.Position = new CCPoint((float)windowSize.Width * .5f, 10);
            InformationLayer.AddChild(font);
            font.Scale = .5f;

            space.SetIterations(5);

            {             // add a fat segment
                var    mass = 1;
                var    length = 100;
                cpVect a = new cpVect(-length / 2, 0), b = new cpVect(length / 2, 0);

                var body = space.AddBody(new cpBody(mass, cp.MomentForSegment(mass, a, b, 0.0f)));
                body.SetPosition(new cpVect(0.0f, 100.0f));

                space.AddShape(new cpSegmentShape(body, a, b, 20));
            }

            {             // add a static segment
                space.AddShape(new cpSegmentShape(space.GetStaticBody(), new cpVect(0, 300), new cpVect(300, 0), 0));
            }

            {             // add a pentagon
                float mass      = 1;
                int   NUM_VERTS = 5;

                cpVect[] verts = new cpVect[NUM_VERTS];
                for (int i = 0; i < NUM_VERTS; i++)
                {
                    float angle = -2 * cp.M_PI * i / (NUM_VERTS);
                    verts[i] = cpVect.cpv(30 * cp.cpfcos(angle), 30 * cp.cpfsin(angle));
                }


                var body = space.AddBody(new cpBody(mass, cp.MomentForPoly(mass, NUM_VERTS, verts, cpVect.Zero, 0.0f)));
                body.SetPosition(new cpVect(50.0f, 30.0f));

                space.AddShape(new cpPolyShape(body, NUM_VERTS, verts, cpTransform.Identity, 10f));
            }

            {             // add a circle
                var mass = 1;
                var r    = 20;

                var body = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0, r, new cpVect(0, 0))));
                body.SetPosition(new cpVect(100.0f, 100.0f));

                space.AddShape(new cpCircleShape(body, r, cpVect.Zero));
            }

            Schedule();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a subscene player
        /// </summary>
        /// <param name="subScenes"></param>
        public void CreateSubScenePlayer(int subScenes)
        {
            var menu = GetPlayerSubLayer();

            menuLayerPlayer.AnchorPoint = new CCPoint(0, 0);
            menu.Position = new CCPoint(Window.WindowSizeInPixels.Width * .67f, Window.WindowSizeInPixels.Height * .05f);
            InformationLayer.AddChild(menu);
            SubScenePlayer.Count = subScenes - 1;
        }
Exemplo n.º 3
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            //Our information layer it's on parent layer because our information text are statics
            background          = new CCSprite("Background.png");
            background.Position = windowSize.Center;
            background.Scale    = windowSize.Height / background.Texture.ContentSizeInPixels.Height;
            BackgroundLayer.AddChild(background, -3);
            this.Position = windowSize.Center;

            //Creation menu debug options
            var lbl1 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Shapes"), (o) => { debug_shapes = !debug_shapes; RefreshDebug(); });

            lbl1.AnchorPoint = new CCPoint(0, .5f);
            var lbl2 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Joins"), (o) => { debug_joints = !debug_joints; RefreshDebug(); });

            lbl2.AnchorPoint = new CCPoint(0, .5f);
            var lbl3 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Contact"), (o) => { debug_contacts = !debug_contacts; RefreshDebug(); });

            lbl3.AnchorPoint = new CCPoint(0, .5f);
            var lbl4 = new CCMenuItemLabelTTF(GetDefaultFontTtf("BB"), (o) => { debug_bb = !debug_bb; RefreshDebug(); });

            lbl4.AnchorPoint = new CCPoint(0, .5f);
            CCMenu menu = new CCMenu(new CCMenuItem[] { lbl1, lbl2, lbl3, lbl4 });

            menu.AlignItemsVertically();
            menu.Position = new CCPoint(windowSize.Width * .02f, windowSize.Height * .35f);
            InformationLayer.AddChild(menu);

            background_white          = new CCSprite("Background-alone.png");
            background_white.Position = windowSize.Center;
            background_white.Scale    = windowSize.Height / background_white.Texture.ContentSizeInPixels.Height;
            background_white.Visible  = false;
            InformationLayer.AddChild(background_white, -4);

            logo = new LogoNode();
            logo.InitialPosition = new CCPoint(new CCPoint(windowSize.Width * .90f, windowSize.Height * .05f));
            logo.Position        = new CCPoint(logo.InitialPosition);

            InformationLayer.AddChild(logo, -2);

            logo.RunAction(new CCRepeatForever(
                               new CCEaseSineInOut(new CCMoveBy(1.5f, new CCPoint(0, 10))),
                               new CCEaseSineInOut(new CCMoveBy(1.5f, new CCPoint(0, -10))))
                           );

            //Debug draw initialization
            //m_debugDraw = new CCChipmunkDebugDraw(DEFAULT_FULL_FONT);

            //Space initialization
            space = new cpSpace();
            //space.SetDebugDraw(m_debugDraw);

            space.CollisionEnabled = CollisionEnabled;
            m_debugDraw            = new PhysicsDebugDraw(space);
            CollisionEnabled
            AddChild(m_debugDraw);

            RefreshDebug();

            //Title initialization
            example             = GetDefaultFontTtf("Physics examples");
            example.AnchorPoint = new CCPoint(.5f, 1f);
            //example.Scale = .3f;
            InformationLayer.AddChild(example);
            SetTitle(this.GetType().Name);

            //Player initialization
            menuLayerPlayer             = GetPlayerLayer();
            menuLayerPlayer.AnchorPoint = new CCPoint(0, 0);

            menuLayerPlayer.Position = new CCPoint(Window.WindowSizeInPixels.Width * .12f, Window.WindowSizeInPixels.Height * .05f);
            InformationLayer.AddChild(menuLayerPlayer);

            //Listeners initializations
            //eMouse = new CCEventListenerMouse();
            //eMouse.OnMouseMove += OnMouseMove;
            //eMouse.OnMouseDown += OnMouseDown;
            //eMouse.OnMouseUp += OnMouseUp;
            //eMouse.OnMouseScroll = e => CCMouse.Instance.OnMouseScroll(e, this);
            //AddEventListener(eMouse);

            eTouch = new CCEventListenerTouchAllAtOnce();
            eTouch.OnTouchesBegan     += OnTouchesBegan;
            eTouch.OnTouchesMoved     += OnTouchesMoved;
            eTouch.OnTouchesCancelled += OnTouchesCancelled;
            eTouch.OnTouchesEnded     += OnTouchesEnded;
            AddEventListener(eTouch);
        }