Beispiel #1
0
    public Chip GetNewBomb(int2 coord, string powerup, Vector3 position, int id)
    {
        SessionAssistant.ChipInfo p = SessionAssistant.main.chipInfos.Find(pu => pu.name == powerup);
        if (p == null)
        {
            return(null);
        }
        id = Mathf.Clamp(id, 0, Chip.colors.Length);
        GameObject o = ContentAssistant.main.GetItem(p.contentName + (p.color ? Chip.chipTypes[id] : ""));

        o.transform.position = position;
        o.name = p.contentName + (p.color ? Chip.chipTypes[id] : "");
        if (Slot.GetSlot(coord).chip)
        {
            o.transform.position = Slot.GetSlot(coord).chip.transform.position;
        }
        Chip chip = o.GetComponent <Chip>();

        Slot.GetSlot(coord).chip = chip;
        return(chip);
    }
Beispiel #2
0
    // Field generator
    public IEnumerator  CreateField()
    {
        RemoveField();          // Removing old field

        field = new Field(LevelProfile.main.GetClone());

        Slot.folder      = new GameObject().transform;
        Slot.folder.name = "Slots";

        Slot.all.Clear();

        Vector3 fieldDimensions = new Vector3(field.width - 1, field.height - 1, 0) * ProjectParameters.main.slot_offset;

        foreach (SlotSettings settings in field.slots.Values)
        {
            yield return(0);

            Slot slot;

            #region Creating a new empty slot
            Vector3    position = new Vector3(settings.position.x, settings.position.y, 0) * ProjectParameters.main.slot_offset - fieldDimensions / 2;
            GameObject obj      = ContentAssistant.main.GetItem("SlotEmpty", position);
            obj.name = "Slot_" + settings.position.x + "x" + settings.position.y;
            obj.transform.SetParent(Slot.folder);
            slot       = obj.GetComponent <Slot>();
            slot.coord = settings.position;
            Slot.all.Add(slot.coord, slot);
            #endregion

            #region Creating a generator
            if (settings.generator)
            {
                slot.gameObject.AddComponent <SlotGenerator>();
            }
            #endregion

            #region Creating a teleport
            if (settings.teleport != int2.Null)
            {
                slot.slotTeleport.target_postion = settings.teleport;
            }
            else
            {
                Destroy(slot.slotTeleport);
            }
            #endregion

            #region Setting gravity direction
            slot.slotGravity.gravityDirection = settings.gravity;
            #endregion

            #region Setting sugar target (by slot tag)
            if (LevelProfile.main.target == FieldTarget.SugarDrop && settings.tags.Contains("SugarDrop"))
            {
                slot.sugarDropSlot = true;
                GameObject sd = ContentAssistant.main.GetItem("SugarDrop", position);
                sd.name                    = "SugarDrop";
                sd.transform.parent        = slot.transform;
                sd.transform.localPosition = Vector3.zero;
                sd.transform.Rotate(0, 0, Utils.SideToAngle(settings.gravity) + 90);
            }
            #endregion

            #region Creating a block
            if (settings.block_type != "")
            {
                GameObject b_obj = ContentAssistant.main.GetItem(settings.block_type);
                b_obj.transform.SetParent(slot.transform);
                b_obj.transform.localPosition = Vector3.zero;
                b_obj.name = settings.block_type + "_" + settings.position.x + "x" + settings.position.y;
                IBlock block = b_obj.GetComponent <IBlock>();
                slot.block  = block;
                block.slot  = slot;
                block.level = settings.block_level;
                block.Initialize();
            }
            #endregion

            #region Create a jelly
            if (LevelProfile.main.target == FieldTarget.Jelly && settings.jelly_level > 0)
            {
                GameObject j_obj;
                switch (settings.jelly_level)
                {
                case 1: j_obj = ContentAssistant.main.GetItem("SingleLayerJelly");
                    break;

                case 2:
                default: j_obj = ContentAssistant.main.GetItem("Jelly");
                    break;
                }
                j_obj.transform.SetParent(slot.transform);
                j_obj.transform.localPosition = Vector3.zero;
                j_obj.name = "Jelly_" + settings.position.x + "x" + settings.position.y;
                Jelly jelly = j_obj.GetComponent <Jelly>();
                slot.jelly = jelly;
            }
            #endregion

            #region Create a jam
            if (LevelProfile.main.target == FieldTarget.Jam)
            {
                Jam.JamIt(slot, settings.jam);
            }
            #endregion

            #region Create a chip
            if (!string.IsNullOrEmpty(settings.chip) && (slot.block == null || slot.block.CanItContainChip()))
            {
                SessionAssistant.ChipInfo chipInfo = SessionAssistant.main.chipInfos.Find(x => x.name == settings.chip);
                if (chipInfo != null)
                {
                    string     key   = chipInfo.contentName + (chipInfo.color ? Chip.chipTypes[Mathf.Clamp(settings.color_id, 0, Chip.colors.Length - 1)] : "");
                    GameObject c_obj = ContentAssistant.main.GetItem(key);
                    c_obj.transform.SetParent(slot.transform);
                    c_obj.transform.localPosition = Vector3.zero;
                    c_obj.name = key;
                    slot.chip  = c_obj.GetComponent <Chip>();
                }
            }
            #endregion
        }

        Slot.Initialize();

        foreach (int2 coord in field.wall_vertical)
        {
            yield return(0);

            #region Create a vertical wall
            Slot slot = Slot.GetSlot(coord);
            if (slot)
            {
                slot.SetWall(Side.Left);
                slot = slot[Side.Left];
                if (slot)
                {
                    slot.SetWall(Side.Right);
                }
            }
            #endregion
        }

        foreach (int2 coord in field.wall_horizontal)
        {
            yield return(0);

            #region Create a horizontal wall
            Slot slot = Slot.GetSlot(coord);
            if (slot)
            {
                slot.SetWall(Side.Bottom);
                slot = slot[Side.Bottom];
                if (slot)
                {
                    slot.SetWall(Side.Top);
                }
            }
            #endregion
        }

        List <Pair <int2> > walls = new List <Pair <int2> >();
        foreach (Slot slot in Slot.all.Values)
        {
            foreach (Side side in Utils.straightSides)
            {
                if (slot[side] != null)
                {
                    continue;
                }

                Pair <int2> pair = new Pair <int2>(slot.coord, slot.coord + Utils.SideOffset(side));
                if (walls.Contains(pair))
                {
                    continue;
                }

                yield return(0);

                #region Create a wall object
                Vector3 position = new Vector3(Utils.SideOffsetX(side), Utils.SideOffsetY(side), 0) * 0.353f;

                GameObject w_obj = ContentAssistant.main.GetItem("Wall");
                w_obj.transform.SetParent(slot.transform);
                w_obj.transform.localPosition = position;
                w_obj.name = "Wall_" + side;
                if (Utils.SideOffsetY(side) != 0)
                {
                    w_obj.transform.Rotate(0, 0, 90);
                }

                walls.Add(pair);
                #endregion
            }
        }

        SlotGravity.Reshading();

        yield return(0);

        SUBoosterButton.Generate(Slot.folder);

        // 広告用に位置をずらしてます
        Slot.folder.transform.localPosition = new Vector3(0.0f, 0.45f, 0.0f);
    }
Beispiel #3
0
    // Field generator
    public IEnumerator  CreateField()
    {
        RemoveField();          // Removing old field

        field = new Field(LevelProfile.main.GetClone());

        Slot.folder      = new GameObject().transform;
        Slot.folder.name = "Slots";


        Slot.all.Clear();

        Vector3 fieldDimensions = new Vector3(field.width - 1, field.height - 1, 0) * ProjectParameters.main.slot_offset;

        foreach (SlotSettings settings in field.slots.Values)
        {
            yield return(0);

            Slot slot;

            #region Creating a new empty slot
            Vector3    position = new Vector3(settings.position.x, settings.position.y, 0) * ProjectParameters.main.slot_offset - fieldDimensions / 2;
            GameObject obj      = ContentAssistant.main.GetItem("SlotEmpty", position);
            obj.name = "Slot_" + settings.position.x + "x" + settings.position.y;
            obj.transform.SetParent(Slot.folder);
            slot       = obj.GetComponent <Slot>();
            slot.coord = settings.position;
            Slot.all.Add(slot.coord, slot);
            #endregion

            #region Creating a generator
            if (settings.generator)
            {
                slot.gameObject.AddComponent <SlotGenerator>();
            }
            #endregion

            #region Creating a block
            if (settings.block_type != "")
            {
                GameObject b_obj = ContentAssistant.main.GetItem(settings.block_type);
                b_obj.transform.SetParent(slot.transform);
                b_obj.transform.localPosition = Vector3.zero;
                b_obj.name = settings.block_type + "_" + settings.position.x + "x" + settings.position.y;
                IBlock block = b_obj.GetComponent <IBlock>();
                slot.block  = block;
                block.slot  = slot;
                block.level = settings.block_level;
                block.Initialize();
            }
            #endregion

            #region Create a chip
            if (!string.IsNullOrEmpty(settings.chip) && (slot.block == null || slot.block.CanItContainChip()))
            {
                SessionAssistant.ChipInfo chipInfo = SessionAssistant.main.chipInfos.Find(x => x.name == settings.chip);
                if (chipInfo != null)
                {
                    string     key   = chipInfo.contentName + (chipInfo.color ? Chip.chipTypes[Mathf.Clamp(settings.color_id, 0, Chip.colors.Length - 1)] : "");
                    GameObject c_obj = ContentAssistant.main.GetItem(key);
                    c_obj.transform.SetParent(slot.transform);
                    c_obj.transform.localPosition = Vector3.zero;
                    c_obj.name = key;
                    slot.chip  = c_obj.GetComponent <Chip>();
                }
            }
            #endregion
        }

        Slot.Initialize();

        List <Pair <int2> > outlines = new List <Pair <int2> >();
        foreach (Slot slot in Slot.all.Values)
        {
            foreach (Side side in Utils.straightSides)
            {
                if (slot[side] != null)
                {
                    continue;
                }

                Pair <int2> pair = new Pair <int2>(slot.coord, slot.coord + Utils.SideOffset(side));
                if (outlines.Contains(pair))
                {
                    continue;
                }

                yield return(0);

                #region Create a outline object
                Vector3 position = new Vector3(Utils.SideOffsetX(side), Utils.SideOffsetY(side), 0) * 0.353f;

                GameObject ol_obj = ContentAssistant.main.GetItem("Outline");
                ol_obj.transform.SetParent(slot.transform);
                ol_obj.transform.localPosition = position;
                ol_obj.name = "Outline_" + side;
                if (Utils.SideOffsetY(side) != 0)
                {
                    ol_obj.transform.Rotate(0, 0, 90);
                }

                outlines.Add(pair);
                #endregion
            }
        }

        SlotGravity.Reshading();

        yield return(0);
    }