// This is called after the Box2D world has been loaded, and while the b2dJson information
        // is still available to do extra loading. Here is where we obtain the named items in the scene.
        public override void AfterLoadProcessing(Nb2dJson json)
        {
            // call superclass method to load images etc
            base.AfterLoadProcessing(json);

            // preload the sound effects
            //SimpleAudioEngine::sharedEngine()->preloadEffect("jump.wav");
            //SimpleAudioEngine::sharedEngine()->preloadEffect("pickupgem.wav");
            //SimpleAudioEngine::sharedEngine()->preloadEffect("pickupstar.wav");

            // find player body and foot sensor fixture
            m_playerBody = json.GetBodyByName("player");
            m_footSensorFixture = json.GetFixtureByName("footsensor");

            // find all fixtures in the scene named 'pickup' and loop over them
            List<b2Fixture> pickupFixtures;
            pickupFixtures = json.GetFixturesByName("pickup").ToList();

            foreach (var f in pickupFixtures)
            {
                //For every pickup fixture, we create a FixtureUserData to set in
                //the user data.
                PlanetCuteFixtureUserData fud = new PlanetCuteFixtureUserData();
                m_allPickups.Add(fud);
                f.UserData = fud;

                // set some basic properties of the FixtureUserData
                fud.fixtureType = _fixtureType.FT_PICKUP;
                fud.body = f.Body;
                fud.originalPosition = f.Body.Position;

                // use the custom properties given to the fixture in the RUBE scene
                //fud.pickupType = (_pickupType)json.GetCustomInt(f, "pickuptype", PT_GEM);
                //json.Equals
                //fud.bounceSpeedH = json.GetCustomFloat(f, "horizontalbouncespeed");
                //fud.bounceSpeedV = json.GetCustomFloat(f, "verticalbouncespeed");
                //fud.bounceWidth  = json.GetCustomFloat(f, "bouncewidth");
                //fud.bounceHeight = json.GetCustomFloat(f, "bounceheight");

                //these "bounce deltas" are just a number given to sin when wobbling
                //the pickups. Each pickup has its own value to stop them from looking
                //like they are moving in unison.
                fud.bounceDeltaH = CCRandom.Float_0_1() * (float)Math.PI;
                fud.bounceDeltaV = CCRandom.Float_0_1() * (float)Math.PI;
            }

            // find the imageInfos for the text instruction images. Sprites 2 and 3 are
            // hidden initially
            m_instructionsSprite1 = null;
            m_instructionsSprite2 = null;
            m_instructionsSprite2 = null;

            foreach (var imgInfo in m_imageInfos)
            {
                if (imgInfo.Name == "instructions1")
                    m_instructionsSprite1 = imgInfo;
                if (imgInfo.Name == "instructions2")
                {
                    m_instructionsSprite2 = imgInfo;
                    m_instructionsSprite2.Sprite.Opacity = 0; // hide
                }
                if (imgInfo.Name == "instructions3")
                {
                    m_instructionsSprite3 = imgInfo;
                    m_instructionsSprite3.Sprite.Opacity = 0; // hide
                }
            }

            // Create a contact listener and let the Box2D world know about it.
            m_contactListener = new PlanetCuteContactListener();
            m_world.SetContactListener(m_contactListener);

            // Give the listener a reference to this class, to use in the callback
            m_contactListener.m_layer = this;

            // set the movement control touches to nil initially
            //m_leftTouch = null;
            //m_rightTouch = null;

            // initialize the values for ground detection
            m_numFootContacts = 0;
            m_jumpTimeout = 0;

            // camera will start at body position
            m_cameraCenter = m_playerBody.Position;
        }
Example #2
0
 public void SetCustomVector(Nb2dJsonImage item, String propertyName, b2Vec2 val)
 {
     m_imagesWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_vec2.Add(propertyName, val);
 }
Example #3
0
 public void SetImageName(Nb2dJsonImage image, String name)
 {
     m_imageToNameMap.Add(image, name);
 }
Example #4
0
 public void SetCustomFloat(Nb2dJsonImage item, String propertyName, float val)
 {
     m_imagesWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_float.Add(propertyName, (float)val);
 }
Example #5
0
 public void SetCustomString(Nb2dJsonImage item, String propertyName, String val)
 {
     m_imagesWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_string.Add(propertyName, val);
 }
Example #6
0
        Nb2dJsonImage j2b2dJsonImage(JObject imageValue)
        {
            Nb2dJsonImage img = new Nb2dJsonImage();

            int bodyIndex = imageValue["body"] == null ? -1 : (int)imageValue["body"];
            if (-1 != bodyIndex)
                img.Body = lookupBodyFromIndex(bodyIndex);

            String imageName = imageValue["name"] == null ? "" : imageValue["name"].ToString();
            if (imageName != "")
            {
                img.Name = imageName;
                SetImageName(img, imageName);
            }

            String fileName = imageValue["file"] == null ? "" : imageValue["file"].ToString();
            //TODO: Renombramos el fichero a una ruta relativa
            if (fileName != "")
                img.File = Path.GetFileName(fileName);

            img.Center = jsonToVec("center", imageValue);
            img.Angle = jsonToFloat("angle", imageValue);
            img.Scale = jsonToFloat("scale", imageValue);
            img.Opacity = jsonToFloat("opacity", imageValue);
            img.RenderOrder = jsonToFloat("renderOrder", imageValue);

            JArray colorTintArray = (JArray)imageValue["colorTint"];
            if (null != colorTintArray)
            {
                for (int i = 0; i < 4; i++)
                {
                    img.ColorTint[i] = (int)colorTintArray[i];
                }
            }

            img.Flip = imageValue["flip"] == null ? false : (bool)imageValue["flip"];

            img.Filter = imageValue["filter"] == null ? 1 : (int)imageValue["filter"];

            img.Corners = new b2Vec2[4];
            for (int i = 0; i < 4; i++)
                img.Corners[i] = jsonToVec("corners", imageValue, i);

            JArray vertexPointerArray = (JArray)imageValue["glVertexPointer"];
            JArray texCoordArray = (JArray)imageValue["glVertexPointer"];
            if (null != vertexPointerArray && null != texCoordArray && vertexPointerArray.Count == texCoordArray.Count)
            {
                int numFloats = vertexPointerArray.Count;
                img.NumPoints = numFloats / 2;
                img.Points = new float[numFloats];
                img.UvCoords = new float[numFloats];
                for (int i = 0; i < numFloats; i++)
                {
                    img.Points[i] = jsonToFloat("glVertexPointer", imageValue, i);
                    img.UvCoords[i] = jsonToFloat("glTexCoordPointer", imageValue, i);
                }
            }

            JArray drawElementsArray = (JArray)imageValue["glDrawElements"];
            if (null != drawElementsArray)
            {
                img.NumIndices = drawElementsArray.Count;
                img.Indices = new short[img.NumIndices];
                for (int i = 0; i < img.NumIndices; i++)
                    img.Indices[i] = (short)drawElementsArray[i];
            }

            return img;
        }
Example #7
0
 public String GetImageName(Nb2dJsonImage image)
 {
     if (m_imageToNameMap.ContainsKey(image))
         return m_imageToNameMap[image];
     return null;
 }
Example #8
0
        JObject B2n(Nb2dJsonImage image)
        {
            JObject imageValue = new JObject();

            if (null != image.Body)
                imageValue["body"] = lookupBodyIndex(image.Body);
            else
                imageValue["body"] = -1;

            if (null != image.Name)
                imageValue["name"] = image.Name;
            if (null != image.File)
                imageValue["file"] = image.File;
            VecToJson("center", image.Center, imageValue);
            FloatToJson("angle", image.Angle, imageValue);
            FloatToJson("scale", image.Scale, imageValue);
            if (image.Flip)
                imageValue["flip"] = true;
            FloatToJson("opacity", image.Opacity, imageValue);
            imageValue["filter"] = image.Filter;
            FloatToJson("renderOrder", image.RenderOrder, imageValue);

            bool defaultColorTint = true;
            for (int i = 0; i < 4; i++)
            {
                if (image.ColorTint[i] != 255)
                {
                    defaultColorTint = false;
                    break;
                }
            }

            if (!defaultColorTint)
            {
                JArray array = (JArray)imageValue["colorTint"];
                for (int i = 0; i < 4; i++)
                    array[i] = image.ColorTint[i];
            }

            // image->updateCorners();
            for (int i = 0; i < 4; i++)
                VecToJson("corners", image.Corners[i], imageValue, i);

            // image->updateUVs();
            for (int i = 0; i < 2 * image.NumPoints; i++)
            {
                VecToJson("glVertexPointer", image.Points[i], imageValue, i);
                VecToJson("glTexCoordPointer", image.UvCoords[i], imageValue, i);
            }
            for (int i = 0; i < image.NumIndices; i++)
                VecToJson("glDrawElements", image.Indices[i], imageValue, i);

            JArray customPropertyValue = WriteCustomPropertiesToJson(image);
            if (customPropertyValue.Count > 0)
                imageValue["customProperties"] = customPropertyValue;

            return imageValue;
        }
Example #9
0
        protected void readCustomPropertiesFromJson(Nb2dJsonImage item, JObject value)
        {
            if (null == item)
                return;

            if (value["customProperties"] != null)
                return;

            int i = 0;
            JArray propValues = (JArray)value["customProperties"];
            if (null != propValues)
            {
                int numPropValues = propValues.Count;
                for (i = 0; i < numPropValues; i++)
                {
                    JObject propValue = (JObject)propValues[i];
                    string propertyName = propValue["name"].ToString();
                    if (propValue["int"] != null)
                        SetCustomInt(item, propertyName, (int)propValue["int"]);
                    if (propValue["float"] != null)
                        SetCustomFloat(item, propertyName, (float)propValue["float"]);
                    if (propValue["string"] != null)
                        SetCustomString(item, propertyName, propValue["string"].ToString());
                    if (propValue["vec2"] != null)
                        SetCustomVector(item, propertyName, this.jsonToVec("vec2", propValue));
                    if (propValue["bool"] != null)
                        SetCustomBool(item, propertyName, (bool)propValue["bool"]);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Post-carga de los objetos cargados del xml
        /// </summary>
        /// <param name="json"></param>
        public override void AfterLoadProcessing(Nb2dJson json)
        {
            //Movemos todos los objetos al offset que deseemos
            var delta = GetOffset(); // move all bodies by this offset

            if (delta.x != 0 && delta.y != 0)
                foreach (var body in json.GetAllBodies())
                    body.SetTransform(body.Position + delta, body.Angle);

            //Obtenemos las imageInfos con todos los objetos
            m_imageInfos = json.GetAllImages().ToList();

            //Recorremos todas
            CCSprite tmpSprite;
            foreach (var img in m_imageInfos)
            {
                //Generamos el sprite en la posiciĆ³n
                tmpSprite = new CCSprite(img.File);
                tmpSprite.Position = new CCPoint(0, 0);
                AddChild(tmpSprite, (int)img.RenderOrder);

                //Guardamos el sprite
                img.Sprite = tmpSprite;

                // Asignamos el volteo y la escala del sprite
                img.Sprite.FlipX = img.Flip;
                img.Sprite.Scale = img.Scale / img.Sprite.ContentSize.Height;

                //Si es el bicho
                if (img.Name.Equals(PLAYER_LAYER_IMAGE_NAME))
                {
                    //img.fixture = json.GetFixturesByName("ball");
                    Player = img;
                }

            }

            OnSetImagePositionsFromPhysicsBodies();

            OnFinishedLoading();
        }
Example #11
0
        public void SetPlayerLayerName(string imageLayerName)
        {
            PLAYER_LAYER_IMAGE_NAME = imageLayerName;
            foreach (var img in m_imageInfos)
            {

                if (img.Name.Equals(PLAYER_LAYER_IMAGE_NAME))
                {
                    Player = img;
                }

            }
        }
Example #12
0
 // Remove one image from the layer
 public void RemoveImageFromWorld(Nb2dJsonImage imgInfo)
 {
     RemoveChild(imgInfo.Sprite, true);
     m_imageInfos.Remove(imgInfo);
 }