// Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 clicked = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            clicked.z = 0;
            Vector3Int coord = myGrid.LocalToCell(clicked);

            //WHEN THE PLAYER CLICKS ON A STARTING TILE
            if (startTileDict.ContainsKey(coord))
            {
                if (currentTile)
                {
                    //SWITCH
                    currentTile.SwitchUnit(startTileDict[coord]);
                    currentTile = null;
                }
                else
                {
                    currentTile = startTileDict[coord];
                }
            }
        }
    }
示例#2
0
    void Start()
    {
        currGameBoardPlayer = (int)Sabotage.Enums.Player.ONE;				// Player One starts off the game.
        activePlayer 	    = (int)Sabotage.Enums.PlayerType.GAMEBOARD;	// The GameBoard Player starts playing first.
        scoreManagerScript  = FindObjectOfType<ScoreManager>();

        startTileGameObject = GameObject.Find("Start Tile");
        startTileScript     = startTileGameObject.GetComponent<StartTile>();

        playerGameObject    = (GameObject)Resources.Load("Prefabs/Player");

        Vector3 playerSpawnLocation   = startTileGameObject.transform.position + new Vector3(0, 0, -0.5f);
        GameObject instantiatedPlayer = (GameObject)Instantiate(playerGameObject,
                                                                playerSpawnLocation,
                                                                startTileGameObject.transform.rotation);

        instantiatedPlayer.transform.localScale = new Vector3(.5f, .5f, .5f);

        playerGameObject = instantiatedPlayer.gameObject;
        playerGameObject.AddComponent<GameBoardPlayer>();
        playerGameObject.AddComponent<MouseMovement>();
        playerGameObject.GetComponent<BoxCollider>().isTrigger = true;
        playerGameObject.AddComponent<Rigidbody>().useGravity = false;

        playerOneGameBoardInventory = new ArrayList();
        playerOneGodInventory		= new ArrayList();
        playerTwoGameBoardInventory = new ArrayList();
        playerTwoGodInventory		= new ArrayList();

        maxGameBoardItems = 5;
        maxGodItems = 10;
    }
示例#3
0
 public void ReBuild(int MaxLineNumber, int MaxWidth, int Length, int StartLevel)
 {
     /*瞎写的路线生成,估计还得改*/
     for (int i = 0; i < MaxLineNumber; i++)
     {
         //重复i次生成路线
         Tile LastTile = null;
         for (int j = 0; j < Length; j++)
         {
             Tile next;
             if (j == 0)
             {
                 //第零层固定位置生成起点
                 int y = MaxWidth / 2;
                 next = Get(StartLevel, y);
                 if (next == null)
                 {
                     next = new StartTile()
                     {
                         X = StartLevel, Y = y
                     }
                 }
                 ;
                 NowTile = next;
             }
             else if (j == 1)
             {
                 //第一层的位置是完全随机的
                 //第一次一定是小怪
                 int y = RandomUtil.MapRandomSeed.Next(0, MaxWidth);
                 next = Get(StartLevel + 1, y);
                 if (next == null)
                 {
                     next = new BattleTile()
                     {
                         X = StartLevel + 1, Y = y
                     }
                 }
                 ;
             }
             else if (j == Length - 1)
             {
                 //最后一层固定位置生成boss
                 int y = MaxWidth / 2;
                 next = Get(StartLevel + j, y);
                 if (next == null)
                 {
                     next = new BossTile()
                     {
                         X = StartLevel + j, Y = y
                     }
                 }
                 ;
             }
             else
             {
                 //中间层
                 List <int> waychoose = new List <int>()
                 {
                     -1, 0, 1
                 };
                 if (LastTile.Y == 0)
                 {
                     waychoose.Remove(-1);
                 }
                 else if (LastTile.Y == MaxWidth - 1)
                 {
                     waychoose.Remove(1);
                 }
                 Tile midNext = Get(StartLevel + j, LastTile.Y);
                 if (midNext != null)
                 {
                     foreach (Tile t in midNext.Pres)
                     {
                         if (t.Y == midNext.Y + 1)
                         {
                             waychoose.Remove(1);
                         }
                         else if (t.Y == midNext.Y - 1)
                         {
                             waychoose.Remove(-1);
                         }
                     }
                 }
                 int NextY = LastTile.Y + waychoose[RandomUtil.MapRandomSeed.Next(0, waychoose.Count)];
                 next = Get(StartLevel + j, NextY);
                 //if (next == null)
                 if (j == Length / 2)
                 {
                     next = Get(StartLevel + j, NextY);
                     if (next == null)
                     {
                         next = new TreasureTile()
                         {
                             X = StartLevel + j, Y = NextY
                         }
                     }
                     ;
                 }
                 else
                 {
                     next = CreatRandom(LastTile.Type, next, StartLevel + j); //new BattleTile() { X = StartLevel + j, Y = NextY };
                 }
                 next.X = StartLevel + j;
                 next.Y = NextY;
             }
             if (j != 0)
             {
                 LastTile.Nexts.Add(next);
             }
             next.Pres.Add(LastTile);
             tiles.Add(next);
             LastTile = next;
         }
     }
 }
 public override void Escape()
 {
     currentTile = null;
     BaseManager.instance.CancelButton();
 }
示例#5
0
    private void LoadLevel(int levelIndex)
    {
        _currentLevelDesignIndex = levelIndex;

        ClearExistingLevel();

        LevelDesign currentLevel = _levelDesigns[_currentLevelDesignIndex];

        //set camera position and size
        Camera.main.transform.position = currentLevel.CameraPos;
        Camera.main.orthographicSize   = currentLevel.CameraSize;
        _currentLevelTimeLimit         = currentLevel.LevelTimeLimit;
        UpdateTimeLimitText();
        ApplyMoveLimitVisualEffects(Color.white, Color.black);

        //set current level tiles
        _currentLevelTiles = new Tile[currentLevel.LevelWidth, currentLevel.LevelHeight];

        for (int x = 0, coordX = 0; x < currentLevel.LevelWidth; ++x, ++coordX)
        {
            for (int y = 0, coordY = currentLevel.LevelHeight - 1; y < currentLevel.LevelHeight; ++y, --coordY)
            {
                GameObject go;
                Vector3    coordsVec = new Vector3(coordX, coordY, 0);
                switch (currentLevel.LevelLayout[x, y])
                {
                case 0:
                    //no tile, but we might need something later on
                    break;

                case 1:
                    //empty tile
                    go = Instantiate(emptyTilePrefabs[Random.Range(0, emptyTilePrefabs.Length)], coordsVec, Quaternion.identity) as GameObject;
                    go.transform.Rotate(new Vector3(0, 0, Random.Range(0, 4) * 90));
                    _currentLevelTiles[coordX, coordY] = go.GetComponent <Tile>();
                    _currentLevelTiles[coordX, coordY].SetTilePosition(new Vector2Int(coordX, coordY));
                    _currentLevelGameObjects.Add(go);
                    break;

                case 2:
                    //start tile
                    go = Instantiate(startTilePrefab, coordsVec, Quaternion.identity) as GameObject;
                    go.transform.Rotate(new Vector3(0, 0, Random.Range(0, 4) * 90));
                    StartTile startTile = go.GetComponent <StartTile>();
                    _startTiles.Add(startTile);
                    _currentLevelTiles[coordX, coordY] = startTile;
                    _currentLevelTiles[coordX, coordY].SetTilePosition(new Vector2Int(coordX, coordY));
                    _currentLevelGameObjects.Add(go);
                    break;

                case 3:
                    //goal tile
                    AddLevelTileToLists(goalTilePrefab, coordX, coordY, coordsVec, true);
                    break;

                case 4:
                    //straight pipe
                    AddLevelTileToLists(straightPipeTilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 5:
                    //str2-pipe
                    AddLevelTileToLists(straightPipe2TilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 6:
                    //l-pipe
                    AddLevelTileToLists(lPipeTilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 7:
                    //l-pipe90
                    AddLevelTileToLists(lPipe90TilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 8:
                    //r-pipe
                    AddLevelTileToLists(rPipeTilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 9:
                    //r-pipe90
                    AddLevelTileToLists(rPipe90TilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 10:
                    //bomb
                    AddLevelTileToLists(bombTilePrefab, coordX, coordY, coordsVec, false);
                    break;

                case 11:
                    //timebonus
                    AddLevelTileToLists(timeBonusTilePrefab, coordX, coordY, coordsVec, false);
                    break;

                default:
                    throw new System.NotImplementedException();
                }
            }
        }
    }