public void EnemyKilled(PatternColor bulletColor, PatternColor enemyColor, PatternShape enemyShape)
    {
        if (enemyShape != PatternShape.none)
        {
            if (patternSystem.EnemyDestroyedShape(enemyShape, (enemyColor == bulletColor)))
            {
                UIManager.Instance.SetNextColor(enemyColor);
                if (patternSystem.CurrentShape() == patternSystem.shapes[0])
                {
                    UIManager.Instance.CompletePattern();
                }
            }
            else
            {
                UIManager.Instance.ClearColors();
            }
        }

        if (enemyColor == bulletColor)
        {
            patternSystem.GotoNextColor();
            CurrentColor.SetColor(patternSystem.CurrentColor());
            NextColor.SetColor(patternSystem.NextColor());
        }
    }
Exemplo n.º 2
0
    public override void Enter()
    {
        targetProjGo.SetActive(true);
        patternProjGo_1.SetActive(true);
        patternProjGo_2.SetActive(true);

        patternProjGo_2.transform.position   = targetProjGo.transform.position;
        patternProjGo_2.transform.localScale = targetProjGo.transform.localScale;

        Mesh patternMesh = PatternShape.BuildMeshFromShape(PatternShape.Current);

        patternProjGo_1.GetComponent <MeshFilter>().mesh = patternMesh;
        patternProjGo_2.GetComponent <MeshFilter>().mesh = patternMesh;

        GUIEventDispatcher.Instance.NotifyEvent(GUIEventID.EnterTurning);
    }
Exemplo n.º 3
0
    public void SetPattern(PatternShape[] patternShapes)
    {
        DestroyChildGameObjects(grid.transform);
        shapes.Clear();

        for(int i = 0; i < patternShapes.Length; i++)
        {
            GameObject newShape = NGUITools.AddChild(grid.gameObject, getPrefabForShape(patternShapes[i]));
            newShape.name = i.ToString();
            shapes.Add(newShape.GetComponent<ShapeColorizer>());

        }

        grid.repositionNow = true;

        m_patternShapes = patternShapes;
    }
 public bool EnemyDestroyedShape(PatternShape EnemyShape, bool ColorMatch)//When a bullet destroys an enemy it should send this message with the shape
 {
     if (EnemyShape == CurrentShape())
     {//match!
         //ADD POINTS AND MOVE ONTO NEXT SHAPE
         SendMessage("EnemyDestroyedShapeMatch", ColorMatch);
         GotoNextShape();
         return true;
     }
     else
     {//no match!
         //ADD points and reset shape pattern
         SendMessage("EnemyDestroyedShapeNoMatch", ColorMatch);
         ResetShapePattern();
         return false;
     }
 }
Exemplo n.º 5
0
    public static Mesh BuildMeshFromShape(PatternShape shape)
    {
        var points = shape.TransformedPoints;

        Vector3[] vertices  = new Vector3[points.Length * 2];
        int[]     triangles = new int[(points.Length - 1) * 2 * 3];

        int vertIndex     = 0;
        int triangleIndex = 0;

        for (int i = 0; i < points.Length; i++)
        {
            vertices[vertIndex]       = points[i];
            vertices[vertIndex + 1]   = vertices[vertIndex];
            vertices[vertIndex + 1].y = -vertices[vertIndex].y;

            if (i > 0)
            {
                triangles[triangleIndex + 0] = vertIndex - 2;
                triangles[triangleIndex + 1] = vertIndex;
                triangles[triangleIndex + 2] = vertIndex - 1;
                triangles[triangleIndex + 3] = vertIndex - 1;
                triangles[triangleIndex + 4] = vertIndex;
                triangles[triangleIndex + 5] = vertIndex + 1;

                triangleIndex += 6;
            }

            vertIndex += 2;
        }

        var mesh = new Mesh();

        mesh.Clear();
        mesh.vertices  = vertices;
        mesh.triangles = triangles;

        return(mesh);
    }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        path.Closed = GUILayout.Toggle(path.Closed, "Closed");

        GUILayout.Space(100);

        showControlPoints = GUILayout.Toggle(showControlPoints, "Show Control Points");

        if (GUILayout.Button("Reset"))
        {
            pathProvider.path = new Path(2f, 1f);
            path = pathProvider.path;
        }

        GUILayout.Space(100);

        fileDirectory = GUILayout.TextField(fileDirectory);
        fileName      = GUILayout.TextField(fileName);

        if (GUILayout.Button("Save"))
        {
            var ps     = path.GetPoints(pathProvider.segment);
            var points = new Vector2[ps.Count];

            for (int i = 0; i < ps.Count; i++)
            {
                points[i] = ps[i];
            }

            PatternShape shapeData = CreateInstance <PatternShape>();
            shapeData.points = points;
            AssetDatabase.CreateAsset(shapeData, fileDirectory + fileName + ".asset");
            AssetDatabase.SaveAssets();
        }
    }
Exemplo n.º 7
0
 GameObject getPrefabForShape(PatternShape shape)
 {
     for(int i = 0; i < Prefabs.Length; i++)
     {
         if (Prefabs[i].shape == shape)
         {
             return Prefabs[i].prefab;
         }
     }
     return null;
 }
Exemplo n.º 8
0
        public static bool PatternMosaic(ref Bitmap bmp, PatternShape ps,
                                                     int width, int height)
        {
            if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
                return false;

            if ((width < 5) | (width > 20)) return false;
            if ((height < 5) | (height > 60)) return false;

            int w = bmp.Width;
            int h = bmp.Height;

            double ww = (double)width;
            double hh = (double)height;

            double[] wd = new double[height];
            int[] iwd = new int[height];

            switch (ps)
            {
                case PatternShape.Brick:
                    for (int i = 0; i < height; i++)
                    {
                        if ((double)i < (hh / 2d))
                            wd[i] = ww;
                        else
                            wd[i] = 0;
                        iwd[i] = (int)(wd[i] + 0.5);
                    }
                    break;

                case PatternShape.Diamond:
                    for (int i = 0; i < height; i++)
                    {
                        if ((double)i < (hh / 2d))
                            wd[i] = ww * (double)i * 2d / hh;
                        else
                            wd[i] = ww * 2d - ww * (double)i * 2d / hh;
                        iwd[i] = (int)(wd[i] + 0.5);
                    }
                    break;

                case PatternShape.Hexagon:
                    for (int i = 0; i < height; i++)
                    {
                        if ((double)i < (hh / 6d))
                            wd[i] = ww * (double)i * 6d / hh;
                        else
                        {
                            if ((double)i < (hh / 2d))
                                wd[i] = ww;
                            else
                            {
                                if ((double)i < (hh * 2d / 3d))
                                    wd[i] = ww * 4d - ww * (double)i * 6d / hh;
                                else
                                    wd[i] = 0;
                            }
                        }

                        iwd[i] = (int)(wd[i] + 0.5);
                    }
                    break;

                case PatternShape.Circle:
                    for (int i = 0; i < height; i++)
                    {
                        if ((double)i < (hh / 2d))
                            wd[i] = ww * (double)i * 2d / hh
                                - (ww / 8d) * Math.Sin((double)i * 4d / hh * Math.PI);
                        else
                            wd[i] = ww * 2d - ww * (double)i * 2d / hh
                                + (ww / 8d) * Math.Sin((double)(i - hh / 2d) *
                                                                    4d / hh * Math.PI);
                        iwd[i] = (int)(wd[i] + 0.5);
                    }
                    break;
            }

            bool eflag = false;

            int r, g, b, count, d, im, yinit;
            double rm;

            Bitmap tmp = bmp.Clone() as Bitmap;

            Graphics gr = Graphics.FromImage(bmp);
            gr.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pn = new Pen(Color.Black, 1.0f);

            BmpProc24 src = new BmpProc24(tmp);

            for (int x = 0; x < w - 1 + width; x += width)
            {
                eflag = !eflag;

                if (eflag) yinit = 0; else yinit = -height / 2;

                for (int y = yinit; y < h - 1; y += height)
                {
                    r = g = b = count = 0;

                    for (int iy = y; iy < y + height; iy++)
                    {
                        if ((iy > h - 1) | (iy < 0)) continue;

                        d = iy % height;

                        if (eflag)
                        {
                            im = iwd[d];
                            rm = wd[d];
                        }
                        else
                        {
                            im = width - iwd[d];
                            rm = ww - wd[d];
                        }

                        for (int ix = x - im; ix <= x + im; ix++)
                        {
                            if ((ix < 0) | (ix > w - 1)) continue;

                            src.SetXY(ix, iy);
                            r += src.R;
                            g += src.G;
                            b += src.B;
                            count++;
                        }
                    }

                    if (count == 0) continue;

                    r /= count;
                    g /= count;
                    b /= count;

                    pn.Color = Color.FromArgb(r, g, b);

                    for (int iy = y; iy < y + height; iy++)
                    {
                        if ((iy > h - 1) | (iy < 0)) continue;

                        d = iy % height;

                        if (eflag)
                        {
                            im = iwd[d];
                            rm = wd[d];
                        }
                        else
                        {
                            im = width - iwd[d];
                            rm = (double)width - wd[d];
                        }

                        gr.DrawLine(pn, (float)(x - rm), (float)iy,
                                                 (float)(x + rm), (float)iy);

                    }
                }
            }

            CallDispose(src, gr, tmp);

            return true;
        }