Esempio n. 1
0
    // Delete all cells and clear the list
    private void Cleanup()
    {
        gameState = GameStates.Finishing;

        for (int i = allCells.Count - 1; i >= 0; i--)
        {
            OneCellClass cell = allCells[i];
            Destroy(cell);
        }

        allCells.Clear();
    }
Esempio n. 2
0
    private void OnDrawGizmos()
    {
        if (gameState != GameStates.Running)
        {
            return;
        }

        OneCellClass current = GetCurrentCell();

        Gizmos.color = Color.green;
        Gizmos.DrawWireCube(current.SmallCell.transform.position, current.SmallCell.transform.localScale);
    }
Esempio n. 3
0
    // Move an entire column to the north or south
    void MoveColumn(int from, bool onNorth)
    {
        if (from == 2) // same column as the start room = impossible
        {
            Audio_DeathScream[1].Play();
            return;
        }

        if ((from != 0) && (from != 1) && (from != 3) && (from != 4))
        {
            Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s] MoveColumn should start from the beginning of a column not {from}.");
            return;
        }

        int        currentCellId = lookupTab[playerCellId];
        List <int> column        = new List <int>(5);

        for (int i = 0; i < 5; ++i)
        {
            column.Add(lookupTab[from + i * 5]);
        }

        if (onNorth)
        {
            lookupTab[from + 0]  = column[1];
            lookupTab[from + 5]  = column[2];
            lookupTab[from + 10] = column[3];
            lookupTab[from + 15] = column[4];
            lookupTab[from + 20] = column[0];
        }
        else
        {
            lookupTab[from + 0]  = column[4];
            lookupTab[from + 5]  = column[0];
            lookupTab[from + 10] = column[1];
            lookupTab[from + 15] = column[2];
            lookupTab[from + 20] = column[3];
        }

        float x = from;

        for (int j = 0; j < 5; ++j)
        {
            float        z    = j;
            OneCellClass cell = allCells[lookupTab[from + j * 5]];
            cell.m_MiniGameTranslation        = new Vector3(x * 0.1f, 0.0f, z * -0.1f) + transform.position;
            cell.SmallCell.transform.position = cell.m_MiniGameTranslation;
        }

        // reposition the player
        SetPlayerLookupId(currentCellId);
    }
Esempio n. 4
0
    // Move an entire row to the east or west
    void MoveRow(int from, bool onEast)
    {
        if (from == 10) // same row as the start room = impossible
        {
            Audio_DeathScream[1].Play();
            return;
        }

        if ((from != 0) && (from != 5) && (from != 15) && (from != 20))
        {
            Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s] MoveRow should start from the beginning of a row not {from}.");
            return;
        }

        int        currentCellId = lookupTab[playerCellId];
        List <int> row           = new List <int>(5);

        for (int i = 0; i < 5; ++i)
        {
            row.Add(lookupTab[from + i]);
        }

        if (onEast)
        {
            lookupTab[from + 0] = row[4];
            lookupTab[from + 1] = row[0];
            lookupTab[from + 2] = row[1];
            lookupTab[from + 3] = row[2];
            lookupTab[from + 4] = row[3];
        }
        else
        {
            lookupTab[from + 0] = row[1];
            lookupTab[from + 1] = row[2];
            lookupTab[from + 2] = row[3];
            lookupTab[from + 3] = row[4];
            lookupTab[from + 4] = row[0];
        }

        float z = from / 5;

        for (int j = 0; j < 5; ++j)
        {
            float        x    = j;
            OneCellClass cell = allCells[lookupTab[from + j]];
            cell.m_MiniGameTranslation        = new Vector3(x * 0.1f, 0.0f, z * -0.1f) + transform.position;
            cell.SmallCell.transform.position = cell.m_MiniGameTranslation;
        }

        // reposition the player
        SetPlayerLookupId(currentCellId);
    }
Esempio n. 5
0
    public CellTypes GetWestType(int current)
    {
        OneCellClass cell = GetWest(current);

        if (cell)
        {
            return(cell.cellType);
        }
        else
        {
            return(CellTypes.Undefined);
        }
    }
Esempio n. 6
0
    // Move the player position on the board to the south -Z
    public void MovePlayerSouth()
    {
        if (playerCellId < 20)
        {
            OneCellClass current = GetCurrentCell();
            current.OnPlayerExit();

            playerCellId += 5;

            current = GetCurrentCell();
            current.OnPlayerEnter();

            // Update cells models to display
            UpdateCellsModels();
        }
    }
Esempio n. 7
0
    // Make sure the player is in the correct cell
    void SetPlayerLookupId(int cellId)
    {
        OneCellClass current       = GetCurrentCell();
        int          currentCellId = current.cellId;

        if (currentCellId != cellId)
        {
            int i = 0;
            foreach (int id in lookupTab)
            {
                if (id == cellId)
                {
                    playerCellId = i;
                }
                i++;
            }
        }
    }
Esempio n. 8
0
    // Move the player position on the board to the west -X
    public void MovePlayerWest()
    {
        if (playerCellId % 5 == 0)
        {
            return;
        }
        OneCellClass current = GetCurrentCell();

        current.OnPlayerExit();

        playerCellId--;

        current = GetCurrentCell();
        current.OnPlayerEnter();

        // Update cells models to display
        UpdateCellsModels();
    }
Esempio n. 9
0
    void TestGetNorth()
    {
        string msg = "";
        int    id  = 10;

        for (int i = 0; i < 5; ++i)
        {
            OneCellClass current = GetNorth(id + i);
            if (current != null)
            {
                msg += current.cellId.ToString() + " ";
            }
            else
            {
                msg += " .. ";
            }
        }
        Debug.Log($"[GameMgr] north of 10 -> {msg}");
    }
Esempio n. 10
0
    // called once per fixed framerate
    private void FixedUpdate()
    {
        //Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s]");

        // always update the player pos
        OneCellClass current = GetCurrentCell();

        if (current != null)
        {
            playerSphere.transform.position = current.SmallCell.transform.position + new Vector3(0.0f, 0.1f, 0.0f);

            if (current.cellType == CellTypes.Exit)
            {
                if (gameState != GameStates.ExitFound)
                {
                    gameState = GameStates.ExitFound;
                    GameObject title = m_basicCanvas.transform.GetChild(0).gameObject;
                    title.GetComponent <TextMeshProUGUI>().text = $"EXIT found!";
                }
            }
        }
    }
Esempio n. 11
0
    // Update cells models to display when entering a new room
    void UpdateCellsModels()
    {
        OneCellClass current = GetCurrentCell();
        CellTypes    curType = current.cellType;
        int          curId   = current.cellId;

        m_CentreModels.SetActiveModel(curType);
        m_NorthModels.SetActiveModel(GetNorthType(curId));
        m_EastModels.SetActiveModel(GetEastType(curId));
        m_SouthModels.SetActiveModel(GetSouthType(curId));
        m_WestModels.SetActiveModel(GetWestType(curId));

        if (curType == CellTypes.Exit)
        {
            float light_range  = 4.0f;
            Color light_colour = new Color(0.9f, 1.0f, 0.9f, 1.0f);
            SetupLights(m_CentreModels, light_range, light_colour);

            //remove the north wall "Trap_1" from south_cell...
            GameObject southModel = m_SouthModels.GetActiveModel();
            if (southModel)
            {
                GameObject northWall = southModel.transform.Find("Trap_1").gameObject;
                //Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s] {m_SouthModels.transform.name}, model: {northWall.name}");
                if (northWall != null)
                {
                    northWall.SetActive(false);
                }
            }
        }
        else if (curType == CellTypes.Deadly)
        {
            SetupLightsBySubType(m_CentreModels, current.cellSubType);
        }

        // Activate levers for centre model only
        if (m_CentreModels.m_GenCellA.activeSelf == true)
        {
            //Debug.Log($"[GameMgr][{Time.fixedTime - startingTime}s] {m_CentreModels.m_GenCellA.name}, MechanismNorth= {current.cellId}");

            /*
             * GameObject genAModel = m_CentreModels.m_GenCellA.gameObject;
             * GameObject h1 = genAModel.transform.Find("Trap_1").gameObject;
             * GameObject h2 = h1.transform.Find("manche_base").gameObject;
             * GameObject h3 = h2.transform.Find("manche").gameObject;
             * h3.SetActive(true);
             * OneCellClass toto = GetCurrentCell();
             * MechanismMove mec = h3.GetComponentInChildren<MechanismMove>();
             * toto.MechanismNorth = mec;
             */
            if (current.MechanismNorth.m_modelSet == false)
            {
                MechanismMove[] mecs = m_CentreModels.m_GenCellA.GetComponentsInChildren <MechanismMove>();
                foreach (MechanismMove mec in mecs)
                {
                    mec.enabled = true;
                    switch (mec.cardinal)
                    {
                    case CardinalPoint.North:
                        current.MechanismNorth            = mec;
                        current.MechanismNorth.m_modelSet = true;
                        break;

                    case CardinalPoint.East:
                        current.MechanismEast            = mec;
                        current.MechanismEast.m_modelSet = true;
                        break;

                    case CardinalPoint.South:
                        current.MechanismSouth            = mec;
                        current.MechanismSouth.m_modelSet = true;
                        break;

                    case CardinalPoint.West:
                        current.MechanismWest            = mec;
                        current.MechanismWest.m_modelSet = true;
                        break;

                    default:
                        Debug.LogWarning($"Wrong cardinal {mec.cardinal} for MechanismMove");
                        break;
                    }
                }
            }
        }

        SetupAdjacentLights(null, 0.0f, Color.red);
    }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        if (instance == null)
        {
            instance = this;
            Debug.Log($"[GameMgr] not initialized ! {instance}.");
        }

        if (Input.GetKeyUp(KeyCode.Backspace))
        {
            //Cleanup();
            //InitializeNewGame(0);
            InitializeNewGame(System.Environment.TickCount);
        }

        OneCellClass current = GetCurrentCell();

        if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            MovePlayerNorth();
        }
        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            MovePlayerSouth();
        }
        if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            MovePlayerEast();
        }
        if (Input.GetKeyUp(KeyCode.LeftArrow))
        {
            MovePlayerWest();
        }
        if (Input.GetKey(KeyCode.Keypad6))
        {
            current.MechanismEast.m_forceActionning = true;
        }
        else
        {
            current.MechanismEast.m_forceActionning = false;
        }
        if (Input.GetKey(KeyCode.Keypad4))
        {
            current.MechanismWest.m_forceActionning = true;
        }
        else
        {
            current.MechanismWest.m_forceActionning = false;
        }
        if (Input.GetKey(KeyCode.Keypad8))
        {
            //MoveColumn(true);
            //current.MechanismNorth.TriggerAction();
            current.MechanismNorth.m_forceActionning = true;
        }
        else
        {
            current.MechanismNorth.m_forceActionning = false;
        }
        if (Input.GetKey(KeyCode.Keypad2))
        {
            current.MechanismSouth.m_forceActionning = true;
        }
        else
        {
            current.MechanismSouth.m_forceActionning = false;
        }

        GameObject directions = m_basicCanvas.transform.GetChild(1).gameObject;

        directions.GetComponent <TextMeshProUGUI>().text = $"Counter\n {Time.fixedTime - current.enterTime}s";

        //*
        if (m_CentreModels.m_light_N.range < 5.0f)
        {
            m_CentreModels.m_light_N.range += Time.deltaTime * 2.0f;
            m_CentreModels.m_light_E.range += Time.deltaTime * 2.0f;
            m_CentreModels.m_light_S.range += Time.deltaTime * 2.0f;
            m_CentreModels.m_light_W.range += Time.deltaTime * 2.0f;
        }
        //*/


        if (Input.GetKeyUp(KeyCode.Z))
        {
            ScanTriggerAction(CardinalPoint.North);
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            ScanTriggerAction(CardinalPoint.East);
        }
        if (Input.GetKeyUp(KeyCode.S))
        {
            ScanTriggerAction(CardinalPoint.South);
        }
        if (Input.GetKeyUp(KeyCode.Q))
        {
            ScanTriggerAction(CardinalPoint.West);
        }
    }
Esempio n. 13
0
    // Start a new fresh game
    void InitializeNewGame(int gameSeed)
    {
        instance  = this;
        gameState = GameStates.Starting;

        startingSeed = gameSeed;
        Random.InitState(startingSeed);

        int firstRandom = (int)(Random.value * 100.0f);

        startingTime = Time.fixedTime;
        Debug.Log($"[GameMgr][{startingTime}] new game initialized with seed {startingSeed}, first random {firstRandom}/19.");

        playerCellId = 12;           // replace the player in the middle

        int        reserveExit = 24; // make sure we'll always have a valid exit
        List <int> deadly      = new List <int>(deadlyCellNb);

        while (deadly.Count < deadlyCellNb)
        {
            int id = (int)(Random.value * 24.0f);
            if ((deadly.Contains(id)) || (id == 12) || (id == reserveExit))
            {
                continue;
            }

            deadly.Add(id);
        }
        string toto = "";

        foreach (int id in deadly)
        {
            toto += id.ToString() + " ";
        }
        Debug.Log($"[GameMgr] deadly {toto}");


        List <int> effectCells = new List <int>(effectCellNb);

        while (effectCells.Count < effectCellNb)
        {
            int id = (int)(Random.value * 24.0f);
            if ((id == 12) || deadly.Contains(id) || effectCells.Contains(id) || (id == reserveExit))
            {
                continue;
            }

            effectCells.Add(id);
        }

        toto = "";
        foreach (int id in effectCells)
        {
            toto += id.ToString() + " ";
        }
        Debug.Log($"[GameMgr] effectCells {toto}");


        // Init a board
        bool exitChosen = false;
        int  exitCount  = 0;

        if (allCells == null)
        {
            allCells = new List <OneCellClass>(25);
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                OneCellClass cell = null;
                int          id   = i * 5 + j;
                if (allCells.Count == 25)
                {
                    cell          = allCells[id];
                    lookupTab[id] = id;
                }
                else
                {
                    cell        = Instantiate <OneCellClass>(cellClassPrefab);
                    cell.cellId = id;
                    allCells.Add(cell);
                    lookupTab.Add(id);
                }
                cell.name = "Cell_" + id;
                float z = i;
                float x = j;
                cell.m_MiniGameTranslation = new Vector3(x * 0.1f, 0.0f, z * -0.1f) + transform.position;
                float aRndNb = Random.value;

                if ((i == 2) && (j == 2))
                {
                    cell.InitCell(CellTypes.Start, 0, aRndNb);
                    playerSphere.transform.position = cell.SmallCell.transform.position + new Vector3(0.0f, 0.1f, 0.0f);
                    continue;
                }

                // Choose deadly ones
                if (deadly.Contains(id))
                {
                    int index = deadly.IndexOf(id);
                    cell.InitCell(CellTypes.Deadly, index, aRndNb);
                    continue;
                }

                // Choose effect ones
                if (effectCells.Contains(id))
                {
                    int index = effectCells.IndexOf(id);
                    cell.InitCell(CellTypes.Effect, index, aRndNb);
                    continue;
                }

                // Choose an exit
                if (!exitChosen)
                {
                    if ((i == 0) || (j == 0) || (i == 4) || (j == 4) || ((i != 2) && (j != 2)))
                    {
                        exitCount++;
                        if ((exitCount >= (int)(aRndNb * 20.0f)) || (id == 24))
                        {
                            cell.InitCell(CellTypes.Exit, 0, aRndNb);
                            exitChosen = true;
                            continue;
                        }
                    }
                }

                cell.InitCell(CellTypes.Safe, 0, aRndNb);
            }
        }

        //--- show models ---
        if (m_CentreModels.m_EntryCell == null)
        {
            m_CentreModels.m_EntryCell = GameObject.Instantiate(m_MiddleCell);
            m_CentreModels.m_EntryCell.transform.SetParent(m_CentreModels.transform);
            m_CentreModels.m_EntryCell.SetActive(true);
            m_CentreModels.m_GenCellA = GameObject.Instantiate(m_GenCellA);
            m_CentreModels.m_GenCellA.transform.SetParent(m_CentreModels.transform);
            m_CentreModels.m_GenCellA.name = "GenACentre Model";
            //Debug.Log($"[MgrInit] Awake. {m_CentreModels.m_GenCellA.name}\\{m_CentreModels.m_GenCellA.transform.parent.name} Centre");
            m_CentreModels.m_ExitCell = GameObject.Instantiate(m_ExitModel);
            m_CentreModels.m_ExitCell.transform.SetParent(m_CentreModels.transform);

            m_NorthModels.m_GenCellA = GameObject.Instantiate(m_GenCellA);
            m_NorthModels.m_GenCellA.SetActive(true);
            m_NorthModels.m_GenCellA.transform.SetParent(m_NorthModels.transform);
            m_NorthModels.m_GenCellA.name = "GenANorth Model";
            //Debug.Log($"[MgrInit] Awake. {m_NorthModels.m_GenCellA.name}\\{m_NorthModels.m_GenCellA.transform.parent.name} m_NorthModels");
            m_NorthModels.m_ExitCell = GameObject.Instantiate(m_ExitModel);
            m_NorthModels.m_ExitCell.transform.SetParent(m_NorthModels.transform);
            m_NorthModels.m_EntryCell = GameObject.Instantiate(m_MiddleCell);
            m_NorthModels.m_EntryCell.transform.SetParent(m_NorthModels.transform);
            m_NorthModels.transform.position = new Vector3(0.0f, 0.0f, 2.9f);

            m_EastModels.m_GenCellA = GameObject.Instantiate(m_GenCellA);
            m_EastModels.m_GenCellA.SetActive(true);
            m_EastModels.m_GenCellA.transform.SetParent(m_EastModels.transform);
            m_EastModels.m_GenCellA.name = "GenAEast Model";
            //Debug.Log($"[MgrInit] Awake. {m_EastModels.m_GenCellA.name}\\{m_EastModels.m_GenCellA.transform.parent.name} m_EastModels");
            m_EastModels.m_EntryCell = GameObject.Instantiate(m_MiddleCell);
            m_EastModels.m_EntryCell.transform.SetParent(m_EastModels.transform);
            m_EastModels.m_ExitCell = GameObject.Instantiate(m_ExitModel);
            m_EastModels.m_ExitCell.transform.SetParent(m_EastModels.transform);
            m_EastModels.transform.position = new Vector3(2.9f, 0.0f, 0.0f);

            m_SouthModels.m_GenCellA = GameObject.Instantiate(m_GenCellA);
            m_SouthModels.m_GenCellA.SetActive(true);
            m_SouthModels.m_GenCellA.transform.SetParent(m_SouthModels.transform);
            m_SouthModels.m_GenCellA.name = "GenASouth Model";
            //Debug.Log($"[MgrInit] Awake. {m_SouthModels.m_GenCellA.name}\\{m_SouthModels.m_GenCellA.transform.parent.name} m_SouthModels");
            m_SouthModels.m_EntryCell = GameObject.Instantiate(m_MiddleCell);
            m_SouthModels.m_EntryCell.transform.SetParent(m_SouthModels.transform);
            m_SouthModels.m_ExitCell = GameObject.Instantiate(m_ExitModel);
            m_SouthModels.m_ExitCell.transform.SetParent(m_SouthModels.transform);
            m_SouthModels.transform.position = new Vector3(0.0f, 0.0f, -2.9f);

            m_WestModels.m_GenCellA = GameObject.Instantiate(m_GenCellA);
            m_WestModels.m_GenCellA.SetActive(true);
            m_WestModels.m_GenCellA.transform.SetParent(m_WestModels.transform);
            m_WestModels.m_GenCellA.name = "GenAWest Model";
            //Debug.Log($"[MgrInit] Awake. {m_WestModels.m_GenCellA.name}\\{m_WestModels.m_GenCellA.transform.parent.name} m_WestModels");
            m_WestModels.m_EntryCell = GameObject.Instantiate(m_MiddleCell);
            m_WestModels.m_EntryCell.transform.SetParent(m_WestModels.transform);
            m_WestModels.m_ExitCell = GameObject.Instantiate(m_ExitModel);
            m_WestModels.m_ExitCell.transform.SetParent(m_WestModels.transform);
            m_WestModels.transform.position = new Vector3(-2.9f, 0.0f, 0.0f);
        }
        //--- show models ---

        //--- set lighting ---
        float light_range  = 1.0f;
        Color light_colour = new Color(1.0f, 1.0f, 0.9f, 1.0f);

        SetupLights(m_CentreModels, light_range, light_colour);
        light_colour = Color.red;
        SetupLights(m_NorthModels, light_range, light_colour);
        SetupLights(m_EastModels, light_range, light_colour);
        SetupLights(m_SouthModels, light_range, light_colour);
        SetupLights(m_WestModels, light_range, light_colour);
        //--- set lighting ---

        UpdateCellsModels();
        gameState = GameStates.Running;
        OneCellClass current = GetCurrentCell();

        current.OnPlayerEnter();
    }
Esempio n. 14
0
    // Return the cell the player is in
    OneCellClass GetCurrentCell()
    {
        OneCellClass current = allCells[lookupTab[playerCellId]];

        return(current);
    }