示例#1
0
    public void CheckPast(LevelMoment moment)
    {
        if (moment.phase == 0)
        {
            return;
        }

        int p = moment.phase;

        List <LevelMoment> present = moments[p];
        List <LevelMoment> past    = moments[p - 1];

        if (present.Count <= past.Count)
        {
            return;
        }

        LevelMoment terminalMoment = past[past.Count - 1];

        int k = Mathf.Abs(present.Count - past.Count);

        for (int i = 0; i < k; i++)
        {
            past.Add(terminalMoment);
        }

        TimeLineCreatedEvent(new Vector2Int(p - 1, past.Count));

        //Proceed recursively
        terminalMoment = past[past.Count - 1];
        CheckPast(terminalMoment);
    }
示例#2
0
    public void LoadData()
    {
        if (transData == null)
        {
            GameObject obj = GameObject.FindGameObjectWithTag("TransitionData");
            transData = obj.GetComponentInChildren <DataTransition>();
        }

        if (levelConfig == null)
        {
            levelConfig = SingletonJsonLoadable <ConfigurationLevelDataPair> .Instance;
        }

        levelConfig.Configure("LevelData/" + transData.nextLevelPath, "LevelData/" + transData.nextLevelPath);
        levelConfig.Load();

        startingMoment = levelConfig.data.startingMoment;
        startingMoment.BuildLevel(levelConfig.data.levelAsString);

        moments = new List <List <LevelMoment> >();

        List <LevelMoment> startingTimeline = new List <LevelMoment>
        {
            startingMoment.DeepCopyLevelMoment()
        };

        moments.Add(startingTimeline);
    }
示例#3
0
    private bool ProcessSpawners(LevelMoment mom)
    {
        bool result = false;

        List <Spawner> spawners = new List <Spawner>();

        spawners.AddRange(mom.spawners);

        foreach (Spawner spawn in spawners)
        {
            spawn.age--;

            if (spawn.age == 0)
            {
                mom.spawners.Remove(spawn);
            }
            if (spawn.age % 2 != 0)
            {
                continue;
            }

            Lemming lem = spawn.MakeLemming();
            if (mom.IsFree(lem.position))
            {
                mom.lemmings.Add(lem);
            }
        }

        return(result);
    }
示例#4
0
 public void RedrawHud(LevelMoment moment)
 {
     if (OnRedrawHudEvent != null)
     {
         OnRedrawHudEvent(moment);
     }
 }
示例#5
0
 public void OnUpdate(LevelMoment moment)
 {
     text.text = "";
     if (moment.goal > 0)
     {
         text.text += moment.goal;
     }
 }
示例#6
0
    private void CentreDisplay(DisplayData data)
    {
        LevelMoment moment    = levelData.startingMoment;
        Transform   container = data.centeringTransform;

        container.localPosition += new Vector3(.5f, .5f, .5f);
        container.localPosition -= new Vector3(moment.x / 2f, moment.y / 2f, moment.z / 2f);
    }
 public void SetMoment(LevelMoment moment)
 {
     if (this.moment == moment)
     {
         return;
     }
     UnbuildDisplay();
     this.moment = moment;
 }
示例#8
0
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        lemming.position = block.pos;

        LevelData.Instance.WormHole(next);
        next.timeTraveler = lemming;
        next.lemmings.Remove(lemming);
        next.phasedLemmings.Remove(lemming);
        next.fail--;
    }
示例#9
0
    public void OnUpdate(LevelMoment moment)
    {
        text.text = "";

        if (moment.goal > 0)
        {
            text.text += moment.MoveableCount(key);
        }

        button.SetActive(moment.MoveableCount(key) > 0);
    }
示例#10
0
    public void OnMove(LevelMoment m)
    {
        if (targets.Count > 0)
        {
            return;
        }

        for (int i = 0; i < numWarps; i++)
        {
            targets.Enqueue(Random.Range(warpMin, warpMax));
        }
        targets.Enqueue(defaultSpeed);
    }
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        Vector3Int i = block.pos;

        if (fade > '0')
        {
            next.level[i.x, i.y, i.z] = fade;
        }
        else
        {
            next.level[i.x, i.y, i.z] = GameBoardCubeDictionary.OPEN_CUBE;
        }
    }
示例#12
0
    public LevelMoment DeepCopyLevelMoment()
    {
        LevelMoment copy = new LevelMoment
        {
            x = this.x,
            y = this.y,
            z = this.z,

            goal           = this.goal,
            fail           = this.fail,
            time           = this.time,
            phase          = this.phase,
            terminalBuffer = this.terminalBuffer,
            wormholeOutPos = this.wormholeOutPos,
            //Shallow copy, but of type char. So the same as a deep copy. Change if switched to pointers please.
            level = (char[, , ]) this.level.Clone()
        };

        foreach (char key in moveables.Keys)
        {
            copy.moveables.Add(key, this.moveables[key]);
        }
        copy.lemmings = new List <Lemming>();

        foreach (Lemming lem in lemmings)
        {
            copy.lemmings.Add(lem.DeepCopy());
        }

        foreach (Lemming lem in savedLemmings)
        {
            copy.savedLemmings.Add(lem.DeepCopy());
        }

        foreach (Lemming lem in deadLemmings)
        {
            copy.deadLemmings.Add(lem.DeepCopy());
        }

        foreach (Lemming lem in phasedLemmings)
        {
            copy.phasedLemmings.Add(lem.DeepCopy());
        }

        foreach (Spawner spawn in spawners)
        {
            copy.spawners.Add(spawn.DeepCopy());
        }

        return(copy);
    }
示例#13
0
    private GameBlock GetBlock(LevelMoment moment, Vector3Int pos)
    {
        GameBlockBuilder blockBuilder = new GameBlockBuilder();

        //Count oob as a normal block
        if (!InBounds(moment, pos))
        {
            return(blockBuilder.Build(GameBoardCubeDictionary.NORMAL_CUBE, pos));
        }

        GameBlock result = blockBuilder.Build(moment.CharAt(pos), pos);

        return(result);
    }
示例#14
0
    public void WormHole(LevelMoment moment)
    {
        Vector2Int i = moment.GetIndex();

        if (moments.Count < (i.x + 2))
        {
            List <LevelMoment> timeline     = new List <LevelMoment>();
            List <LevelMoment> prevTimeline = moments[i.x];

            LevelMoment prevStart = LevelData.Instance.startingMoment;
            LevelMoment newStart  = prevStart.DeepCopyLevelMoment();

            newStart.phase = i.x + 1;

            newStart.PhaseInLemmings();

            for (int l = 0; l < newStart.y; l++)
            {
                for (int k = 0; k < newStart.z; k++)
                {
                    for (int m = 0; m < newStart.x; m++)
                    {
                        char key = newStart.level[m, l, k];
                        if (key == GameBoardCubeDictionary.WORMHOLE_IN)
                        {
                            newStart.Remove(new Vector3Int(m, l, k), key);
                        }
                    }
                }
            }

            newStart.RecieveTimeTraveler();
            timeline.Add(newStart);

            moments.Add(timeline);

            Vector2Int j = new Vector2Int(i.x + 1, 0);
            if (TimeLineCreatedEvent != null)
            {
                TimeLineCreatedEvent(j);
            }
            else
            {
                AddToEvent(j);
            }
        }
    }
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        Lemming check = null;

        foreach (Lemming lem in prev.lemmings)
        {
            if (check != null)
            {
                break;
            }
            if (lem.position == block.pos)
            {
                check = lem;
            }
        }

        foreach (Lemming lem in prev.phasedLemmings)
        {
            if (check != null)
            {
                break;
            }
            if (lem.position == block.pos)
            {
                check = lem;
            }
        }

        if (check != null)
        {
            Vector3Int test = check.direction * -1;
            if (lemming.direction == test)
            {
                if (check.position.y > 0)
                {
                    char below = prev.level[check.position.x, check.position.y - 1, check.position.z];
                    if ((below != GameBoardCubeDictionary.OPEN_CUBE) && (below != GameBoardCubeDictionary.NEGA_CUBE))
                    {
                        lemming.Turn();
                        return;
                    }
                }
            }
        }

        lemming.position = block.pos;
    }
示例#16
0
 public void OnUpdate(LevelMoment moment)
 {
     //If the player won
     if (moment.IsWin())
     {
         dLight.color = winColor;
     }
     //If the player can't win in this timeline
     else if (moment.IsLose())
     {
         dLight.color = failColor;
     }
     else
     {
         dLight.color = regColor;
     }
 }
示例#17
0
    private GameBlock GetMoveBlock(LevelMoment moment, Vector3Int dPos, Vector3Int fPos)
    {
        GameBlock result = null;

        //Check below for
        result = GetBlock(moment, dPos);


        if (!(result.enterMoveBehaviour is BlockedIntoMoveBehaviour))
        {
            return(result);
        }

        result = GetBlock(moment, fPos);

        return(result);
    }
示例#18
0
    private bool InBounds(LevelMoment mom, Vector3Int pos)
    {
        if ((pos.x < 0) || (pos.y < 0) || (pos.z < 0))
        {
            return(false);
        }

        Vector3Int upper = new Vector3Int(mom.x, mom.y, mom.z);

        upper -= pos;
        if ((upper.x <= 0) || (upper.y <= 0) || (upper.z <= 0))
        {
            return(false);
        }

        return(true);
    }
示例#19
0
    private LevelMoment FindOldMoment()
    {
        foreach (List <LevelMoment> timeline in levelData.moments)
        {
            LevelMoment terminalMoment = timeline[timeline.Count - 1];
            if (terminalMoment.CanChange())
            {
                if ((terminalMoment.time == 0) && (terminalMoment.phase > 0))
                {
                    terminalMoment.RecieveTimeTraveler();
                }
                return(terminalMoment);
            }
        }

        return(null);
    }
示例#20
0
    private void CheckDisplayUpdate()
    {
        //See if the mouse is over any point
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit))
        {
            Vector2Int i             = momDisplay.displayCenter;
            Transform  centerDisplay = momDisplay.displays[i.x][i.y].transform;

            Transform t = hit.collider.transform;

            //Only place the new object in the centre display
            if (!t.IsChildOf(centerDisplay))
            {
                return;
            }

            //Check that the square in the game space is free
            LevelMoment moment = momDisplay.GetFocusedMoment();

            Vector3Int j = new Vector3Int(Mathf.RoundToInt(t.localPosition.x),
                                          Mathf.RoundToInt(t.localPosition.y + 1),
                                          Mathf.RoundToInt(t.localPosition.z));

            if (!moment.IsFree(j))
            {
                return;
            }


            displayTrans.position    = t.position + Vector3.up;
            displayTrans.eulerAngles = t.eulerAngles;

            DisplayData data = centerDisplay.GetComponentInChildren <DisplayData>();

            displayTrans.parent = data.centeringTransform;
            tempObj.SetActive(true);
        }
        else
        {
            tempObj.SetActive(false);
        }
    }
示例#21
0
    private void CheckDisplayUpdate()
    {
        //See if the mouse is over any point
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit))
        {
            Vector2Int i             = momDisplay.displayCenter;
            Transform  centerDisplay = momDisplay.displays[i.x][i.y].transform;

            Transform t = hit.collider.transform;

            //Only place the new object in the centre display
            if (!t.IsChildOf(centerDisplay))
            {
                return;
            }

            //Check that the square in the game space is free
            LevelMoment moment = momDisplay.GetFocusedMoment();

            Vector3Int j = new Vector3Int(Mathf.RoundToInt(t.localPosition.x),
                                          Mathf.RoundToInt(t.localPosition.y),
                                          Mathf.RoundToInt(t.localPosition.z));


            key = moment.level[j.x, j.y, j.z];

            if (IsRemoveable(key))
            {
                overI = j;

                Highlight(t);
            }
            else
            {
                UnHighlight();
            }
        }
        else
        {
            UnHighlight();
        }
    }
示例#22
0
    private void PlaceObject()
    {
        Vector3    objPos = tempObj.transform.localPosition;
        Vector3Int pos    = new Vector3Int(Mathf.RoundToInt(objPos.x),
                                           Mathf.RoundToInt(objPos.y),
                                           Mathf.RoundToInt(objPos.z));

        LevelMoment moment  = momDisplay.GetFocusedMoment();
        bool        changed = moment.Change(pos, key);

        if (changed)
        {
            LevelData.Instance.ChangeFuture(moment);
            logicController.updating = true;
            momDisplay.UpdateTimeline(moment);
            hudControl.RedrawHud(moment);
        }

        DisableController();
    }
示例#23
0
    private void RemoveObject()
    {
        if (overI.x < 0)
        {
            return;
        }

        LevelMoment moment  = momDisplay.GetFocusedMoment();
        bool        changed = moment.Remove(overI, key);

        if (!changed)
        {
            return;
        }

        LevelData.Instance.ChangeFuture(moment);

        momDisplay.UpdateTimeline(moment);
        hudControl.RedrawHud(moment);
        logicController.updating = true;
    }
示例#24
0
    public void UpdateTimeline(LevelMoment moment)
    {
        //Get display coordinates.
        Vector2Int momentIndex = moment.GetIndex();

        Vector2Int i = MomentIToVectorI(momentIndex);

        //If the row changed is in the current display
        int phase = moment.phase;

        while (true)
        {
            if (!InDisplayColumn(i))
            {
                return;
            }

            RebuildRow(i.x, phase);
            i.x++;
            phase++;
        }
    }
示例#25
0
    public void ChangeFuture(LevelMoment moment)
    {
        Vector2Int i = new Vector2Int(moment.phase, moment.time);

        List <LevelMoment> timeline = new List <LevelMoment>();

        for (int j = 0; j <= i.y; j++)
        {
            timeline.Add(moments[i.x][j]);
        }

        List <List <LevelMoment> > newMoments = new List <List <LevelMoment> >();

        for (int k = 0; k < i.x; k++)
        {
            newMoments.Add(moments[k]);
        }

        newMoments.Add(timeline);

        moments = newMoments;
    }
示例#26
0
    public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
    {
        Lemming check = null;

        foreach (Lemming lem in next.lemmings)
        {
            if (check != null)
            {
                break;
            }
            if (lem.position == block.pos)
            {
                check = lem;
            }
        }

        foreach (Lemming lem in next.phasedLemmings)
        {
            if (check != null)
            {
                break;
            }
            if (lem.position == block.pos)
            {
                check = lem;
            }
        }

        if (check != null)
        {
            lemming.Turn();
            return;
        }

        lemming.position = block.pos;
    }
示例#27
0
    public void RecieveTimeTraveler()
    {
        if (phase == 0)
        {
            return;
        }

        List <LevelMoment> prevTimeline = LevelData.Instance.moments[phase - 1];

        //Check if there can be a time traveler.
        if ((prevTimeline.Count - time) < 3)
        {
            return;
        }

        LevelMoment wormHole = prevTimeline[time + 2];

        if (!wormHole.HasTimeTraveler())
        {
            return;
        }

        WormHole(wormHole.timeTraveler);
    }
示例#28
0
    private void CheckBuilding()
    {
        //if (!Input.GetKeyDown(KeyCode.N)) return;

        if (isWin)
        {
            return;
        }
        bool changed = false;

        //Find next map to update. (for not just go linearly)
        LevelMoment prevMoment = FindOldMoment();

        if (prevMoment == null)
        {
            updating = false;
            return;
        }


        LevelMoment nextMoment = prevMoment.DeepCopyLevelMoment();

        if (prevMoment.terminalBuffer == 0)
        {
            prevMoment.terminalBuffer++;
        }

        nextMoment.Age();

        //Keep track of saved and dead lemming count
        Vector2Int lemCounts = new Vector2Int(nextMoment.savedLemmings.Count, nextMoment.deadLemmings.Count);

        //Go one past the last moment
        if ((lemCounts.x > 0) || (lemCounts.y > 0))
        {
            changed = true;
        }

        nextMoment.goal -= lemCounts.x;
        nextMoment.fail -= lemCounts.y;

        List <Lemming> movingLemmings = new List <Lemming>();

        movingLemmings.AddRange(nextMoment.lemmings);
        movingLemmings.AddRange(nextMoment.phasedLemmings);

        nextMoment.lemmings       = new List <Lemming>();
        nextMoment.savedLemmings  = new List <Lemming>();
        nextMoment.deadLemmings   = new List <Lemming>();
        nextMoment.phasedLemmings = new List <Lemming>();



        foreach (Lemming lem in movingLemmings)
        {
            Vector3Int pos = lem.position;

            Vector3Int forwardIndex = lem.position + lem.direction;
            Vector3Int belowIndex   = new Vector3Int(pos.x, pos.y - 1, pos.z);

            GameBlock current = null;
            GameBlock move    = null;
            GameBlock below   = null;

            current = GetBlock(prevMoment, pos);

            changed |= true;

            move  = GetBlock(prevMoment, forwardIndex);
            below = GetBlock(prevMoment, belowIndex);

            Vector3Int prevPos = lem.position;
            if (below != null)
            {
                below.overMoveBehaviour.Move(nextMoment, prevMoment, lem, below);
            }
            if ((move != null) && (prevPos == lem.position))
            {
                move.enterMoveBehaviour.Move(nextMoment, prevMoment, lem, move);
            }
            current.exitMoveBehaviour.Move(nextMoment, prevMoment, lem, below);

            Vector3Int lPos = lem.position;;
            char       key  = nextMoment.level[lPos.x, lPos.y, lPos.z];

            if (key == GameBoardCubeDictionary.END_ZONE)
            {
                nextMoment.savedLemmings.Add(lem);
            }
            else if (CheckDead(lem))
            {
                if (nextMoment.LemmingInPhase(lem))
                {
                    nextMoment.deadLemmings.Add(lem);
                }
            }
            else
            {
                if (nextMoment.LemmingInPhase(lem))
                {
                    nextMoment.lemmings.Add(lem);
                }
                else
                {
                    nextMoment.phasedLemmings.Add(lem);
                }
            }
        }

        if (changed)
        {
            if (nextMoment.HasTimeTraveler())
            {
                nextMoment.lemmings.Remove(nextMoment.timeTraveler);
            }
        }

        ProcessSpawners(nextMoment);
        nextMoment.RecieveTimeTraveler();

        LevelData.Instance.CheckPast(nextMoment);

        //If a new moment was created, add it to the timeline, call event

        if ((MomentBuiltEvent != null))
        {
            List <LevelMoment> timeline = levelData.moments[nextMoment.phase];
            Vector2Int         i        = new Vector2Int(nextMoment.phase, nextMoment.time);
            timeline.Add(nextMoment);
            MomentBuiltEvent(i);
        }
    }
示例#29
0
    private void Start()
    {
        LevelMoment moment = LevelData.Instance.moments[0][0];

        text.text += moment.MoveableCount(key);
    }
 public override void Move(LevelMoment next, LevelMoment prev, Lemming lemming, GameBlock block)
 {
     lemming.Turn();
 }