コード例 #1
0
    void FacePlayer()
    {
        Vector2 dif = GameManager.Instance.Player.transform.position - transform.position;

        forward = dif.normalized;
        myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(dif));
    }
コード例 #2
0
 void Dash()
 {
     state = ElementalState.Dash;
     trailDropTimer.Start();
     forward = Vector2.one.Rotate(Random.Range(0, 8) * 45);
     myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(forward));
 }
コード例 #3
0
        public void DirectionOpposite()
        {
            Direction myDirection = Direction.CW;

            Assert.AreEqual(Direction.CCW, DirectionHandler.getOpposite(myDirection));
            myDirection = Direction.CCW;
            Assert.AreEqual(Direction.CW, DirectionHandler.getOpposite(myDirection));
        }
コード例 #4
0
    void ConnectRooms(Room one, Room two, bool onMainPath = true)
    {
        Directions         roomDirection = DirectionHandler.GetClosestDirection(two.DungeonPosition - one.DungeonPosition);
        RoomConnectionInfo rci           = new RoomConnectionInfo(roomDirection, onMainPath);

        one.AddConnection(rci);
        rci = new RoomConnectionInfo(DirectionHandler.GetOppositeDirection(roomDirection), true);
        two.AddConnection(rci);
    }
コード例 #5
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Wall"))
     {
         Vector2 fwd = -forward;
         fwd     = fwd.Rotate(Random.Range(-2, 3) * 45);
         forward = fwd;
         myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(forward));
     }
 }
コード例 #6
0
        public void TestDirection()
        {

            Map map = new Map(5, 5);
            Rover rover = new Rover(map, new Coordinate(1, 2), Directions.north);


            var dHandler = DirectionHandler.getInstance();
            
            var nextDirection = (dHandler as DirectionHandler).GetNewDirection(Directions.north,"L");
            Assert.True(nextDirection == Directions.east, "Direction North + Left is "+nextDirection);

            nextDirection = (dHandler as DirectionHandler).GetNewDirection(Directions.south, "L");
            Assert.True(nextDirection == Directions.west, "Direction South + Left is " + nextDirection);


        }
コード例 #7
0
    List <Room> GetPossibleNeighbors(Room room)
    {
        List <Room> possibleDirections = new List <Room>();

        for (int i = 0; i < 4; i++)
        {
            Vector2Int newPos = room.DungeonPosition + DirectionHandler.ConvertDirectionToVector2Int((Directions)i);

            if (IsRoomAt(newPos))
            {
                Room newRoom = GetRoomAt(newPos);
                if (newRoom.Type == RoomTypes.Unassigned)
                {
                    possibleDirections.Add(newRoom);
                }
            }
        }

        return(possibleDirections);
    }
コード例 #8
0
    private void Awake()
    {
        myAnimator = GetComponent <Animator>();
        moveTimer  = new Timer(moveTime);

        moveTimer.OnComplete.AddListener(() =>
        {
            FacePlayer();
            travelDirection = Vector3.zero;
            pauseTimer.Start();
        });

        pauseTimer = new Timer(pauseTime);
        pauseTimer.OnComplete.AddListener(() =>
        {
            FacePlayer();
            FireProjectile();

            moveStyle = (MovementStyle)(Random.Range(1, 3));

            if (moveStyle == MovementStyle.Rotate)
            {
                rotationDirection = Random.Range(0, 1) * 2 - 1;
                travelDirection   = Vector2.down.RotateDeg(Random.Range(-4, 3) * 45);
                myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(travelDirection));
            }
            else
            {
                travelDirection = Vector2.down.RotateDeg(Random.Range(0, 4) * 90);
                myAnimator.SetInteger("Direction", (int)DirectionHandler.GetClosestDirection(travelDirection));
            }
            moveTimer.Start();
        });


        moveStyle = MovementStyle.Rotate;
    }
コード例 #9
0
 protected void ChooseRandomDirection()
 {
     Forward = DirectionHandler.ConvertDirectionToVector3((Directions)(Random.Range(0, 4)));
 }
コード例 #10
0
 private void Start() => directionHandler = GetComponent <DirectionHandler>();
コード例 #11
0
ファイル: Room.cs プロジェクト: jefferydkelly/MementoMori
    public void Generate(Vector2Int roomSize, RoomTileset tiles)
    {
        size    = roomSize;
        tileset = tiles;

        float halfWidth  = (size.x - 1) * 1.5f;
        float halfHeight = (size.y - 1) * 1.5f;

        topWall = new GameObject("Top Wall");
        topWall.transform.SetParent(transform);
        topWall.transform.localPosition = new Vector3(0, halfHeight + 2.5f);

        bottomWall = new GameObject("Bottom Wall");
        bottomWall.transform.SetParent(transform);
        bottomWall.transform.localPosition = new Vector3(0, -(halfHeight + 2.5f));

        for (int i = 0; i < size.x; i++)
        {
            GameObject wally = Instantiate(tileset.topWall);
            wally.transform.SetParent(topWall.transform);
            wally.transform.localPosition = Vector3.right * ((i * 3) - halfWidth);
            if (i == size.x / 2)
            {
                topDoorSection = wally;
            }

            wally = Instantiate(tileset.bottomWall);
            wally.transform.SetParent(bottomWall.transform);
            wally.transform.localPosition = Vector3.right * ((i * 3) - halfWidth);

            if (i == size.x / 2)
            {
                bottomDoorSection = wally;
            }
        }

        leftWall = new GameObject("Left Wall");
        leftWall.transform.SetParent(transform);
        leftWall.transform.localPosition = new Vector3(-halfWidth - 2.5f, 0);

        rightWall = new GameObject("Right Wall");
        rightWall.transform.SetParent(transform);
        rightWall.transform.localPosition = new Vector3(halfWidth + 2.5f, 0);;

        for (int i = 0; i < size.y; i++)
        {
            GameObject wally = Instantiate(tileset.leftWall);
            wally.transform.SetParent(leftWall.transform);
            wally.transform.localPosition = Vector3.up * ((i * 3) - halfHeight);

            if (i == size.y / 2)
            {
                leftDoorSection = wally;
            }


            wally = Instantiate(tileset.rightWall);
            wally.transform.SetParent(rightWall.transform);
            wally.transform.localPosition = Vector3.up * ((i * 3) - halfHeight);

            if (i == size.y / 2)
            {
                rightDoorSection = wally;
            }
        }

        GameObject corner = Instantiate(tileset.topLeftCorner);

        corner.transform.SetParent(transform);
        corner.transform.localPosition = new Vector3(-halfWidth - 2.5f, halfHeight + 2.5f);

        corner = Instantiate(tileset.topRightCorner);
        corner.transform.SetParent(transform);
        corner.transform.localPosition = new Vector3(halfWidth + 2.5f, halfHeight + 2.5f);

        corner = Instantiate(tileset.botLeftCorner);
        corner.transform.SetParent(transform);
        corner.transform.localPosition = new Vector3(-halfWidth - 2.5f, -(halfHeight + 2.5f));

        corner = Instantiate(tileset.botRightCorner);
        corner.transform.SetParent(transform);
        corner.transform.localPosition = new Vector3((halfWidth + 2.5f), -(halfHeight + 2.5f));

        GameObject floor = new GameObject("Floor");

        floor.transform.SetParent(transform);
        floor.transform.localPosition = Vector3.zero;

        GameObject[,] myTiles = new GameObject[size.x, size.y];
        for (int x = 0; x < size.x; x++)
        {
            for (int y = 0; y < size.y; y++)
            {
                GameObject tile = Instantiate(tileset.floorTile);
                tile.transform.SetParent(floor.transform);
                tile.transform.localPosition = new Vector3(x * 3 - halfWidth, y * 3 - halfHeight);
                myTiles[x, y] = tile;
            }
        }



        if (Type == RoomTypes.Boss)
        {
            name = "Boss Room";

            roomLoot = tileset.heartContainer;
            GameObject boss = Instantiate(tileset.bosses.RandomElement());
            boss.transform.SetParent(transform);
            boss.transform.localPosition = new Vector3(0, 0, -2);

            boss.GetComponent <DamageTaker>().OnHealthChanged.AddListener((int hp) =>
            {
                if (hp <= 0)
                {
                    OpenDoors();
                    monsters.Remove(boss);
                }
            });

            monsters = new List <GameObject>()
            {
                boss
            };
            OnEnter.AddListener(RevealMonsters);
            OnExit.AddListener(HideMonsters);
            HideMonsters();
        }
        else if (Type == RoomTypes.Healing)
        {
            name = "Healing Spring";
            GameObject spring = null;//GameManager.Instance.ThePool.GetPooledObject(tileset.spring.name);
            spring.transform.SetParent(floor.transform);
            spring.transform.localPosition = Vector3.zero.SetZ(-1);
        }
        else if (Type == RoomTypes.Shop)
        {
            name = "Shop";
            GameObject carpet = Instantiate(tileset.storeCarpet);
            carpet.transform.SetParent(floor.transform);
            carpet.transform.localPosition = Vector3.zero.SetZ(-1);


            carpet = Instantiate(tileset.shopkeep);
            carpet.transform.SetParent(floor.transform);
            carpet.transform.localPosition = Vector3.zero.SetZ(-2);
            List <ItemInfo> items = DungeonGenerator.Instance.StoreItems;

            for (int i = 0; i < 4; i++)
            {
                ShopCounter counter = Instantiate(tileset.storeCounter).GetComponent <ShopCounter>();
                counter.transform.SetParent(floor.transform);
                counter.transform.localPosition = (DirectionHandler.ConvertDirectionToVector3((Directions)i) * 2.5f).SetZ(-1);
                if (i % 2 == 1)
                {
                    counter.transform.localRotation = Quaternion.AngleAxis(90, Vector3.forward);
                }

                counter.SetItem(items.RandomElement());
            }
        }
        else if (Type == RoomTypes.Miniboss)
        {
            name = "Miniboss";

            GameObject boss = Instantiate(tileset.minibosses.RandomElement());
            boss.transform.SetParent(transform);
            boss.transform.localPosition = new Vector3(0, 0, -2);

            TreasureChest chest = Instantiate(tileset.treasureChest).GetComponent <TreasureChest>();
            chest.transform.SetParent(transform);
            chest.transform.localPosition = -Vector3.forward;
            chest.contents = DungeonGenerator.Instance.Treasures.RandomElement();
            chest.gameObject.SetActive(false);
            boss.GetComponent <DamageTaker>().OnHealthChanged.AddListener((int hp) =>
            {
                if (hp <= 0)
                {
                    //Create treasure chest and put treasure inside of it
                    monsters.Remove(boss);
                    chest.gameObject.SetActive(true);

                    foreach (ShortLivedObject slo in GetComponentsInChildren <ShortLivedObject>())
                    {
                        Destroy(slo.gameObject);
                    }

                    OpenDoors();
                    OnEnter.RemoveListener(RevealMonsters);
                }
            });

            monsters = new List <GameObject>()
            {
                boss
            };
            OnEnter.AddListener(RevealMonsters);
            OnExit.AddListener(HideMonsters);
            HideMonsters();
        }
        else if (Type == RoomTypes.Basic)
        {
            int randy = Random.Range(0, 5);

            if (randy == 4)
            {
                Type = RoomTypes.Goddess;
                string color = "Red";
                randy = Random.Range(0, 3);
                if (randy == 1)
                {
                    color = "Green";
                }
                else
                {
                    color = "Blue";
                }
                GameObject coinPrefab = DatabaseManager.Instance.GetGameObjectFromDataBase("Items", "Epic", "Goddess Coins", color);
                GameObject coin       = Instantiate(coinPrefab);
                coin.transform.SetParent(transform);
                coin.transform.localPosition = -Vector3.forward;
                name = color + "Goddess Room";
                OnEnter.AddListener(CloseDoors);
            }
            else if (randy >= 2)
            {
                //Spawn Enemies
                Type = RoomTypes.Encounter;
                SpawnMonsters();
                roomLoot = (Random.value >= 0.5f) ? DungeonGenerator.Instance.RoomLoot.RandomElement().item : null;
                //HideMonsters();
            }
            else
            {
                OnEnter.AddListener(OpenDoors);

                int wetness = Random.Range(0, 5);
                if (wetness == 3)
                {
                    for (int x = size.x / 2 - 1; x <= size.x / 2 + 1; x++)
                    {
                        for (int y = size.y / 2 - 1; y <= size.y / 2 + 1; y++)
                        {
                            Destroy(myTiles[x, y]);
                            GameObject tile = Instantiate(tileset.waterTile);
                            tile.transform.SetParent(floor.transform);
                            tile.transform.localPosition = new Vector3(x * 3 - halfWidth, y * 3 - halfHeight);
                            myTiles[x, y] = tile;
                        }
                    }
                }
                else if (wetness > 3)
                {
                    for (int y = 0; y < size.y; y++)
                    {
                        if (y != size.y / 2 || !HasDoorOn(Directions.Left))
                        {
                            Destroy(myTiles[0, y]);
                            GameObject tile = Instantiate(tileset.waterTile);
                            tile.transform.SetParent(floor.transform);
                            tile.transform.localPosition = new Vector3(-halfWidth, y * 3 - halfHeight);
                            myTiles[0, y] = tile;
                        }
                        if (y != size.y / 2 || !HasDoorOn(Directions.Right))
                        {
                            Destroy(myTiles[size.x - 1, y]);
                            GameObject tile = Instantiate(tileset.waterTile);
                            tile.transform.SetParent(floor.transform);
                            tile.transform.localPosition = new Vector3((size.x - 1) * 3 - halfWidth, y * 3 - halfHeight);
                            myTiles[size.x - 1, y]       = tile;
                        }
                    }

                    for (int x = 0; x < size.x; x++)
                    {
                        if (x != size.x / 2 || !HasDoorOn(Directions.Up))
                        {
                            Destroy(myTiles[x, 0]);
                            GameObject tile = Instantiate(tileset.waterTile);
                            tile.transform.SetParent(floor.transform);
                            tile.transform.localPosition = new Vector3(x * 3 - halfWidth, -halfHeight);
                            myTiles[x, 0] = tile;
                        }
                        if (x != size.x / 2 || !HasDoorOn(Directions.Down))
                        {
                            Destroy(myTiles[x, size.y - 1]);
                            GameObject tile = Instantiate(tileset.waterTile);
                            tile.transform.SetParent(floor.transform);
                            tile.transform.localPosition = new Vector3(x * 3 - halfWidth, (size.y - 1) * 3 - halfHeight);
                            myTiles[x, size.y - 1]       = tile;
                        }
                    }
                }
            }
        }
        else
        {
            OnEnter.AddListener(OpenDoors);
        }

        foreach (RoomConnectionInfo direction in connections)
        {
            AddDoor(direction);
        }
    }
コード例 #12
0
ファイル: Player.cs プロジェクト: IllusiveS/Asteroids
 public void AddDirectionObserver(DirectionHandler observer)
 {
     Controller.OnDirectionChange += observer;
 }
コード例 #13
0
 /// <summary>
 /// Gets the closest direction to the normal of this collision
 /// </summary>
 /// <param name="collision">The collision</param>
 /// <returns>The closest direction to the normal of this collision</returns>
 public static Directions GetClosestDirection(this Collision2D collision)
 {
     return(DirectionHandler.GetClosestDirection(collision.GetContact(0).normal));
 }