//place player ship and get next for select place
    public void PlaceShip()
    {
        if (editCanPlace)
        {
            // select next ship
            var ship = playerFieldData.Ships.Find(x => x.go == editedShip);
            ship.status = PlayerField.shipStatus.Placed;

            var chiPlaced = ship.go.GetComponentsInChildren <MeshRenderer>();

            foreach (MeshRenderer chi in chiPlaced)
            {
                chi.gameObject.transform.localPosition = Vector3Int.FloorToInt(chi.transform.localPosition);
            }

            var newShip = playerFieldData.Ships.Find(x => x.status == PlayerField.shipStatus.Hide);

            if (newShip != null)
            {
                editedShip = newShip.go;
                editedShip.transform.localPosition = new Vector3(11, 0.5f, 0);
            }
            else
            {
                currentMode = GameMode.play;
            }
        }
    }
Example #2
0
    public static void FillNoisySphere(World world, uint id, Vector3 o, float r, FastNoiseLite noise, float noiseScale, uint idVariant, float variantRate)
    {
#if PROFILE
        UnityEngine.Profiling.Profiler.BeginSample("TestTree.FillNoisySphere");
#endif
        var rand = new System.Random();

        Vector3Int min = Vector3Int.FloorToInt(o) - Vector3Int.one * Mathf.CeilToInt(r + noiseScale);
        Vector3Int max = Vector3Int.CeilToInt(o) + Vector3Int.one * Mathf.CeilToInt(r + noiseScale);

        for (int x = min.x; x <= max.x; x++)
        {
            for (int y = min.y; y <= max.y; y++)
            {
                for (int z = min.z; z <= max.z; z++)
                {
                    if ((new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - o).magnitude <= (r + 0.35f + noise.GetNoise(x, y, z) * noiseScale))
                    {
                        if (rand.NextDouble() < variantRate)
                        {
                            world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(idVariant));
                        }
                        else
                        {
                            world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(id));
                        }
                    }
                }
            }
        }

#if PROFILE
        UnityEngine.Profiling.Profiler.EndSample();
#endif
    }
Example #3
0
        private GameObject GetObjectInCell(GridLayout grid, Transform parent, Vector3Int position)
        {
            int childCount;

            GameObject[] sceneChildren = null;
            if (parent == null)
            {
                var scene = SceneManager.GetActiveScene();
                sceneChildren = scene.GetRootGameObjects();
                childCount    = scene.rootCount;
            }
            else
            {
                childCount = parent.childCount;
            }
            var anchorCellOffset = Vector3Int.FloorToInt(m_Anchor);
            var cellSize         = grid.cellSize;

            anchorCellOffset.x = cellSize.x == 0 ? 0 : anchorCellOffset.x;
            anchorCellOffset.y = cellSize.y == 0 ? 0 : anchorCellOffset.y;
            anchorCellOffset.z = cellSize.z == 0 ? 0 : anchorCellOffset.z;

            for (var i = 0; i < childCount; i++)
            {
                var child = sceneChildren == null?parent.GetChild(i) : sceneChildren[i].transform;

                if (position == grid.WorldToCell(child.position) - anchorCellOffset)
                {
                    return(child.gameObject);
                }
            }
            return(null);
        }
        // Creates bricks at the coarsest level for all areas that are overlapped by the pass in volume
        private void Rasterize(Volume volume, List <Brick> outBricks)
        {
            Profiler.BeginSample("Rasterize");
            // Calculate bounding box for volume in refvol space
            var AABB = volume.CalculateAABB();

            // Calculate smallest brick size capable of covering shortest AABB dimension
            float minVolumeSize    = Mathf.Min(AABB.size.x, Mathf.Min(AABB.size.y, AABB.size.z));
            int   brickSubDivLevel = Mathf.Min(Mathf.CeilToInt(Mathf.Log(minVolumeSize, 3)), m_MaxSubdivision);
            int   brickTotalSize   = (int)Mathf.Pow(3, brickSubDivLevel);

            // Extend AABB to have origin that lies on a grid point
            AABB.Encapsulate(new Vector3(
                                 brickTotalSize * Mathf.Floor(AABB.min.x / brickTotalSize),
                                 brickTotalSize * Mathf.Floor(AABB.min.y / brickTotalSize),
                                 brickTotalSize * Mathf.Floor(AABB.min.z / brickTotalSize)));

            // Calculate origin of bricks and how many are needed to cover volume
            Vector3Int origin          = Vector3Int.FloorToInt(AABB.min);
            Vector3    logicalBrickRes = Vector3Int.CeilToInt(AABB.size / brickTotalSize);

            // Cover the volume with bricks
            for (int x = 0; x < logicalBrickRes.x; x++)
            {
                for (int y = 0; y < logicalBrickRes.y; y++)
                {
                    for (int z = 0; z < logicalBrickRes.z; z++)
                    {
                        Vector3Int pos = origin + new Vector3Int(x, y, z) * brickTotalSize;
                        outBricks.Add(new Brick(pos, brickSubDivLevel));
                    }
                }
            }
            Profiler.EndSample();
        }
Example #5
0
    public static void ProcessTile(Vector3 Location, GameObject WhoBy)
    {
        Location.z = 0f;
        Vector3Int worldPosInt = Location.To2Int().To3Int();
        Matrix     matrix      = MatrixManager.AtPoint(worldPosInt, true).Matrix;

        Location = matrix.transform.InverseTransformPoint(Location);
        Vector3Int tilePosition = Vector3Int.FloorToInt(Location);

        var registerTiles = matrix.Get <RegisterTile>(tilePosition, false);

        List <GameObject> _Objects = registerTiles.Select(x => x.gameObject).ToList();

        //include interactable tiles
        var interactableTiles = matrix.GetComponentInParent <InteractableTiles>();

        if (interactableTiles != null)
        {
            _Objects.Add(interactableTiles.gameObject);
        }

        List <Transform> transforms = new List <Transform>();

        foreach (var Object in _Objects)
        {
            transforms.Add(Object.transform);
        }

        ProcessListOnTileTransform(transforms, WhoBy);
    }
Example #6
0
    void Update()
    {
        // Check if unit contained within selection rectangle (Multi-Unit Selection)
        if (inputHandler.IsWithinSelectionBounds(gameObject))
        {
            //Check if cursor is over UI element
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                isSelected = true;
                target     = transform.position;
            }
        }

        // Check if unit is to be selected by user (Single Unit Selection)
        else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.Alpha1))
        {
            Vector3Int mPosWorldI = getCurCursorWorldCoords();
            Vector3Int puPosI     = Vector3Int.FloorToInt(transform.position);
            //Check if cursor is over UI element
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (mPosWorldI.x == puPosI.x && mPosWorldI.y == puPosI.y)
                {
                    isSelected = true;
                }
            }
        }

        // Update unit's target position based on player's desired movement position
        MoveUnit();

        // Update unit's current positon within world
        transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * _speed);
    }
Example #7
0
    public Vector3Int?GetPositionOfTheNeighbourIfExists(Vector3 gridPosition, Direction direction)
    {
        Vector3Int?neighbourPosition = Vector3Int.FloorToInt(gridPosition);

        switch (direction)
        {
        case Direction.Up:
            neighbourPosition += new Vector3Int(0, 0, cellSize);
            break;

        case Direction.Right:
            neighbourPosition += new Vector3Int(cellSize, 0, 0);
            break;

        case Direction.Down:
            neighbourPosition += new Vector3Int(0, 0, -cellSize);
            break;

        case Direction.Left:
            neighbourPosition += new Vector3Int(-cellSize, 0, 0);
            break;
        }
        var index = CalculateGridIndex(neighbourPosition.Value);

        if (CheckIndexValidity(index) == false)
        {
            return(null);
        }
        return(neighbourPosition);
    }
Example #8
0
        public static Vector3 ScreenToWorld(this Vector3 screen, float z = 0f)
        {
            var result = Vector3Int.FloorToInt(R.camera.ScreenToWorldPoint(screen) - origin) + origin + ZERO_DOT_FIVE;

            result.z = z;
            return(result);
        }
Example #9
0
    /// <summary>
    ///     Returns GameObjects eligible to be displayed in the Item List Tab
    /// </summary>
    /// <param name="position">Position where to look for items</param>
    public static List <GameObject> GetItemsAtPosition(Vector3 position)
    {
        var matrix = MatrixManager.AtPoint(Vector3Int.RoundToInt(position), CustomNetworkManager.Instance._isServer).Matrix;

        if (!matrix)
        {
            return(new List <GameObject>());
        }

        position = matrix.transform.InverseTransformPoint(position);
        Vector3Int tilePosition = Vector3Int.FloorToInt(position);

        var registerTiles = matrix.Get <RegisterTile>(tilePosition, false);

        var result = registerTiles.Select(x => x.gameObject).ToList();

        //include interactable tiles
        var interactableTiles = matrix.GetComponentInParent <InteractableTiles>();

        if (interactableTiles != null)
        {
            result.Add(interactableTiles.gameObject);
        }

        return(result);
    }
Example #10
0
        public static Vector3Int WorldToArray(this Vector3 world)
        {
            var result = Vector3Int.FloorToInt(world - ZERO_DOT_FIVE - origin);

            result.z = 0;
            return(result);
        }
Example #11
0
        public static Vector3Int ScreenToArray(this Vector3 screen)
        {
            var result = Vector3Int.FloorToInt(R.camera.ScreenToWorldPoint(screen) - origin);

            result.z = 0;
            return(result);
        }
Example #12
0
        private void TakeStep(Vector2 movement)
        {
            var halfCollider = movementCollider * 0.5f;

            bool willCollide = false;

            foreach (var corner in new Vector2[]
            {
                new Vector2(halfCollider.x, halfCollider.y),
                new Vector2(-halfCollider.x, halfCollider.y),
                new Vector2(halfCollider.x, -halfCollider.y),
                new Vector2(-halfCollider.x, -halfCollider.y)
            })
            {
                var samplePoint        = Position + corner + movement;
                var sampleTilePosition = Vector3Int.FloorToInt(samplePoint);

                if (terrainCollider.OverlapPoint(samplePoint))
                {
                    willCollide = true;
                }
                if (decorationCollider.OverlapPoint(samplePoint))
                {
                    willCollide = true;
                }
            }

            if (!willCollide)
            {
                transform.position         = transform.position + new Vector3(movement.x, movement.y, 0.0f);
                game.State.Player.Position = new Vector2(transform.position.x, transform.position.y);
            }
        }
    void Spawn(int x, int y, GameObject toSpawn)
    {
        //find the position to spawn

        Vector2 offset   = roomSizeWorldUnits / 2.0f;
        Vector2 spawnPos = new Vector2(x, y) * worldUnitsInOneGridCell - offset;
        int     rand     = Random.Range(1, 200);

        //spawn object
        if (toSpawn == floorObj)
        {
            Vector3Int floorVec = Vector3Int.FloorToInt(new Vector2(x, y) * worldUnitsInOneGridCell - offset);

            floorMap.SetTile(floorVec, floorTile);
        }

        if (toSpawn == waterObj)
        {
            Vector3Int waterVec = Vector3Int.FloorToInt(new Vector2(x, y) * worldUnitsInOneGridCell - offset);
            wall2Map.SetTile(waterVec, wall2Tile);
        }

        if (toSpawn == wallObj)
        {
            Vector3Int wallVec = Vector3Int.FloorToInt(new Vector2(x, y) * worldUnitsInOneGridCell - offset);
            wallMap.SetTile(wallVec, wallTile);
        }
    }
    void SpawnSingleEnemy(int x, int y)
    {
        Vector2 offset   = roomSizeWorldUnits / 2.0f;
        Vector2 spawnPos = new Vector2(x, y) * worldUnitsInOneGridCell - offset;

        float rand     = Random.Range(1, 100);
        float distance = Vector3.Distance(new Vector3(x, y), new Vector3(player.transform.position.x, player.transform.position.y));

        if (distance > 50f)
        {
            // Spawn bat chance
            if (enemiesToSpawn > 0 && rand < spawnChance && grid[x + 1, y] != gridSpace.wall && grid[x - 1, y] != gridSpace.wall && grid[x, y + 1] != gridSpace.wall && grid[x, y - 1] != gridSpace.wall)
            {
                Vector3 spawnVec = Vector3Int.FloorToInt(spawnPos);
                Instantiate(robot, spawnVec, Quaternion.identity);
                enemiesToSpawn--;
                enemiesLeft++;
            }

            if (bossSpawned == false && enemiesToSpawn > 0 && rand < spawnChance && grid[x + 1, y] != gridSpace.wall && grid[x - 1, y] != gridSpace.wall && grid[x, y + 1] != gridSpace.wall && grid[x, y - 1] != gridSpace.wall)
            {
                Vector3 spawnVec = Vector3Int.FloorToInt(spawnPos);
                Instantiate(boss, spawnVec, Quaternion.identity);
                enemiesToSpawn--;
                enemiesLeft++;
                bossSpawned = true;
            }
        }
    }
Example #15
0
 public void Delete(Vector2 pos)
 {
     foreach (var t in tilemaps)
     {
         t.SetTile(Vector3Int.FloorToInt(pos), null);
     }
 }
Example #16
0
    private void ReapCorps(Ray ray)
    {
        RaycastHit2D hitInfo = new RaycastHit2D();

        hitInfo = Physics2D.GetRayIntersection(ray, 999999.0f, LayerMask.GetMask("Crops"));//有个返回数组的方法GetRayIntersectionAll,以后可以考考虑使用


        if (hitInfo.transform != null && hitInfo.transform.CompareTag("Crops"))
        {
            Vector3 pos = hitInfo.transform.position;
            pos.x -= 0.5f;
            pos.y -= 0.5f;
            if (FarmDataManager._Instance.TryGetNowPlotDataDic().TryGetValue(Vector3Int.FloorToInt(pos),
                                                                             out PlotData plot))
            {
                if ((bool)plot.CheckCropMature())
                {
                    //清空sprite、播放收获动画、删除ganmeobject
                    hitInfo.transform.gameObject.GetComponent <SpriteRenderer>().sprite = null;
                    Animator animator = hitInfo.transform.gameObject.GetComponent <Animator>();
                    animator.enabled = true;
                    animator.Play("ReapCrop", 0, 0);
                    AnimationClip temp =
                        Resources.Load("Animation/Farm/ReapCrop", typeof(AnimationClip)) as AnimationClip;
                    //清除Game Object(TileMapController)
                    Destroy(hitInfo.transform.gameObject, temp.length);
                    //Item++(FarmDataManager)
                    int fruitItemID = FarmDataManager._Instance.dataManager.GetCropsItemByID(plot.cropID).fruitItemID;
                    FarmDataManager._Instance.ItemAdd(fruitItemID, 1);
                    //清除plotData中的crop数据(FarmDataManager)
                    FarmDataManager._Instance.DeleteCropData(Vector3Int.FloorToInt(pos));
                }
            }
        }
    }
Example #17
0
    public void init()
    {
        player     = GameManager.instance.getPlayer();
        grid       = GameManager.instance.getGrid();
        mainCamera = GameManager.instance.getMainCamera();

        Vector3 origin = mainCamera.GetComponent <Camera>().ViewportToWorldPoint(mainCamera.transform.position);

        intOrigin = Vector3Int.FloorToInt(origin);

        ground = grid.transform.Find("Ground").gameObject.GetComponent <Tilemap>();
        // onGround = grid.transform.Find("On Ground").gameObject.GetComponent<Tilemap>();
        blockingCells = grid.transform.Find("Blocking Cells").gameObject.GetComponent <Tilemap>();
        boundaries    = grid.transform.Find("Boundaries").gameObject.GetComponent <Tilemap>();

        world        = new Tile[TOTAL_ROWS][];
        cellType     = new char[TOTAL_ROWS + 1, COLS];
        prevCellType = new char[TOTAL_ROWS + 1, COLS];

        generateWorldPart(0, true);
        displayWorldPart(0);
        generateBoundaryRow(-1);

        generateWorldPart(1);
        displayWorldPart(1);
        generateWorldPart(2);
        displayWorldPart(2);
    }
Example #18
0
        // Update is called once per frame
        void FixedUpdate()
        {
            Vector3Int enemyPos  = Vector3Int.FloorToInt(transform.position);
            Vector3Int playerPos = Vector3Int.FloorToInt(Player.transform.position);

            if (_playerHasSword)
            {
                Enemy.SetActive(false);
            }

            if (playerPos == enemyPos)
            {
                // if (_hasDamaged) return;
                if (!_playerHasSword)
                {
                    playerMovementScript.StopMovement();
                    Player.SendMessage("ReduceHealth", 1);
                    playerMovementScript.ResetPlayer();
                }
                else
                {
                    Enemy.SetActive(false);
                }
            }
        }
Example #19
0
    // Helper method to generate a vectorInt containing the current position of the cursor in
    // world coordinates that are floored to produce integer values.
    private Vector3Int getCurCursorWorldCoords()
    {
        Vector3    mPosWorldF = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int mPosWorldI = Vector3Int.FloorToInt(mPosWorldF);

        return(mPosWorldI);
    }
Example #20
0
    //public Branch GetNode(Vector3Int nodeIndex)
    //{
    //    return nodes[nodeIndex.x, nodeIndex.y, nodeIndex.z];
    //}

    public Branch GetNodeFromChunkIndex(Vector3Int chunkIndex)
    {
        Vector3    inputMod  = chunkIndex - origin;
        Vector3Int nodeIndex = Vector3Int.FloorToInt(inputMod / nodesPerChild);

        return(nodes[nodeIndex.x, nodeIndex.y, nodeIndex.z]);
    }
Example #21
0
    void Update()
    {
        if (PlayerSelected)
        {
            Vector2    mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Collider2D hover    = Physics2D.OverlapPoint(mousePos);
            Vector3Int mouse    = Vector3Int.FloorToInt(mousePos);
            Vector3    distance = player.transform.position;
            Vector3Int Distance = Vector3Int.FloorToInt(distance);

            int x = Mathf.Abs(mouse.x - Distance.x);
            int y = Mathf.Abs(mouse.y - Distance.y);


            if (Input.GetMouseButtonDown(0) && x < range && y < range)
            {
                //TileBase target = tilemap.GetTile(mouse);
                Debug.Log("You just ran tilemap.SetTile(mouse, null); at " + mouse + ", and you're on " + distance + ", that means you're only " + x + "," + y + " tiles away from it.");
                tilemap.SetTile(mouse, null);
            }
        }
        if (player == null)
        {
            player         = GameObject.Find("Player 1(Clone)");
            PlayerSelected = true;
        }
    }
Example #22
0
    private void SetRedirection()
    {
        bool bFlag = false;

        while (!bFlag)
        {
            destinationPosition = new Vector3(Random.Range(-14f, 14f), Random.Range(8f, 16f), 0f);

            //Random.Range(-14f, 14f), Random.Range(8f, 16f) : dungeon
            //Random.Range(-14f, 14f), Random.Range(-19f, -22f) : village

            foreach (var pos in tilemaping.nodes)
            {
                if (pos.Key == Vector3Int.FloorToInt(destinationPosition))
                {
                    if (pos.Value.Walkable == true)
                    {
                        bFlag = true;
                        //Debug.Log($"목적지 : {destinationPosition},{pos.Value.Walkable}");
                    }
                }
            }
        }

        FlipFacing();
    }
    /// <summary>
    /// Gets the game objects under the given world position, ordered so that highest item comes first.
    ///
    /// The top-level matrix gameobject (the one with InteractableTiles) at this point is included at the end (if any of its tilemap gameobjects were at this point)
    /// </summary>
    /// <param name="worldPoint">world point to check</param>
    /// <param name="layerMask">layers to check for hits in. If left null, will use DefaultInteractionLayerMask (basically includes every layer
    /// that can have interactable things).</param>
    /// <param name="gameObjectFilter">optional filter to filter out game objects prior to sorting and checking for pixel hits, can improve performance
    /// by shrinking the amount of sorting and pixel checking that needs to be done. Func should return true if should include the gameobject, otherwise false.
    /// Be aware that the GameObject passed to this function will be the one that the SpriteRenderer or TilemapRenderer lives on, which may NOT
    /// be the "root" of the gameobject this renderer lives on.</param>
    /// <returns>the ordered game objects that were under the mouse, top first</returns>
    public static IEnumerable <GameObject> GetOrderedObjectsAtPoint(Vector3 worldPoint, LayerMask?layerMask = null, Func <GameObject, bool> gameObjectFilter = null)
    {
        worldPoint.z = 0;
        var matrix = MatrixManager.AtPoint(Vector3Int.RoundToInt(worldPoint), CustomNetworkManager.Instance._isServer).Matrix;

        if (!matrix)
        {
            return(new List <GameObject>());
        }


        var tilePosition = Vector3Int.FloorToInt(worldPoint.ToLocal());

        List <RegisterTile> resultRegisterTile = new List <RegisterTile>();

        //humm probably there's a better way of doing this
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.up, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.down, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.right, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.left, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.up + Vector3Int.right, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.up + Vector3Int.left, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.down + Vector3Int.right, false).ToList());
        resultRegisterTile.AddRange(matrix.GetRegisterTile(tilePosition + Vector3Int.down + Vector3Int.left, false).ToList());



        var result             = resultRegisterTile.Select(x => x.gameObject);
        var IInteractableTiles = matrix.GetComponentInParent <InteractableTiles>().gameObject;

        // var result = Physics2D.RaycastAll(worldPoint, Vector2.zero, 10f,
        // layerMaskToUse)
        // failsafe - exclude hidden / despawned things in case they happen to mouse over hiddenpos
        // .Where(hit => !hit.collider.gameObject.IsAtHiddenPos())
        // get the hit game object
        // .Select(hit => hit.collider.gameObject);


        if (gameObjectFilter != null)
        {
            result = result.Where(gameObjectFilter);
        }

        return(result
               //check for a pixel hit
               .Select(go => IsPixelHit(go.transform))
               .Where(r => r != null)
               //order by sort layer
               .OrderByDescending(r => SortingLayer.GetLayerValueFromID(r.sortingLayerID))
               //then by sort order
               .ThenByDescending(renderer => renderer.sortingOrder)
               //get the "parent" game object of each of the hit renderers
               //for a sprite renderer, the parent is the object that has a RegisterTile.
               //for a tilemap renderer, the parent is the oject that has a Matrix
               .Select(r => r is TilemapRenderer ? r.GetComponentInParent <InteractableTiles>().gameObject :
                       r.GetComponentInParent <RegisterTile>().gameObject)
               //each gameobject should only show up once
               .Append(IInteractableTiles).Distinct());
    }
Example #24
0
 private void AutoJump()
 {
     if (facingRight &&
         // Block to the right exists
         tilemap.GetTile(Vector3Int.FloorToInt(new Vector3(GetComponent <Collider2D>().bounds.min.x + detectionDistance, GetComponent <Collider2D>().bounds.min.y, 0))) != null &&
         // Block to the right top does not exist
         tilemap.GetTile(Vector3Int.FloorToInt(new Vector3(GetComponent <Collider2D>().bounds.min.x + detectionDistance, GetComponent <Collider2D>().bounds.min.y + detectionDistance + 1, 0))) == null)
     {
         if (contact && canJump)
         {
             Jump(jumpStrength);
         }
     }
     if (!facingRight &&
         // Block to the left exists
         tilemap.GetTile(Vector3Int.FloorToInt(new Vector3(GetComponent <Collider2D>().bounds.min.x - detectionDistance, GetComponent <Collider2D>().bounds.min.y, 0))) != null &&
         // Block to the left top does not exist
         tilemap.GetTile(Vector3Int.FloorToInt(new Vector3(GetComponent <Collider2D>().bounds.min.x - detectionDistance, GetComponent <Collider2D>().bounds.min.y + detectionDistance + 1, 0))) == null)
     {
         if (contact && canJump)
         {
             Jump(jumpStrength);
         }
     }
 }
    public void OnPlayerFinished(PhotonPlayer player, int turn, object move)
    {
        print("Player Finish: " + player);
        if (player.IsLocal || move == null)
        {
            return;
        }

        var data = (MoveData)move;

        if (data.index.x != -1)
        {
            array[data.index.x][data.index.y] = player.IsMasterClient ? PlayerO : PlayerX;
            map.SetTile(Vector3Int.FloorToInt(data.index + offset), player.IsMasterClient ? tileO : tileX);
        }

        if (data.state == MoveData.State.WIN)
        {
            // I lost !
            print("Thua roi !");
            gameOverText.text = "Thua roi !";
            StartCoroutine(WaitToReload());
        }
        else if (data.state == MoveData.State.LOOSE)
        {
            // I won !
            print("Thang roi !");
            gameOverText.text = "Thang roi !";
            StartCoroutine(WaitToReload());
        }
        turnManager.SendMove(null, true);
    }
Example #26
0
    private void StormSpawn()
    {
        int     xCoord = Random.Range(-1 * ((map.size.x / 2) - 1), (map.size.x / 2) - 1);
        int     yCoord = Random.Range(-1 * ((map.size.y / 2) - 1), (map.size.y / 2) - 1);
        Vector3 temp   = new Vector3(xCoord, yCoord, 0);

        GameObject tempStorm = Instantiate(StormPrefab, map.CellToWorld(Vector3Int.FloorToInt(temp)), this.transform.rotation);

        StormList.Add(tempStorm);



        //collisionCheckStorm(map.CellToWorld(Vector3Int.FloorToInt(temp)))
        int limit = 0;

        while (collisionCheckStorm(tempStorm.transform.position, tempStorm) || CollisionCheckPlayer(tempStorm.transform.position))
        {
            //temp = StormSpawn();
            limit++;
            changeStormPosition(tempStorm);
            if (limit > 6)
            {
                return;
            }
        }
    }
    private void AutoPos()
    {
        Vector3    fromCenterPos = door.FronTilemap.cellBounds.center, toCenterPos = door.ToTilemap.cellBounds.center;
        Vector3Int fromInt = Vector3Int.FloorToInt(fromCenterPos), toInt = Vector3Int.FloorToInt(toCenterPos);

        Debug.Log(door.FronTilemap.CellToWorld(fromInt) - door.ToTilemap.CellToWorld(toInt));
    }
Example #28
0
        internal static float Gradient(Vector3 position)
        {
#if BIOSEARCHER_PROFILING
            Profiler.BeginSample("Noise.Gradient");
#endif
            Vector3Int wholePart = Vector3Int.FloorToInt(position);
            Vector3    fractPart = Smooth(position - wholePart);
            var        noisesZ   = new float[2];
            var        noisesY   = new float[2];
            var        noisesX   = new float[2];
            Vector3Int delta     = default;

            for (delta.z = 0; delta.z < 2; delta.z++)
            {
                for (delta.y = 0; delta.y < 2; delta.y++)
                {
                    for (delta.x = 0; delta.x < 2; delta.x++)
                    {
                        noisesX[delta.x] = Get(wholePart + delta);
                    }
                    noisesY[delta.y] = Mathf.Lerp(noisesX[0], noisesX[1], fractPart.x);
                }
                noisesZ[delta.z] = Mathf.Lerp(noisesY[0], noisesY[1], fractPart.y);
            }
            float gradient = Mathf.Lerp(noisesZ[0], noisesZ[1], fractPart.z);

#if BIOSEARCHER_PROFILING
            Profiler.EndSample();
#endif
            return(gradient);
        }
Example #29
0
    void Start()
    {
        map        = GameObject.FindGameObjectWithTag("Map").GetComponent <Map>();
        attachment = GetComponent(typeof(IAttachment)) as IAttachment;

        Vector3Int pos = Vector3Int.FloorToInt(transform.position);
    }
    public void SwitchAttackMode()
    {
        if (attackMode)
        {
            attackMode            = false;
            avalibleMovementTiles = AreaCalculations.GetTilesAvalibleForMovement(currentCharacter);

            if (attackArea != null)
            {
                ClearTiles(attackArea.AffectedTiles);
                ClearTilesFromHashtable(attackArea.AffectedCharacters);
            }

            ShowTilesFromHashtable(avalibleMovementTiles, tileAvailableForMove);
        }
        else
        {
            attackMode = true;
            ClearTilesFromHashtable(avalibleMovementTiles);

            if (currentCharacter.ActionAvailable)
            {
                attackArea = AreaCalculations.GetAreaOfEffect(Vector3Int.FloorToInt(currentCharacter.transform.position), currentCharacter.AttackRange, currentCharacter.Team);
                ShowTiles(attackArea.AffectedTiles, tileAffected);
                ShowTilesFromHashtable(attackArea.AffectedCharacters, tileTarget);
            }
        }
    }