Example #1
0
 // ## Flip ##
 // This is a handler for the Flip event. It is triggered when the player
 // turns a cube face down or face up. The `newOrientationIsUp` argument
 // tells you which way the cube is now facing.
 //
 // Note that when a Flip event is triggered, a Tilt event is also
 // triggered.
 private void OnFlip(Cube cube, bool newOrientationIsUp)
 {
     if (newOrientationIsUp)
     {
         CubeWrapper wrappercube = (CubeWrapper)cube.userData;
         if (wrappercube.mNumber > 1 && wrappercube.mNumber < 6)
         {
             if (wrappercube.mOtherstate < 3)
             {
                 wrappercube.mOtherstate = +1;
             }
             wrappercube.mOtherstate = 0;
         }
         Log.Debug("Flip face up");
         mScale    = 1;
         mNeedDraw = true;
         //osc1.sendMsg("/vcs",3145733,50f);
     }
     else
     {
         Log.Debug("Flip face down");
         mScale    = 2;
         mNeedDraw = true;
         //osc1.sendMsg("/vcs",3145733,50f);
     }
 }
        /*
         * // ## Neighbor Add ##
         * // This method is a handler for the NeighborAdd event. It is triggered when
         * // two cubes are placed side by side.
         * //
         * // Cube1 and cube2 are the two cubes that are involved in this neighboring.
         * // The two cube arguments can be in any order; if your logic depends on
         * // cubes being in specific positions or roles, you need to add logic to
         * // this handler to sort the two cubes out.
         * //
         * // Side1 and side2 are the sides that the cubes neighbored on.
         * private void OnNeighborAdd (Cube cube1, Cube.Side side1, Cube cube2, Cube.Side side2)
         * {
         *      CubeWrapper wrapper1 = (CubeWrapper)cube1.userData;
         *      CubeWrapper wrapper2 = (CubeWrapper)cube2.userData;
         *      Log.Debug ("Neighbor add: {0}.{1} <-> {2}.{3}", wrapper1.mNumber, side1, wrapper2.mNumber, side2);
         *
         *      if (wrapper2.mNumber < wrapper1.mNumber) {
         *              CubeWrapper wrapper3 = cube1.userData;
         *              wrapper2 = wrapper1;
         *              wrapper1 = wrapper3;
         *      }
         *
         *
         *
         *      //s'arranger pour savoir quel cube est le premier, celui qui a le plus petit nombre, devient wrapper1
         *      if (cube1 == SOURCE) {
         *              switch (cube2){
         *              case FILTER:
         *                      break;
         *              }
         *
         *
         *      }
         *
         *
         *      if (wrapper1.mNumber == 1) {
         *              if (wrapper2.mNumber == 2) {
         *
         *              }
         *      }
         *
         *      if (wrapper1.mNumber== 2) {
         *              if (wrapper2.mNumber == 3) {
         *                      cube2.Image("all",0,0,0,ALL_LFO,Cube.SCREEN_WIDTH,Cube.SCREEN_HEIGHT,0,0);
         *              }
         *      }
         *
         *      cube1.Paint();
         *      cube2.Paint();
         *      /*
         * CubeWrapper wrapper = (CubeWrapper)cube1.userData;
         * if (wrapper != null) {
         * // Here we set our wrapper's rotation value so that the image gets
         * // drawn with its top side pointing towards the neighbor cube.
         * //
         * // Cube.Side is an enumeration (TOP, LEFT, BOTTOM, RIGHT, NONE). The
         * // values of the enumeration can be cast to integers by counting
         * // counterclockwise:
         * //
         * // * TOP = 0
         * // * LEFT = 1
         * // * BOTTOM = 2
         * // * RIGHT = 3
         * // * NONE = 4
         * wrapper.mRotation = (int)side1;
         * wrapper.mNeedDraw = true;
         * }
         *
         * wrapper = (CubeWrapper)cube2.userData;
         * if (wrapper != null) {
         * wrapper.mRotation = (int)side2;
         * wrapper.mNeedDraw = true;
         *
         * }
         *
         * // ## Neighbor Remove ##
         * // This method is a handler for the NeighborRemove event. It is triggered
         * // when two cubes that were neighbored are separated.
         * //
         * // The side arguments for this event are the sides that the cubes
         * // _were_ neighbored on before they were separated. If you check the
         * // current state of their neighbors on those sides, they should of course
         * // be NONE.
         * private void OnNeighborRemove (Cube cube1, Cube.Side side1, Cube cube2, Cube.Side side2)
         * {
         * CubeWrapper wrapper1 = (CubeWrapper)cube1.userData;
         *      CubeWrapper wrapper2 = (CubeWrapper)cube2.userData;
         *
         *      if (wrapper2.mNumber < wrapper1.mNumber) {
         *              CubeWrapper wrapper3 = cube1.userData;
         *              wrapper2 = wrapper1;
         *              wrapper1 = wrapper3;
         *      }
         *      Log.Debug ("Neighbor remove: {0}.{1} <-> {2}.{3}", wrapper1.mNumber, side1, wrapper2.mNumber, side2);
         *
         *      if (cube1 == SOURCE) {
         *              switch (cube2){
         *              case FILTER:
         *                      break;
         *              }
         *
         *
         *      }
         *
         *
         *      if (wrapper1.mNumber == 1) {
         *              if (wrapper2.mNumber == 2) {
         *                      cube2.Image("all",0,0,0,ALL_FILTERBASIC,Cube.SCREEN_WIDTH,Cube.SCREEN_HEIGHT,0,0);
         *                      cube1.Image("all",0,0,0,ALL_SOURCE,Cube.SCREEN_WIDTH,Cube.SCREEN_HEIGHT,0,0);
         *                      //message OSC, son de base
         *              }
         *      }
         *
         *      if (wrapper1.mNumber == 2) {
         *              if (wrapper2.mNumber == 3) {
         *                      cube2.Image("all",0,0,0,ALL_LFOBASIC,Cube.SCREEN_WIDTH,Cube.SCREEN_HEIGHT,0,0);
         *                      // message OSC, son filtré simplement
         *                      //savoir si on sait faire un "ctrl+z" sur KYMA, alors on reprend juste le son précédent
         *                      //si pas -> switch
         *              }
         *      }
         *
         *      cube1.Paint();
         *      cube2.Paint();
         *
         * /*  CubeWrapper wrapper = (CubeWrapper)cube1.userData;
         * if (wrapper != null) {
         * wrapper.mScale = 1;
         * wrapper.mRotation = 0;
         * wrapper.mNeedDraw = true;
         * }
         *
         * wrapper = (CubeWrapper)cube2.userData;
         * if (wrapper != null) {
         * wrapper.mScale = 1;
         * wrapper.mRotation = 0;
         * wrapper.mNeedDraw = true;
         * }
         * }
         */
        private void OnNeighborAdd(Cube cube1, Cube.Side side1, Cube cube2, Cube.Side side2)
        {
            CubeWrapper wrapper1 = (CubeWrapper)cube1.userData;
            CubeWrapper wrapper2 = (CubeWrapper)cube2.userData;

            if (wrapper2.mNumber < wrapper1.mNumber)
            {
                CubeWrapper wrapper3 = (CubeWrapper)cube2.userData;
                wrapper2 = wrapper1;
                wrapper1 = wrapper3;

                Cube cuby;
                cuby  = cube2;
                cube2 = cube1;
                cube1 = cuby;
            }

            Cube[] connected = CubeHelper.FindConnected(cube1);

            foreach (Cube cuby in connected)
            {
                Log.Debug("connected {0}", connected);
            }

            if (connected.Length > 1)
            {
                foreach (Cube cubelook in connected)
                {
                    CubeWrapper wrapper4 = (CubeWrapper)cubelook.userData;

                    if (wrapper4.mNumber == 1)
                    {
                        wrapper2.mIsconnected = true;
                        wrapper2.mHaschanged  = true;
                        mNeedCheck            = true;
                        Log.Debug("on a bien changé le connected");
                    }
                }
            }
            mNeedCheck = true;
        }
Example #3
0
        // ## Button ##
        // This is a handler for the Button event. It is triggered when a cube's
        // face button is either pressed or released. The `pressed` argument
        // is true when you press down and false when you release.
        private void OnButton(Cube cube, bool pressed)
        {
            if (pressed)
            {
                CubeWrapper wrappercube = (CubeWrapper)cube.userData;
                wrappercube.mHaschanged = true;

                //Log.Debug("click on the button to change the state {0}", wrappercube.mNumber);
                switch (wrappercube.mNumber)
                {
                case 1:
                    if (wrappercube.mState < 3)
                    {
                        wrappercube.mState = wrappercube.mState + 1;
                        //	Log.Debug("on a l'état {0}",wrappercube.mState);
                    }
                    else
                    {
                        wrappercube.mState = 0;
                    }
                    break;

                case 2:
                    if (wrappercube.mState < 1)
                    {
                        wrappercube.mState = wrappercube.mState + 1;
                        Log.Debug("etat du hp {0}", wrappercube.mState);
                    }
                    else
                    {
                        wrappercube.mState = 0;
                    }
                    break;

                case 3:
                    if (wrappercube.mState < 2)
                    {
                        wrappercube.mState = wrappercube.mState + 1;
                    }
                    else
                    {
                        wrappercube.mState = 0;
                    }

                    break;

                case 4:
                    if (wrappercube.mState < 2)
                    {
                        wrappercube.mState = wrappercube.mState + 1;
                    }
                    else
                    {
                        wrappercube.mState = 0;
                    }

                    break;

                case 5:
                    if (wrappercube.mState < 1)
                    {
                        wrappercube.mState = +1;
                    }
                    else
                    {
                        wrappercube.mState = 0;
                    }

                    break;
                }
                KYMA_SIFTEO.mNeedCheck = true;
            }
        }
        /*
         * public readonly int SOURCEON = 1;
         * public readonly int SOURCEOFF = 0;
         * public readonly int LSOFF = 0;
         * public readonly int LSON = 1;
         * public readonly int LFOOFF = 0;
         * public readonly int LFOON = 1;
         * public readonly int FILTEROFF = 0;
         * public readonly int FILTERLOWPASS = 1;
         * public readonly int FILTERHIGHPASS = 2;
         * public readonly int EFFET = 0;
         * public readonly int DELAY = 1;
         *
         *
         * public int SOURCE = 0;
         * public int LS = 0;
         * public int FILTER = 0;
         * public int LFO = 0;
         * public int SPECIAL = 0;
         */
        // Here we initialize our app.

        public override void Setup()
        {
            // Load up the list of images.
            // mImageNames = LoadImageIndex();
            int number     = 1;
            int state      = 0;
            int otherstate = 0;
            int j          = 0;

            bool isconnedted = false;
            bool haschanged  = false;

            WithdrawSound();

            // Loop through all the cubes and set them up.
            foreach (Cube cube in CubeSet)
            {
                Cubes[j] = cube;
                // Create a wrapper object for each cube. The wrapper object allows us
                // to bundle a cube with extra information and behavior.
                CubeWrapper wrapper = new CubeWrapper(this, cube, number, state, otherstate, isconnedted, haschanged);
                mWrappers.Add(wrapper);
                cube.FillRect(new Color(0, 0, 255), 0, 0, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT);

                switch (wrapper.mNumber)
                {
                case 1:
                    cube.Image("FULL", 0, 0, 0, FULL_SOURCE1, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT, 0, 0);
                    break;

                case 2:
                    cube.Image("FULL", 0, 0, 0, FULL_LSOFF, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT, 0, 0);
                    break;

                case 3:
                    cube.Image("FULL", 0, 0, 0, FULL_FILTER, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT, 0, 0);
                    break;

                case 4:
                    cube.Image("FULL", 0, 0, 0, FULL_LFO1, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT, 0, 0);
                    break;

                case 5:
                    cube.Image("FULL", 0, 0, 0, FULL_SPECIAL, Cube.SCREEN_WIDTH, Cube.SCREEN_HEIGHT, 0, 0);
                    break;
                }
                cube.Paint();
                number++;
                j++;
                //wrapper.DrawSlide();
            }

            // ## Event Handlers ##
            // Objects in the Sifteo API (particularly BaseApp, CubeSet, and Cube)
            // fire events to notify an app of various happenings, including actions
            // that the player performs on the cubes.
            //
            // To listen for an event, just add the handler method to the event. The
            // handler method must have the correct signature to be added. Refer to
            // the API documentation or look at the examples below to get a sense of
            // the correct signatures for various events.
            //
            // **NeighborAddEvent** and **NeighborRemoveEvent** are triggered when
            // the player puts two cubes together or separates two neighbored cubes.
            // These events are fired by CubeSet instead of Cube because they involve
            // interaction between two Cube objects. (There are Cube-level neighbor
            // events as well, which comes in handy in certain situations, but most
            // of the time you will find the CubeSet-level events to be more useful.)
            CubeSet.NeighborAddEvent    += OnNeighborAdd;
            CubeSet.NeighborRemoveEvent += OnNeighborRemove;
        }
        private void OnNeighborRemove(Cube cube1, Cube.Side side1, Cube cube2, Cube.Side side2)
        {
            bool sourceishere  = false;
            bool sourceishere2 = false;

            //the "remove part" is a little bit more tricky because we have to check which part stays with the source

            /*
             *      CubeWrapper wrapper1 = (CubeWrapper)cube1.userData;
             *      CubeWrapper wrapper2 = (CubeWrapper)cube2.userData;
             *
             *      if (wrapper2.mNumber < wrapper1.mNumber)
             *      {
             *              CubeWrapper wrapper3 = (CubeWrapper)cube2.userData;
             *              wrapper2 = wrapper1;
             *              wrapper1 = wrapper3;
             *
             *              Cube cuby = Cube;
             *              cuby = cube2;
             *              cube2 = cube1;
             *              cube1 = cuby;
             *      }
             */
            Cube[] connected  = CubeHelper.FindConnected(cube1);
            Cube[] connected2 = CubeHelper.FindConnected(cube2);

            foreach (Cube cubelook4 in connected)
            {
                CubeWrapper wrapper4 = (CubeWrapper)cubelook4.userData;

                if (wrapper4.mNumber == 1)
                {                 //we check if the source is in this part, and if it is the case, everycube in the group is connected
                    sourceishere = true;
                }
            }

            foreach (Cube cubelook2 in connected2)
            {
                CubeWrapper wrapper4 = (CubeWrapper)cubelook2.userData;

                if (wrapper4.mNumber == 1)
                {                 //we check if the source is in this part, and if it is the case, everycube in the group is connected
                    sourceishere2 = true;
                }
            }


            if (sourceishere)
            {
                foreach (Cube cubelook3 in connected)
                {
                    CubeWrapper wrapper5 = (CubeWrapper)cubelook3.userData;
                    wrapper5.mIsconnected = true;                    //if it is not the case, they are not connected
                    wrapper5.mHaschanged  = true;
                }
                foreach (Cube cubelook3 in connected2)
                {
                    CubeWrapper wrapper5 = (CubeWrapper)cubelook3.userData;
                    wrapper5.mIsconnected = false;                    //if it is not the case, they are not connected
                    wrapper5.mHaschanged  = true;
                }
            }

            if (sourceishere2)
            {
                foreach (Cube cubelook3 in connected2)
                {
                    CubeWrapper wrapper5 = (CubeWrapper)cubelook3.userData;
                    wrapper5.mIsconnected = true;                    //if it is not the case, they are not connected
                    wrapper5.mHaschanged  = true;
                }
                foreach (Cube cubelook3 in connected)
                {
                    CubeWrapper wrapper5 = (CubeWrapper)cubelook3.userData;
                    wrapper5.mIsconnected = false;                    //if it is not the case, they are not connected
                    wrapper5.mHaschanged  = true;
                }
            }

            /*foreach (Cube cubelook2 in connected2)
             * {
             *      CubeWrapper wrapper4 = (CubeWrapper)cubelook2.userData;
             *
             *      if (wrapper4.mNumber == 1)
             *      { //we check if the source is in this part, and if it is the case, everycube in the group is connected
             *              foreach (Cube cubelook3 in connected2)
             *              {
             *                      CubeWrapper wrapper5 = (CubeWrapper)cubelook3.userData;
             *                      wrapper5.mIsconnected = true;
             *                      sourceishere = true;
             *              }
             *      }
             * }*/
            mNeedCheck = true;
        }