Example #1
0
        public Quarterpipe( CubeGame game,
                            World world,
                            float radius,
                            Vector2 position,
                            Type type,
                            BodyType bodyType = BodyType.Static,
                            float density = 1,
                            Category categories = Constants.Categories.DEFAULT )
            : base(game, world, position.ToUnits(), AngleFromType( type ), new QuarterpipeMaker( radius ))
        {
            mRadius = radius;

            FixtureFactory.AttachChainShape(
                MakeArc( 100, radius.ToUnits(), 0 ),
                Body,
                new Concave() );

            var fixtureList = FixtureFactory.AttachCompoundPolygon(
                Triangulate.ConvexPartition(
                    MakeArc( 10, radius.ToUnits(), 0 ),
                    TriangulationAlgorithm.Earclip ),
                density,
                Body );

            foreach ( var f in fixtureList )
                f.CollidesWith = Category.None;

            Body.BodyType = bodyType;
            Body.CollisionCategories = categories;

            Initialize();
        }
 public void Start( EditableCube.Face face, Vector2 mousePos, GameTime gameTime )
 {
     Solid solid = face.FindSolidAt( mousePos.ToUnits() );
     if ( solid != null )
     {
         switch ( solid.BodyType )
         {
         case BodyType.Static:
             solid.BodyType = BodyType.Dynamic;
             solid.Body.CollisionCategories = Category.Cat2;
             break;
         case BodyType.Dynamic:
             solid.BodyType = BodyType.Static;
             solid.Body.CollisionCategories = Category.Cat1;
             break;
         }
     }
 }
Example #3
0
        public EndDoor( CubeGame game,
                        World world,
                        Vector2 pos,
                        string nextLevel = null,
                        BodyType bodyType = BodyType.Static,
                        float density = 1,
                        Category categories = Category.Cat1 )
            : base(game, world, pos.ToUnits(), 0, new EndDoorMaker())
        {
            var door = FixtureFactory.AttachRectangle(
                    WIDTH.ToUnits(),
                    HEIGHT.ToUnits(),
                    density,
                    Vector2.Zero,
                    Body,
                    new Door( nextLevel ) );

            door.IsSensor = true;

            Body.BodyType = bodyType;
            Body.CollisionCategories = categories;
        }
Example #4
0
        public void Update( EditableCube.Face face, Vector2 mousePos, GameTime gameTime )
        {
            if ( face != mFace )
                return;

            var input = Game.Input;

            if ( input.CheckFocus( mSelectedSolid ) )
            {
                Vector2 delta = Vector2.Zero;

                if ( input.Keyboard.IsKeyDown( Keys.Up ) )
                    delta.Y += -1.ToUnits();

                if ( input.Keyboard.IsKeyDown( Keys.Right ) )
                    delta.X += 1.ToUnits();

                if ( input.Keyboard.IsKeyDown( Keys.Down ) )
                    delta.Y += 1.ToUnits();

                if ( input.Keyboard.IsKeyDown( Keys.Left ) )
                    delta.X += -1.ToUnits();

                if ( input.GetAction( Action.RotateClockwise ) )
                    mSelectedSolid.Rotation += MathHelper.PiOver2;

                if ( input.GetAction( Action.RotateAntiClockwise ) )
                    mSelectedSolid.Rotation -= MathHelper.PiOver2;

                mSelectedSolid.Position += delta.Rotate( face.Cube.UpDir.Angle );

                if ( input.Keyboard_WasAnyKeyPressed( Keys.Delete, Keys.Back ) )
                {
                    face.RemoveSolid( mSelectedSolid );
                    Cancel();
                }
            }

            if ( !Started )
                return;

            mSelectedSolid.Position = mOriginalPos + (mousePos.ToUnits() - mStartPos.ToUnits());

            if ( !input.IsShiftDown() )
            {
                mSelectedSolid.Position = EditScreen.SnapVector( mSelectedSolid.Position.ToPixels(), EditScreen.SNAP_SIZE / 2 ).ToUnits();
            }
            else
            {
                mSelectedSolid.Position = mSelectedSolid.Position
                                                        .ToPixels()
                                                        .Rounded()
                                                        .ToUnits();
            }
        }
Example #5
0
        public void Start( EditableCube.Face face, Vector2 mousePos, GameTime gameTime )
        {
            Solid selectedSolid = face.FindSolidAt( mousePos.ToUnits() );

            if ( selectedSolid != mSelectedSolid )
                Cancel();

            if ( selectedSolid != null )
            {
                mFace = face;
                Started = true;
                mStartPos = mousePos;
                mSelectedSolid = selectedSolid;
                mOriginalPos = mSelectedSolid.Position;
                Game.Input.Focus = mSelectedSolid;
            }
        }