private bool ValidatePush(Vector3 v3Direction)
    {
        int index = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition + v3Direction, gameController.GetCurrentLevel().MaxSize);

        return(MMUtils.IsPushableObject(gameController.scenarioObjects[index].GetComponent <ScenarioObject>().tTileType) &&
               gameController.scenarioObjects[index].GetComponent <MovementObject>().bEnableMovement);
    }
    public void RefreshLevelReference(Vector3 v3Direction)
    {
        int        iCurrIndex = MMUtils.MatrixIndexesToListIndex(v3TargetPosition, gameController.GetCurrentLevel().MaxSize);
        int        iPrevIndex = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition, gameController.GetCurrentLevel().MaxSize);
        GameObject goAux      = gameController.scenarioObjects[iCurrIndex];

        gameController.scenarioObjects[iCurrIndex] = gameController.scenarioObjects[iPrevIndex];
        gameController.scenarioObjects[iPrevIndex] = goAux;
    }
 public void SetLevelStatus(string sLevel, int iLevelDim)
 {
     string[] sLevelArray = sLevel.Split(MMConstants.LEVEL_SEPARATOR);
     iLevelStatus = new int[iLevelDim, iLevelDim];
     for (int x = 0; x < iLevelDim; x++)
     {
         for (int z = 0; z < iLevelDim; z++)
         {
             int index = MMUtils.MatrixIndexesToListIndex(x, z, iLevelDim);
             iLevelStatus[x, z] = int.Parse(sLevelArray[index]);
         }
     }
 }
Esempio n. 4
0
    private void BuildLevelTiles(int iTiles)
    {
        tiles = new GameObject[iTiles * iTiles];
        print("building..");
        for (int x = 0; x < iTiles; x++)
        {
            for (int z = 0; z < iTiles; z++)
            {
                GameObject goNewEditorTile = Instantiate(prefEditorTile, new Vector3(x, 0.4f, z), Quaternion.identity);
                goNewEditorTile.transform.SetParent(tContainer);

                int index = MMUtils.MatrixIndexesToListIndex(x, z, iTiles);
                tiles[index] = goNewEditorTile;
            }
        }
    }
    public void Move(Vector3 v3Direction)
    {
        if (bEnableMovement)
        {
            if (bRotateBeforeMove && v3LookDirection != v3Direction)
            {
                v3LookDirection = v3Direction;
                if (v3LookDirection == Vector3.right)
                {
                    this.transform.rotation = Quaternion.Euler(Vector3.up * 180);
                }
                else if (v3LookDirection == Vector3.left)
                {
                    this.transform.rotation = Quaternion.Euler(Vector3.zero);
                }
                else if (v3LookDirection == Vector3.forward)
                {
                    this.transform.rotation = Quaternion.Euler(Vector3.up * 90);
                }
                else if (v3LookDirection == Vector3.back)
                {
                    this.transform.rotation = Quaternion.Euler(Vector3.up * 270);
                }

                qCurrentRotation = this.transform.rotation;
            }
            else
            {
                if (ValidateMove(v3Direction))
                {
                    v3TargetPosition += v3Direction;
                    bfinishedMoving   = false;
                    RefreshLevelReference(v3Direction);
                }

                else if (ValidatePush(v3Direction))
                {
                    int            index          = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition + v3Direction, gameController.GetCurrentLevel().MaxSize);
                    MovementObject mvObjectToMove = gameController.scenarioObjects[index].GetComponent <MovementObject>();
                    if (mvObjectToMove.bEnableMovement)
                    {
                        StartCoroutine(mvObjectToMove.Movequeue(v3Direction));
                    }
                }
            }
        }
    }
    private bool ValidateMove(Vector3 v3Direction)
    {
        int index = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition + v3Direction, gameController.GetCurrentLevel().MaxSize);

        return(MMUtils.IsWalkableObject(gameController.scenarioObjects[index].GetComponent <ScenarioObject>().tTileType) && gameController.scenarioObjects[index].activeInHierarchy);
    }
    protected GameObject GetLookingAtObject(Vector3 v3LookDirection)
    {
        int index = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition + v3LookDirection, gameController.GetCurrentLevel().MaxSize);

        return(gameController.scenarioObjects[index]);
    }
Esempio n. 8
0
    public void GenerateBaseLevel(LevelData curLevel)
    {
        int iObjectPlacementNumber = 0;
        int iObjectMovementNumber  = 0;
        int iObjectColorNumber     = 0;

        string[] sLevelObjects = curLevel.levelBuild.Split(MMConstants.LEVEL_SEPARATOR);
        gameController.scenarioObjects = new GameObject[sLevelObjects.Length];
        for (int x = 0; x < curLevel.MaxSize; x++)
        {
            for (int z = 0; z < curLevel.MaxSize; z++)
            {
                GameObject goNewTile = Instantiate(goTile, new Vector3(x, 0.4f, z), Quaternion.identity);
                goNewTile.transform.SetParent(this.transform);
                int index = MMUtils.MatrixIndexesToListIndex(x, z, curLevel.MaxSize);
                if ((MMEnums.TileType) int.Parse(sLevelObjects[index]) == MMEnums.TileType.NONE)
                {
                    goNewTile.SetActive(false);
                }
                if (index == (curLevel.MaxSize * curLevel.MaxSize) / 2)
                {
                    cameraManager.PlaceCamera(curLevel.MaxSize, goNewTile);
                }
                GameObject goToInstantiate = null;
                switch ((MMEnums.TileType) int.Parse(sLevelObjects[index]))
                {
                case MMEnums.TileType.MIRROR:
                    goToInstantiate = goMirror;
                    break;

                case MMEnums.TileType.LASER:
                    goToInstantiate = goLaser;
                    break;

                case MMEnums.TileType.RECEIVER:
                    goToInstantiate = goReceiver;

                    break;

                case MMEnums.TileType.SPLITTER:
                    goToInstantiate = goSplitter;
                    break;

                case MMEnums.TileType.ROCKS:
                    goToInstantiate = goRocks;
                    break;

                case MMEnums.TileType.CHARACTER:
                    goToInstantiate = goCharacter;
                    break;

                case MMEnums.TileType.MERGER:
                    goToInstantiate = goMerger;
                    break;

                case MMEnums.TileType.BIG_ROCK:
                    goToInstantiate = goBigRock;
                    break;

                case MMEnums.TileType.DUPLICATOR:
                    goToInstantiate = goDuplicator;
                    break;
                }

                if (goToInstantiate != null)
                {
                    GameObject goNewObj = Instantiate(goToInstantiate, new Vector3(x, 1, z) + goToInstantiate.GetComponent <ScenarioObject>().v3Offset, Quaternion.identity);
                    goNewObj.transform.SetParent(this.transform);
                    goNewObj.GetComponent <ScenarioObject>().SetLevelReference(gameController);
                    gameController.scenarioObjects[index] = goNewObj;

                    if (goToInstantiate != goRocks && goToInstantiate != goBigRock)
                    {
                        goNewObj.transform.rotation = Quaternion.Euler(curLevel.objRotation[iObjectPlacementNumber]);
                        goNewObj.name += iObjectPlacementNumber;
                        iObjectPlacementNumber++;
                        if (goToInstantiate == goLaser)
                        {
                            goNewObj.GetComponent <RayLaser>().UpdateRayColor(curLevel.objColor[iObjectColorNumber]);
                            iObjectColorNumber++;
                        }
                        else if (goToInstantiate == goReceiver)
                        {
                            goNewObj.GetComponent <Receiver>().UpdateColorSolution(curLevel.objColor[iObjectColorNumber]);
                            iObjectColorNumber++;
                        }
                    }

                    if (MMUtils.IsPushableObject(goToInstantiate.GetComponent <ScenarioObject>().tTileType))
                    {
                        goNewObj.GetComponent <MovementObject>().bEnableMovement = curLevel.objMovementEnabled[iObjectMovementNumber];
                        iObjectMovementNumber++;
                    }
                }
                else if (!goNewTile.activeInHierarchy)
                {
                    gameController.scenarioObjects[index] = goNewTile;
                }
                else
                {
                    gameController.scenarioObjects[index] = goNewTile;
                }
            }
        }
    }