Beispiel #1
0
    void DropShapeOnGrid(IntVec2 gridPos, ShapeDef shapeDef)
    {
        Debug.Log("DropShapeOnGrid " + gridPos.x + ", " + gridPos.y);

        string defString = ShapeAssetManager.Instance.GetShapeString(shapeDef.m_shapeType);

        char[]   delimiterChars = { ' ', ',', '.', ':', '\t' };
        string[] lines          = defString.Split(delimiterChars);

        int numLines = lines.Length;
        int minLine  = -((numLines - 1) / 2);

        for (int y = 0; y < numLines; y++)
        {
            string s        = lines [y];
            int    numChars = s.Length;
            int    minChar  = -((numChars - 1) / 2);
            for (int x = 0; x < numChars; x++)
            {
                if (s [x] == '1')
                {
                    IntVec2 cellGridPos = new IntVec2(x + minChar + gridPos.x, y + minLine + gridPos.y);
                    if ((cellGridPos.x >= 0) && (cellGridPos.y >= 0) && (cellGridPos.x < m_gridXDim) && (cellGridPos.y < m_gridYDim))
                    {
                        CellController cell = m_grid [cellGridPos.x, cellGridPos.y].GetComponent <CellController> ();
                        //cell.SetColor (ShapeAssetManager.Instance.GetColorFromCellColorType(shapeDef.m_colour));
                        cell.SetColor(Color.black);
                        cell.SetFilledStatus(true);
                    }
                }
            }
        }
    }
Beispiel #2
0
    // Use this for initialization
    protected override void Init()
    {
        var ground = API.CreateBody(world, new Vector2(0, 0), 0, BodyType.STATIC_BODY);

        API.AddEdgeShape(ground, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f), new ShapeDef(0));

        ShapeDef sp = new ShapeDef(20.0f);

        sp.friction = 0.2f;

        Vector2          anchor;
        RevoluteJointDef jd = new RevoluteJointDef();

        IntPtr prevBody = ground;
        float  y        = 25;

        for (int i = 0; i < e_count; ++i)
        {
            var b = API.CreateBody(world, new Vector2(0.5f + i, y), 0, BodyType.DYNAMIC_BODY);
            API.AddBoxShape(b, 0.6f, 0.125f, Vector2.zero, 0, sp);

            anchor = new Vector2(i, y);
            jd.Initialize(prevBody, b, anchor);
            API.CreateRevoluteJoint(world, jd);

            prevBody = b;
        }
    }
Beispiel #3
0
        private IShape ParseDefineShape4(SWFDataTypeReader shapeReader)
        {
            Rect bounds = shapeReader.ReadRect();

            shapeReader.Align8();
            Rect edgeBounds = shapeReader.ReadRect();

            shapeReader.Align8();

            shapeReader.ReadUBits(5); /* Reserved: 0 */

            bool usesFillWinding       = shapeReader.ReadBit();
            bool usesNonScalingStrokes = shapeReader.ReadBit();
            bool usesScalingStrokes    = shapeReader.ReadBit();

            ShapeDef sws = this.ReadShapeDef(shapeReader, Tag.DefineShape4, true, null, null);

            return(new Shape()
            {
                ShapeDef = sws,
                Bounds = bounds,
                UsesScalingStrokes = usesScalingStrokes,
                UsesNonScalingStrokes = usesNonScalingStrokes,
                UsesFillWinding = usesFillWinding
            });
        }
Beispiel #4
0
    // Use this for initialization
    protected override IntPtr Create(ShapeDef def)
    {
        Vector3 p00 = p0 + transform.position;
        Vector3 p11 = p1 + transform.position;

        return(API.AddEdgeShape(body.body, new Vector2(p00.x, p00.y), new Vector2(p11.x, p11.y), def));
    }
Beispiel #5
0
        private ShapeDef ReadShapeDef(SWFDataTypeReader shapeReader, Tag format, bool withStyle, IFillStyle[] fillStyles, ILineStyle[] lineStyles)
        {
            ShapeDef shapeDef = new ShapeDef();

            /* Shapes either don't have fill styles (Font glyphs), they come with a bunch of fill styles
             * (Regular shapes) or are preceeded by fill styles which are passed into this method
             * (Morph shapes). Could probably be tidier... */

            if (fillStyles != null)
            {
                shapeDef.FillStyles.AddRange(fillStyles);
            }

            if (lineStyles != null)
            {
                shapeDef.LineStyles.AddRange(lineStyles);
            }

            if (withStyle)
            {
                shapeDef.FillStyles.AddRange(this.ReadFillStyleArray(shapeReader, format));
                shapeReader.Align8();
                shapeDef.LineStyles.AddRange(this.ReadLineStyleArray(shapeReader, format));
                shapeReader.Align8();
            }

            /* Read the shape stuff... */

            int fillBits = (int)shapeReader.ReadUBits(4);
            int lineBits = (int)shapeReader.ReadUBits(4);

            this.ReadShapeRecordsInto(shapeDef, shapeReader, ref fillBits, ref lineBits, format);

            return(shapeDef);
        }
    // Use this for initialization
    protected override void Init()
    {
        var ground = API.CreateBody(world, new Vector2(0, 0), 0, BodyType.STATIC_BODY);

        API.AddEdgeShape(ground, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f), new ShapeDef(0));
        API.AddEdgeShape(ground, new Vector2(20.0f, 0.0f), new Vector2(20.0f, 20.0f), new ShapeDef(0));


        float[] xs = new float[5] {
            0.0f, -10.0f, -5.0f, 5.0f, 10.0f
        };

        ShapeDef sp = new ShapeDef(1.0f);

        sp.friction = 0.3f;

        for (int j = 0; j < e_columnCount; ++j)
        {
            for (int i = 0; i < e_rowCount; ++i)
            {
                var b = API.CreateBody(world, new Vector2(xs[j], 0.752f + 1.54f * i), 0, BodyType.DYNAMIC_BODY);
                API.AddBoxShape(b, 0.5f, 0.5f, Vector2.zero, 0, sp);
            }
        }
    }
Beispiel #7
0
        public static GameObject CreateGrenade(IModelForComponents model, PointF location, Vec2 startVelocity, IBullet grenadeBullet)
        {
            var      gameObject  = new GameObject(model, TypesGameObject.Grenade, TypesBehaveObjects.Active);
            ShapeDef circleShape = CreateBaseCircleDef(setupsWeapon, SizeGreanade);

            circleShape.Filter.CategoryBits = (ushort)CollideCategory.Grenade;
            circleShape.Filter.MaskBits     = (ushort)CollideCategory.Box | (ushort)CollideCategory.Stone;

            ShapeDef sensorDef = CreateBaseCircleDef(setupsWeapon, new SizeF(RadiusExplosionGrenade, RadiusExplosionGrenade));

            sensorDef.IsSensor            = true;
            sensorDef.Filter.CategoryBits = (ushort)CollideCategory.Grenade;
            sensorDef.Filter.MaskBits     = (ushort)CollideCategory.Player;

            var body = new SolidBody(gameObject, new RectangleF(location, SizeGreanade),
                                     new ShapeDef[] { circleShape, sensorDef }, setupsWeapon.linearDamping, startVelocity);

            gameObject.Components.Add(body);

            var explosion = new Explosion(gameObject, grenadeBullet);

            gameObject.Components.Add(explosion);

            model.AddOrUpdateGameObject(gameObject);

            return(gameObject);
        }
Beispiel #8
0
        public int RoundedRect(float x, float y, float width, float height, float r0, float r1, float r2, float r3)
        {
            ShapeDef shapeDef = new ShapeDef(ShapeType.RoundedRect);

            shapeDef.p0 = new Vector2(x, y);
            shapeDef.p1 = new Vector2(width, height);

            float min = math.min(width, height);

            if (min <= 0)
            {
                min = 0.0001f;
            }

            float halfMin = min * 0.5f;

            r0 = math.clamp(r0, 0, halfMin) / min;
            r1 = math.clamp(r1, 0, halfMin) / min;
            r2 = math.clamp(r2, 0, halfMin) / min;
            r3 = math.clamp(r3, 0, halfMin) / min;

            shapeDef.p2     = new Vector2(r0, r1);
            shapeDef.p3     = new Vector2(r2, r3);
            shapeDef.bounds = new Rect(x, y, width, height);
            shapes.Add(shapeDef);
            return(shapes.Count - 1);
        }
Beispiel #9
0
        public void Rhombus(float x, float y, float width, float height)
        {
            ShapeDef shapeDef = new ShapeDef(ShapeType.Rhombus);

            shapeDef.p0     = new Vector2(x, y);
            shapeDef.p1     = new Vector2(width, height);
            shapeDef.bounds = new Rect(x, y, width, height);
            shapes.Add(shapeDef);
        }
Beispiel #10
0
        public int Ellipse(float x, float y, float rw, float rh, int segmentCount = 50)
        {
            ShapeDef shapeDef = new ShapeDef(ShapeType.Ellipse);

            shapeDef.p0     = new Vector2(x, y);
            shapeDef.p1     = new Vector2(rw, rh);
            shapeDef.p2     = new Vector2(segmentCount, 0);
            shapeDef.bounds = new Rect(x, y, rw * 2, rh * 2);
            shapes.Add(shapeDef);
            return(shapes.Count - 1);
        }
Beispiel #11
0
        public int Rect(float x, float y, float width, float height)
        {
            requiresGeometryUpdate = true;

            ShapeDef shapeDef = new ShapeDef(ShapeType.Rect);

            shapeDef.bounds = new Rect(x, y, width, height);
            shapeList.Add(shapeDef);
            currentShapeRange.length++;
            return(shapeList.size - 1);
        }
Beispiel #12
0
    public ShapeDef PopFromQueue(int usedPieceIndex)
    {
        ShapeDef nextAnimal = m_shapeQueue[usedPieceIndex];

        for (int i = usedPieceIndex; i < QUEUE_LENGTH - 1; i++)
        {
            m_shapeQueue[i] = m_shapeQueue[i + 1];
        }
        m_shapeQueue[QUEUE_LENGTH - 1] = PullAnimalFromDeck();

        return(nextAnimal);
    }
Beispiel #13
0
        public int Circle(float x, float y, float r, int segmentCount = 50)
        {
            float    diameter = r * 2;
            ShapeDef shapeDef = new ShapeDef(ShapeType.Circle);

            shapeDef.p0     = new Vector2(x, y);
            shapeDef.p1     = new Vector2(diameter, diameter);
            shapeDef.p2     = new Vector2(segmentCount, 0);
            shapeDef.bounds = new Rect(x, y, diameter, diameter);
            shapes.Add(shapeDef);
            return(shapes.Count - 1);
        }
Beispiel #14
0
    ShapeDef PullAnimalFromDeck()
    {
        if (m_shapeDeck.Count == 0)
        {
            InitShapeDeck();
        }

        ShapeDef ad = m_shapeDeck[0];

        m_shapeDeck.RemoveAt(0);
        return(ad);
    }
Beispiel #15
0
    ShapeDef RandomShape()
    {
        ShapeDef.ColorTypes[] colorTypesArray = Enum.GetValues(typeof(ShapeDef.ColorTypes)) as ShapeDef.ColorTypes[];

        int numberOfShapeTypes = ShapeAssetManager.Instance.NumberOfShapeTypes();
        int type = UnityEngine.Random.Range(0, numberOfShapeTypes);

        ShapeDef.ColorTypes colour = colorTypesArray[UnityEngine.Random.Range(0, colorTypesArray.Length)];

        ShapeDef ad = new ShapeDef(type, colour);

        return(ad);
    }
Beispiel #16
0
        private IShape ParseDefineShapeN(SWFDataTypeReader shapeReader, Tag format)
        {
            Rect bounds = shapeReader.ReadRect();

            shapeReader.Align8();
            ShapeDef sws = this.ReadShapeDef(shapeReader, format, true, null, null);

            return(new Shape()
            {
                ShapeDef = sws,
                Bounds = bounds
            });
        }
Beispiel #17
0
        public void RegularPolygon(float x, float y, float width, float height, int sides)
        {
            if (sides < 3)
            {
                sides = 3;
            }
            ShapeDef shapeDef = new ShapeDef(ShapeType.Polygon);

            shapeDef.p0     = new Vector2(x, y);
            shapeDef.p1     = new Vector2(width, height);
            shapeDef.p2     = new Vector2(sides, 0);
            shapeDef.bounds = new Rect(x, y, width, height);
            shapes.Add(shapeDef);
        }
Beispiel #18
0
        private IShape ParseDefineMorphShape(SWFDataTypeReader shapeReader, Tag format)
        {
            Rect startBounds = shapeReader.ReadRect();

            shapeReader.Align8();
            Rect endBounds = shapeReader.ReadRect();

            shapeReader.Align8();

            Rect startEdgeBounds       = null;
            Rect endEdgeBounds         = null;
            bool usesNonScalingStrokes = false;
            bool usesScalingStrokes    = false;

            if (format == Tag.DefineMorphShape2)
            {
                startEdgeBounds = shapeReader.ReadRect();
                shapeReader.Align8();
                endEdgeBounds = shapeReader.ReadRect();
                shapeReader.Align8();

                /*(void)*/ shapeReader.ReadUBits(6); /* Reserved. Assume 0 */

                usesNonScalingStrokes = shapeReader.ReadBit();
                usesScalingStrokes    = shapeReader.ReadBit();
            }

            /*(void)*/ shapeReader.ReadUI32(); /* end edges offset. We don't need this */

            MorphFillStyle[] mfsa = this.ReadMorphFillStyleArray(shapeReader);

            MorphLineStyle[] mlsa = this.ReadMorphLineStyleArray(shapeReader, format);

            ShapeDef startShape = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa);
            ShapeDef endShape   = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa);

            return(new MorphShape()
            {
                Bounds = startBounds,
                EndBounds = endBounds,
                StartEdgeBounds = startEdgeBounds,
                EndEdgeBounds = endEdgeBounds,
                UsesNonScalingStrokes = usesNonScalingStrokes,
                UsesScalingStrokes = usesScalingStrokes,
                StartShape = startShape,
                EndShape = endShape
            });
        }
Beispiel #19
0
        public RigidBody CreateBox(float restetution, float friction, float width, float height, float density, bool isSensor = false, short group_index = 1)
        {
            PolygonDef pDef = new PolygonDef();

            pDef.Restitution = restetution;
            pDef.Friction    = friction;
            pDef.Density     = density;

            pDef.SetAsBox(width / PhysicsController.metric / 2, height / PhysicsController.metric / 2);

            pDef.Filter.GroupIndex = group_index;
            pDef.IsSensor          = isSensor;

            _shapeDef = pDef;

            return(this);
        }
Beispiel #20
0
        public static GameObject CreateStone(IModelForComponents model, PointF location)
        {
            var      gameObject = new GameObject(model, TypesGameObject.Stone, TypesBehaveObjects.Passive);
            ShapeDef CircleDef  = CreateBaseCircleDef(setupsStoneAndTree, SizeStone);

            CircleDef.Filter.CategoryBits = (ushort)CollideCategory.Stone;
            CircleDef.Filter.MaskBits     = (ushort)CollideCategory.Player |
                                            (ushort)CollideCategory.Grenade | (ushort)CollideCategory.Loot;

            var body = new SolidBody(gameObject, new RectangleF(location, SizeStone), new ShapeDef[] { CircleDef });

            gameObject.Components.Add(body);

            model.AddOrUpdateGameObject(gameObject);

            return(gameObject);
        }
Beispiel #21
0
    // Use this for initialization
    protected override IntPtr Create(ShapeDef def)
    {
        Vector2[] vs = new Vector2[vertexTransform.Length];
        for (int i = 0; i < vs.Length; ++i)
        {
            vs[i] = new Vector2(vertexTransform[i].localPosition.x, vertexTransform[i].localPosition.y);
        }

        if (destroyTransform)
        {
            for (int i = 0; i < vertexTransform.Length; ++i)
            {
                Destroy(vertexTransform[i].gameObject);
            }
        }

        return(API.AddPolygonShape(body.body, vs, vs.Length, def));
    }
Beispiel #22
0
        public void EndPath()
        {
            if (!buildingPath)
            {
                return;
            }
            buildingPath = false;
            inHole       = false;
            ShapeDef shapeDef = new ShapeDef(ShapeType.Path);

            shapeDef.pathDef = currentPath;
            shapeDef.bounds  = ComputePathBounds();
            ClampHoles(shapeDef.pathDef.holeRange, shapeDef.bounds);
            shapes.Add(shapeDef);
            currentPath = default;
            lastPoint.x = 0;
            lastPoint.y = 0;
        }
Beispiel #23
0
    // Use this for initialization
    protected override void Init()
    {
        var ground = API.CreateBody(world, new Vector2(0, 0), 0, BodyType.STATIC_BODY);

        API.AddEdgeShape(ground, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f), new ShapeDef(0));

        ShapeDef sp = new ShapeDef(20.0f);

        sp.friction = 0.2f;

        RevoluteJointDef def      = new RevoluteJointDef();
        IntPtr           prevBody = ground;

        for (int i = 0; i < e_count; ++i)
        {
            var b = API.CreateBody(world, new Vector2(-14.5f + i, 5.0f), 0, BodyType.DYNAMIC_BODY);
            API.AddBoxShape(b, 0.5f, 0.125f, Vector2.zero, 0, sp);

            def.Initialize(prevBody, b, new Vector2(-15.0f + i, 5.0f));
            API.CreateRevoluteJoint(world, def);
            prevBody = b;
        }

        def.Initialize(prevBody, ground, new Vector2(-15.0f + e_count, 5.0f));
        API.CreateRevoluteJoint(world, def);

        for (int i = 0; i < 2; ++i)
        {
            var       b        = API.CreateBody(world, new Vector2(-8.0f + 8 * i, 12), 0, BodyType.DYNAMIC_BODY);
            Vector2[] vertices = new Vector2[3];
            vertices[0].Set(-0.5f, 0.0f);
            vertices[1].Set(0.5f, 0.0f);
            vertices[2].Set(0.0f, 1.5f);
            API.AddPolygonShape(b, vertices, vertices.Length, new ShapeDef(1.0f));
        }

        for (int i = 0; i < 3; ++i)
        {
            var b = API.CreateBody(world, new Vector2(-6.0f + 6 * i, 10), 0, BodyType.DYNAMIC_BODY);
            API.AddCircleShape(b, 0.5f, new ShapeDef(1.0f));
        }
    }
Beispiel #24
0
        private static SolidBody CreateBodyWeapon(Weapon weapon, PointF location, PhysicsSetups physicsSetupsWeapon, SizeF sizeWeapon)
        {
            ShapeDef circleShape = CreateBaseCircleDef(physicsSetupsWeapon, sizeWeapon);

            circleShape.Filter.CategoryBits = (ushort)CollideCategory.Loot;
            circleShape.Filter.MaskBits     = (ushort)CollideCategory.Box | (ushort)CollideCategory.Stone;

            ShapeDef sensorDef = CreateBaseCircleDef(physicsSetupsWeapon, sizeWeapon);

            sensorDef.IsSensor            = true;
            sensorDef.Filter.CategoryBits = (ushort)CollideCategory.Loot;
            sensorDef.Filter.MaskBits     = (ushort)CollideCategory.Player;

            var body = new SolidBody(weapon, new RectangleF(location, sizeWeapon), new ShapeDef[] { circleShape, sensorDef },
                                     physicsSetupsWeapon.linearDamping, Vec2.Zero);

            weapon.Components.Add(body);

            return(body);
        }
Beispiel #25
0
        /// <summary>
        /// Creates a shape and attach it to this body.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="shapeDef">The shape definition.</param>
        /// <returns></returns>
        public Shape CreateShape(ShapeDef shapeDef)
        {
            lock (_world._lock) {
                Shape s = Shape.Create(shapeDef);

                s._next    = _shapeList;
                _shapeList = s;
                ++_shapeCount;

                s._body = this;

                // Add the shape to the world's broad-phase.
                s.CreateProxy(_world._broadPhase, _xf);

                // Compute the sweep radius for CCD.
                s.UpdateSweepRadius(_sweep.LocalCenter);

                return(s);
            }
        }
Beispiel #26
0
        public Shape CreateShape(ShapeDef shapeDef)
        {
            Box2DXDebug.Assert(!this._world._lock);
            Shape result;

            if (this._world._lock)
            {
                result = null;
            }
            else
            {
                Shape shape = Shape.Create(shapeDef);
                shape._next     = this._shapeList;
                this._shapeList = shape;
                this._shapeCount++;
                shape._body = this;
                shape.CreateProxy(this._world._broadPhase, this._xf);
                shape.UpdateSweepRadius(this._sweep.LocalCenter);
                result = shape;
            }
            return(result);
        }
Beispiel #27
0
        public void EndPath()
        {
            requiresGeometryUpdate = true;

            if (!buildingPath)
            {
                return;
            }
            currentShapeRange.length++;
            buildingPath = false;
            inHole       = false;
            ShapeDef shapeDef = new ShapeDef(ShapeType.Path);

            shapeDef.pointRange = currentPath.pointRange;
            shapeDef.holeRange  = currentPath.holeRange;
            shapeDef.bounds     = ComputePathBounds();
            ClampHoles(shapeDef.holeRange, shapeDef.bounds);
            shapeList.Add(shapeDef);
            currentPath = default;
            lastPoint.x = 0;
            lastPoint.y = 0;
        }
Beispiel #28
0
//	void SetColor(int colorNum)
//	{
//		m_colorSprite.color = ShapeAssetManager.Instance.GetColorFromCellColorType(colorNum);
//	}

//	void SetAnimalTexture(Texture2D tex)
//	{
//		Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f,0.5f));
//		m_animalSprite.sprite = sprite;
//	}

    public void SetDef(ShapeDef def)
    {
        string defString = ShapeAssetManager.Instance.GetShapeString(def.m_shapeType);

        ClearShape();

        char[]   delimiterChars = { ' ', ',', '.', ':', '\t' };
        string[] lines          = defString.Split(delimiterChars);

        Vector2 gridPitch = GameController.Instance.GridPitch();

        int numLines = lines.Length;
        int minLine  = -((numLines - 1) / 2);

        //float blockSize = 0.8f;
        for (int y = 0; y < numLines; y++)
        {
            string s        = lines [y];
            int    numChars = s.Length;
            int    minChar  = -((numChars - 1) / 2);
            for (int x = 0; x < numChars; x++)
            {
                float   xCoord = -(x + minChar) * gridPitch.x;
                float   yCoord = -(y + minLine) * gridPitch.y;
                Vector3 pos    = new Vector3(xCoord, yCoord, 0f);
                //pos = new Vector3(0f, 0f, 0f);
                if (s [x] == '1')
                {
                    GameObject cell = Instantiate(m_shapeBlock, pos, Quaternion.identity);
                    cell.transform.SetParent(m_spritesRoot);
                    cell.transform.localPosition = pos;
                    cell.GetComponent <SpriteRenderer> ().color = ShapeAssetManager.Instance.GetColorFromCellColorType(def.m_colour);
                }
            }
        }

        //SetColor((int)def.m_colour);
    }
Beispiel #29
0
        public static Gamer CreateGamer(IModelForComponents model, PointF location)
        {
            var      gameObject = new Gamer(model, TypesGameObject.Player, TypesBehaveObjects.Active);
            ShapeDef CircleDef  = CreateBaseCircleDef(setupsGamer, SizeGamer);

            CircleDef.Filter.CategoryBits = (ushort)CollideCategory.Player;
            CircleDef.Filter.MaskBits     = (ushort)CollideCategory.Box | (ushort)CollideCategory.Stone
                                            | (ushort)CollideCategory.Grenade;

            var body = new SolidBody(gameObject, new RectangleF(location, SizeGamer), new ShapeDef[] { CircleDef });

            gameObject.Components.Add(body);

            var movement = new Movement(gameObject, SpeedGamer);

            gameObject.Components.Add(movement);

            var collector = new Collector(gameObject);

            gameObject.Components.Add(collector);

            var currentWeapon = new CurrentWeapon(gameObject);

            gameObject.Components.Add(currentWeapon);

            var healthy = new Healthy(gameObject);

            gameObject.Components.Add(healthy);

            var statistics = new Statistics(gameObject);

            gameObject.Components.Add(statistics);

            model.AddOrUpdateGameObject(gameObject);
            model.Players.Add(gameObject);

            return(gameObject);
        }
Beispiel #30
0
    bool TryToPlacePiece(IntVec2 gridPos, int queuePosition)
    {
        ShapeDef nextShape = m_shapeQueue.QueuePosition(queuePosition);

        if (OKToDropShapeHere(gridPos, nextShape))
        {
            DropShapeOnGrid(gridPos, nextShape);

            m_shapeQueue.PopFromQueue(queuePosition);
            Transform piecePos = m_grid[gridPos.x, gridPos.y].transform;
            //MovePieceIntoPlace(piecePos, queuePosition);
            StartCoroutine(ScrollAnimalQueueCoRoutine(queuePosition));

            return(true);
        }

//		CellController cellController = m_grid[gridPos.x,gridPos.y].GetComponent<CellController>();
//		AnimalDef nextAnimal = m_animalQueue.QueuePosition(queuePosition);
//		cellController.AddAnimal(m_animalPrefab, nextAnimal);

//		SetController.PlaceAnimalResult placeResult = ChooseSet(setNum, queuePosition);
//		if (placeResult != SetController.PlaceAnimalResult.NOT_PLACED)
//		{
//			if (placeResult == SetController.PlaceAnimalResult.MATCHING_SET_COMPLETED)
//			{
//				m_animalQueue.AddNewSpeciesToDeck(nextAnimal);
//			}
//
//			m_animalQueue.PopFromQueue(queuePosition);
//			Transform piecePos = m_sets[setNum].GetComponent<SetController>().GetPlacedPiecePosition();
//			MovePieceIntoPlace(piecePos, queuePosition);
//			StartCoroutine(ScrollAnimalQueueCoRoutine(queuePosition));
//
//			return true;
//		}

        return(false);
    }
Beispiel #31
0
        private void ReadShapeRecordsInto(ShapeDef sws, SWFDataTypeReader shapeReader, ref int fillBits, ref int lineBits, Tag format)
        {
            List<IShapeRecord> records = new List<IShapeRecord>();

            int currentX = 0;
            int currentY = 0;

            while (true)
            {
                bool isEdgeRecord = shapeReader.ReadBit();
                if (isEdgeRecord)
                {
                    if (shapeReader.ReadBit())
                    {
                        /* StraightEdgeRecord */
                        int bpv = 2 + (int)shapeReader.ReadUBits(4);

                        bool isGeneralLine = shapeReader.ReadBit();
                        bool isVertical = false;
                        if (!isGeneralLine)
                        {
                            isVertical = shapeReader.ReadBit();
                        }

                        int dx = 0;
                        int dy = 0;

                        if (isGeneralLine || !isVertical)
                        {
                            dx = shapeReader.ReadSBits(bpv);
                        }

                        if (isGeneralLine || isVertical)
                        {
                            dy = shapeReader.ReadSBits(bpv);
                        }

                        currentX += dx;
                        currentY += dx;

                        records.Add(new StraightEdge() { DX = dx, DY = dy });
                    }
                    else
                    {
                        /* CurvedEdgeRecord */
                        int bpv = 2 + (int)shapeReader.ReadUBits(4);

                        int ctrlDX = shapeReader.ReadSBits(bpv);
                        int ctrlDY = shapeReader.ReadSBits(bpv);
                        int anchorDX = shapeReader.ReadSBits(bpv);
                        int anchorDY = shapeReader.ReadSBits(bpv);

                        currentX += ctrlDX + anchorDX;
                        currentY += ctrlDY + anchorDY;

                        records.Add(new CurvedEdge() { AnchorDX = anchorDX, AnchorDY = anchorDY, CtrlDX = ctrlDX, CtrlDY = ctrlDY });
                    }
                }
                else
                {
                    uint flags = shapeReader.ReadUBits(5);

                    if (flags == 0)
                    {
                        /* EndShapeRecord */
                        break;
                    }

                    /* StyleChangeRecord */

                    bool stateMoveTo = (flags & 1) == 1;
                    flags >>= 1;
                    bool stateFillStyle0 = (flags & 1) == 1;
                    flags >>= 1;
                    bool stateFillStyle1 = (flags & 1) == 1;
                    flags >>= 1;
                    bool stateLineStyle = (flags & 1) == 1;
                    flags >>= 1;
                    bool stateNewStyles = (flags & 1) == 1;
                    flags >>= 1;

                    StyleChange sc = new StyleChange();

                    if (stateMoveTo)
                    {
                        int moveBits = (int)shapeReader.ReadUBits(5);

                        sc.DX = shapeReader.ReadSBits(moveBits);
                        sc.DY = shapeReader.ReadSBits(moveBits);

                        currentX = sc.DX.Value;
                        currentY = sc.DY.Value;
                    }

                    if (stateFillStyle0)
                    {
                        sc.FillStyle0 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits));
                    }

                    if (stateFillStyle1)
                    {
                        sc.FillStyle1 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits));
                    }

                    if (stateLineStyle)
                    {
                        sc.LineStyle = (int)shapeReader.ReadUBits(lineBits);
                    }

                    if (stateNewStyles)
                    {
                        sc.NewFillStyles = this.ReadFillStyleArray(shapeReader, format);
                        sc.NewLineStyles = this.ReadLineStyleArray(shapeReader, format);

                        fillBits = (int)shapeReader.ReadUBits(4);
                        lineBits = (int)shapeReader.ReadUBits(4);

                        /* ISSUE 21: We're storing new styles defined in shape records in two places and
                         * in such a way that we can't figure out where we got them from. This makes
                         * it impossible to reconstruct the SWF data. Kinda need to work out how to
                         * find styles. */

                        sws.FillStyles.AddRange(sc.NewFillStyles);
                        sws.LineStyles.AddRange(sc.NewLineStyles);
                    }

                    records.Add(sc);
                }
            }

            shapeReader.Align8();

            sws.Records = records.ToArray();
        }
Beispiel #32
0
        private ShapeDef ReadShapeDef(SWFDataTypeReader shapeReader, Tag format, bool withStyle, IFillStyle[] fillStyles, ILineStyle[] lineStyles)
        {
            ShapeDef shapeDef = new ShapeDef();

            /* Shapes either don't have fill styles (Font glyphs), they come with a bunch of fill styles
             * (Regular shapes) or are preceeded by fill styles which are passed into this method
             * (Morph shapes). Could probably be tidier... */

            if (fillStyles != null)
            {
                shapeDef.FillStyles.AddRange(fillStyles);
            }

            if (lineStyles != null)
            {
                shapeDef.LineStyles.AddRange(lineStyles);
            }

            if (withStyle)
            {
                shapeDef.FillStyles.AddRange(this.ReadFillStyleArray(shapeReader, format));
                shapeReader.Align8();
                shapeDef.LineStyles.AddRange(this.ReadLineStyleArray(shapeReader, format));
                shapeReader.Align8();
            }

            /* Read the shape stuff... */

            int fillBits = (int)shapeReader.ReadUBits(4);
            int lineBits = (int)shapeReader.ReadUBits(4);

            this.ReadShapeRecordsInto(shapeDef, shapeReader, ref fillBits, ref lineBits, format);

            return shapeDef;
        }