Esempio n. 1
0
    public void StopMoving()
    {
        targetCoord = curCoord;
        switch (transform.parent.GetComponent <Move>().dir)
        {
        case Direction.Left:
            transform.position = transform.parent.position - Vector3.left;
            break;

        case Direction.Right:
            transform.position = transform.parent.position - Vector3.right;
            break;

        case Direction.Up:
            transform.position = transform.parent.position - Vector3.up;
            break;

        case Direction.Down:
            transform.position = transform.parent.position - Vector3.down;
            break;

        default:
            break;
        }
    }
Esempio n. 2
0
    private LevelCoord GetLastCoord()
    {
        LevelCoord lastCoord = curCoord;

        switch (dir)
        {
        case Direction.Left:
            lastCoord = new LevelCoord(curCoord.x + 1, curCoord.y);
            break;

        case Direction.Right:
            lastCoord = new LevelCoord(curCoord.x - 1, curCoord.y);
            break;

        case Direction.Up:
            lastCoord = new LevelCoord(curCoord.x, curCoord.y - 1);
            break;

        case Direction.Down:
            lastCoord = new LevelCoord(curCoord.x, curCoord.y + 1);
            break;

        default:
            break;
        }
        int grid = LevelData.instance.GridMap[lastCoord.y, lastCoord.x];

        return((LevelData.instance.IsEmpty(grid) || (LevelData.instance.IsOccupiedByPlayer(grid) && grid == -id - 2)) ? lastCoord : curCoord);
    }
    // Use this for initialization
    //   public void StartGame () {
    //	for(int i = 0; i < 8; i++)
    //       {
    //           List<LevelCoord> tmpset = LevelData.instance.GetLootSpawnPoint(i);
    //           if (tmpset.Count < itemNums[i])
    //           {
    //               Debug.Log("Error: Uncompatible count for id: " + i + 1);
    //               break;
    //           }
    //           for (int j = itemNums[i]; j < tmpset.Count; j++)
    //           {
    //               int k = Random.Range(0, j - 1);
    //               if (k < itemNums[i])
    //               {
    //                   LevelCoord tmpCoord = tmpset[j];
    //                   tmpset[j] = tmpset[k];
    //                   tmpset[k] = tmpCoord;
    //               }
    //           }
    //           for(int j = 0; j < tmpset.Count; j++)
    //           {
    //               if (j < itemNums[i])
    //               {
    //                   var tmpPrefab = Instantiate(itemPrefabs[i]);
    //                   tmpPrefab.transform.position = LevelData.instance.Coord2WorldPos(tmpset[j]);
    //                   itemPool.Add(tmpPrefab);
    //                   LevelData.instance.OriginMap[tmpset[j].y, tmpset[j].x] = 1;
    //                   LevelData.instance.GridMap[tmpset[j].y, tmpset[j].x] = 1;
    //               }
    //               else
    //               {
    //                   var tmpPrefab = Instantiate(closetPrefab);
    //                   tmpPrefab.transform.position = LevelData.instance.Coord2WorldPos(tmpset[j]);
    //                   itemPool.Add(tmpPrefab);
    //                   LevelData.instance.OriginMap[tmpset[j].y, tmpset[j].x] = -1;
    //                   LevelData.instance.GridMap[tmpset[j].y, tmpset[j].x] = -1;
    //               }
    //           }
    //       }
    //}

    public void StartGame()
    {
        List <LevelCoord> tmpset = LevelData.instance.GetLootSpawnPoint(0);

        if (tmpset.Count < itemNums)
        {
            Debug.Log("Error: Uncompatible count");
            return;
        }
        for (int i = itemNums; i < tmpset.Count; i++)
        {
            int j = Random.Range(0, i - 1);
            if (j < itemNums)
            {
                LevelCoord tmpCoord = tmpset[i];
                tmpset[i] = tmpset[j];
                tmpset[j] = tmpCoord;
            }
        }
        for (int i = 0; i < tmpset.Count; i++)
        {
            var tmpPrefab = Instantiate(closetPrefab);
            tmpPrefab.transform.position = LevelData.instance.Coord2WorldPos(tmpset[i]);
            itemPool.Add(tmpPrefab);
            if (i >= itemNums)
            {
                int tmpSurprise = Random.Range((int)GridType.LootSpawn2, (int)GridType.LootSpawn8);
                LevelData.instance.OriginMap[tmpset[i].y, tmpset[i].x] = tmpSurprise;
                LevelData.instance.GridMap[tmpset[i].y, tmpset[i].x]   = tmpSurprise;
            }
        }
    }
 public void ItemPickup(LevelCoord coord, int id)
 {
     for (int i = 0; i < itemPool.Count; i++)
     {
         if (LevelData.instance.WorldPos2Coord(itemPool[i].transform.position) == coord)
         {
             Destroy(itemPool[i]);
             itemPool.RemoveAt(i);
             var tmpPrefab = Instantiate(itemPrefabs[id]);
             tmpPrefab.transform.position = LevelData.instance.Coord2WorldPos(coord);
             LevelData.instance.OriginMap[coord.y, coord.x] = 1;
             break;
         }
     }
 }
Esempio n. 5
0
 // Use this for initialization
 void StartGame()
 {
     if (inputCtrl == null)
     {
         inputCtrl = gameObject.AddComponent <InputController>();
     }
     id                 = gameObject.GetComponent <PlayerController>().id;
     lastTime           = 0;
     dir                = Direction.Stay;
     curCoord           = LevelData.instance.GetPlayerSpawnPoint(id).First();
     transform.position = LevelData.instance.Coord2WorldPos(curCoord);
     LevelData.instance.GridMap[curCoord.y, curCoord.x] = -id - 2;
     //LevelData.instance.OriginMap[curCoord.y, curCoord.x] = -1;
     targetCoord   = curCoord;
     isStart       = true;
     waitTickState = 0;
     Debug.Log("CurrentCoord:" + curCoord.x + " , " + curCoord.y);
     Debug.Log("TargetCoord:" + targetCoord.x + " , " + targetCoord.y);
 }
    public void PickupItem(LevelCoord coord, int itemid)
    {
        if (!hasItem)
        {
            if (itemid == (int)GridType.LootSpawn1)
            {
                if (id == 3)
                {
                    GameManager.instance.MomWin();
                }
                hasItem = true;

                SoundManager.Instance.Play("Effect_GetController");
                switchModel.SetActive(true);
            }
            else
            {
                SoundManager.Instance.Play("Effect_CatchByMom");
            }
            LootItemManager.instance.ItemPickup(coord, itemid - (int)GridType.LootSpawn1);
            //LevelData.instance.OriginMap[coord.y, coord.x] = -1;
        }
    }
Esempio n. 7
0
 public SpawnPoint(int typeId, LevelCoord coord)
 {
     this.typeId = typeId;
     this.coord  = coord;
 }
Esempio n. 8
0
 public Vector3 Coord2WorldPos(LevelCoord coord)
 {
     return(Coord2WorldPos(coord.x, coord.y));
 }
Esempio n. 9
0
 public Vector3 Coord2LocalPos(LevelCoord coord)
 {
     return(Coord2LocalPos(coord.x, coord.y));
 }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        if (isStart)
        {
            if (gameObject.GetComponent <PlayerController>().isAlive)
            {
                if (dir == Direction.Stay)
                {
                    Vector2 inputAxis = new Vector2(GetInputX(), GetInputY());
                    if (inputAxis != Vector2.zero)
                    {
                        dir = Mathf.Abs(GetInputX()) > Mathf.Abs(GetInputY()) ? (GetInputX() > 0 ? Direction.Right : Direction.Left) : (GetInputY() > 0 ? Direction.Up : Direction.Down);
                    }
                }
                else if (waitTickState == 0)
                {
                    Vector2 inputAxis = new Vector2(GetInputX(), GetInputY());
                    if (inputAxis != Vector2.zero)
                    {
                        Direction tmpdir = Mathf.Abs(GetInputX()) > Mathf.Abs(GetInputY()) ? (GetInputX() > 0 ? Direction.Right : Direction.Left) : (GetInputY() > 0 ? Direction.Up : Direction.Down);
                        if (tmpdir == Direction.Down && dir == Direction.Up ||
                            tmpdir == Direction.Up && dir == Direction.Down ||
                            tmpdir == Direction.Left && dir == Direction.Right ||
                            tmpdir == Direction.Right && dir == Direction.Left)
                        {
                            waitTickState = 2;
                        }
                    }
                }
                lastTime += Time.deltaTime;
                if (lastTime > GameManager.instance.ticktime / gameObject.GetComponent <PlayerController>().speedRatio)
                {
                    lastTime -= GameManager.instance.ticktime / gameObject.GetComponent <PlayerController>().speedRatio;
                    Tick();
                }
                curCoord           = LevelData.instance.WorldPos2Coord(transform.position);
                transform.position = Vector3.MoveTowards(transform.position, LevelData.instance.Coord2WorldPos(targetCoord), GameManager.instance.speed * gameObject.GetComponent <PlayerController>().speedRatio *Time.deltaTime);
            }
            else if (!gameObject.GetComponent <PlayerController>().isInBed)
            {
                lastTime += Time.deltaTime;
                if (lastTime > GameManager.instance.ticktime / transform.parent.GetComponent <PlayerController>().speedRatio)
                {
                    lastTime -= GameManager.instance.ticktime / transform.parent.GetComponent <PlayerController>().speedRatio;
                    FollowTick();
                }
                switch (dir)
                {
                case Direction.Left:
                    transform.position = transform.parent.position - Vector3.left;
                    break;

                case Direction.Right:
                    transform.position = transform.parent.position - Vector3.right;
                    break;

                case Direction.Up:
                    transform.position = transform.parent.position - Vector3.up;
                    break;

                case Direction.Down:
                    transform.position = transform.parent.position - Vector3.down;
                    break;

                default:
                    break;
                }
            }
        }
        else
        {
            if (LevelData.instance.isGenerated && !isStart)
            {
                StartGame();
            }
        }
    }
Esempio n. 11
0
    private void Tick()
    {
        if (waitTickState == 2)
        {
            targetCoord = curCoord;
            waitTickState--;
            return;
        }
        if (waitTickState == 1)
        {
            if (dir == Direction.Up)
            {
                dir = Direction.Down;
            }
            else if (dir == Direction.Down)
            {
                dir = Direction.Up;
            }
            else if (dir == Direction.Left)
            {
                dir = Direction.Right;
            }
            else if (dir == Direction.Right)
            {
                dir = Direction.Left;
            }
        }
        if (waitTickState > 0)
        {
            waitTickState--;
        }
        if (dir == Direction.Stay)
        {
            return;
        }
        int grid = LevelData.instance.GridMap[curCoord.y, curCoord.x];

        if (!(LevelData.instance.IsEmpty(grid) || (LevelData.instance.IsOccupiedByPlayer(grid) && grid == -id - 2)))
        {
            Debug.Log(LevelData.instance.GridMap[curCoord.y, curCoord.x]);
            targetCoord = GetLastCoord();
            LevelData.instance.GridMap[targetCoord.y, targetCoord.x] = -id - 2;
            dir = Direction.Stay;
        }
        else
        {
            LevelCoord nextCoord = GetNextCoord();
            grid = LevelData.instance.GridMap[nextCoord.y, nextCoord.x];
            if (!(LevelData.instance.IsEmpty(grid) || (LevelData.instance.IsOccupiedByPlayer(grid) && grid == -id - 2)))
            {
                if (id != 3 && LevelData.instance.IsLootItem(grid))
                {
                    gameObject.GetComponent <PlayerController>().PickupItem(nextCoord, grid);
                    //GameManager.instance.ticktime /= 1.1f;
                    //GameManager.instance.speed *= 1.1f;
                    //Debug.Log("Accelaration" + id);
                }
                else if (id == 3 && LevelData.instance.IsOccupiedByPlayer(grid))
                {
                    gameObject.GetComponent <PlayerController>().KnockoutPlayer(-grid - 2);
                    LevelData.instance.GridMap[nextCoord.y, nextCoord.x] = LevelData.instance.OriginMap[nextCoord.y, nextCoord.x];
                }
                else if (id != 3 && grid == -5)
                {
                    PlayerController[] players = GameObject.FindObjectsOfType <PlayerController>();
                    for (int i = 0; i < players.Length; i++)
                    {
                        if (players[i].id == 3)
                        {
                            players[i].KnockoutPlayer(id);
                        }
                    }
                }
                targetCoord = curCoord;
                dir         = Direction.Stay;
            }
            else
            {
                targetCoord = nextCoord;
                //if (LevelData.instance.IsLootItem(grid))
                //{
                //    gameObject.GetComponent<PlayerController>().PickupItem(targetCoord);
                //}
                LevelData.instance.GridMap[targetCoord.y, targetCoord.x] = -id - 2;
                LevelData.instance.GridMap[curCoord.y, curCoord.x]       = LevelData.instance.OriginMap[curCoord.y, curCoord.x];
            }
            //if (dir == Direction.Stay)
            //    LevelData.instance.GridMap[curCoord.y, curCoord.x] = -id - 2;
            //else
            //    LevelData.instance.GridMap[curCoord.y, curCoord.x] = -1;
        }
    }