GetTileAtPosition() public method

Gets the tile coordinate at position. This can be used to obtain tile or color data explicitly from layers Returns true if the position is within the tilemap bounds
public GetTileAtPosition ( Vector3 position, int &x, int &y ) : bool
position Vector3
x int
y int
return bool
Esempio n. 1
0
 public bool enemy(Enemy enemy)
 {
     UM.infoDabuguo  = "你打不过他\n\n";
     UM.infoDabuguo += "怪物属性:\n";
     UM.infoDabuguo += "生命:" + enemy.shengming + "\n";
     UM.infoDabuguo += "攻击:" + enemy.gongji + "\n";
     UM.infoDabuguo += "防御:" + enemy.fangyu + "\n";
     UM.infoDabuguo += "金币:" + enemy.jinbi + "\n";
     UM.infoDabuguo += "经验:" + enemy.jingyan + "\n";
     if (HA._gongji <= enemy.fangyu)
     {
         UM.state = "dabuguo";
     }
     else
     {
         int   shanghai     = HA._gongji - enemy.fangyu;
         float cishu        = Mathf.Floor(enemy.shengming / shanghai);
         float zongshanghai = 0;
         if (enemy.gongji > HA._fangyu)
         {
             float shoushang = enemy.gongji - HA._fangyu;
             zongshanghai = shoushang * cishu;
         }
         if (zongshanghai >= HA._shengming)
         {
             UM.state = "dabuguo";
         }
         else
         {
             AuM.playAudio("fight");
             Instantiate(fightAnimation, enemy.gameObject.transform.position, enemy.gameObject.transform.rotation);
             HA._shengming -= (int)zongshanghai;
             HA._jingyan   += enemy.jingyan;
             HA.plusJinbi(enemy.jinbi);
             UM.tipContent = "经验+" + enemy.jingyan + ",金币+" + enemy.jinbi;
             UM.tipTime    = 3f;
             if (enemy.isDoorProtector)
             {
                 List <GameObject> protectorGameObject = enemy.doorComponent.protectorGameObject;
                 if (protectorGameObject.Remove(enemy.gameObject))
                 {
                     if (protectorGameObject.Count == 0)
                     {
                         DoorAnim = enemy.doorComponent.gameObject.GetComponent <tk2dSpriteAnimator>();
                         DoorAnim.Play("DoorBig");
                         Destroy(enemy.doorComponent.gameObject, 0.5f);
                         tk2dTileMap tm = GameObject.Find("TileMap").GetComponent <tk2dTileMap>();
                         int         x, y;
                         tm.GetTileAtPosition(enemy.doorComponent.gameObject.transform.position, out x, out y);
                         tm.ClearTile(x, y, 1);
                     }
                 }
             }
             Destroy(enemy.gameObject);
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
    public Point GetLocation(Vector3 v)
    {
        int x;
        int y;

        tilemap.GetTileAtPosition(v, out x, out y);
        return(new Point(x, y));
    }
Esempio n. 3
0
    //对话完成后,移除精灵
    public void clearJingLing()
    {
        tk2dTileMap tm = GameObject.Find("TileMap").GetComponent <tk2dTileMap>();
        int         x, y;

        tm.GetTileAtPosition(jingling.transform.position, out x, out y);
        tm.ClearTile(x, y, 1);
        Destroy(jingling);
    }
        public TileInfo GetTileAtPosition(Vector2 pos, TileLayer l)
        {
            int           x, y, tileId = -1;
            TileDirection dir = TileDirection.Up;

            if (map.GetTileAtPosition(pos, out x, out y))
            {
                tileId = map.GetTile(x, y, (int)l);
            }
            tk2dTileFlags flags = map.GetTileFlags(x, y, (int)l);

            dir = (TileFlagsToTileDirection(flags));

            TileInfo tile = new TileInfo();

            tile.worldPos = map.GetTilePosition(x, y);
            switch (tileId)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 32:
            case 33:
            case 34:
            case 35:
            case 36:
            case 64:
            case 65:
            case 66:
                tile.type = TileType.Wall;
                break;

            case 8:
                tile.type = TileType.Lava;
                break;

            default:
                tile.type = TileType.Empty;
                break;
            }
            if (tileId == spikeTile)
            {
                tile.type = TileType.Spike;
            }
            print(tile.type);
            tile.direction = dir;
            return(tile);
        }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (projectileCollision != null)
        {
            int xPos;
            int yPos;

            ContactPoint2D contactpoint = projectileCollision.contacts[0];
            Vector3        tempVec      = new Vector3(contactpoint.point.x + (.5f * contactpoint.normal.x), contactpoint.point.y, 5);

            tilemap.GetTileAtPosition(tempVec, out xPos, out yPos);


            int tileId = tilemap.Layers[layerCollider].GetTile(xPos, yPos);
            if (tileId >= 0)
            {
                if (tileArray[xPos, yPos] > 0)
                {
                    tileArray[xPos, yPos] -= damage;
                    int damageTile = (int)(3 * (tileArray[xPos, yPos]) / health) + 64;
                    Debug.Log(damageTile);
                    tilemap.Layers[layerColliderDecals].SetTile(xPos, yPos, damageTile);
                }
                else
                {
                    tilemap.Layers[layerCollider].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderDecals].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderCorners].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderEdges].ClearTile(xPos, yPos);
                    setNWESTiles(xPos, yPos);
                }
                tilemap.Build();
            }
        }
        projectileCollision = null;
        damage = 0;
    }
Esempio n. 6
0
    void Update()
    {
        if (isGoal)
        {
            if (!isGoalWalkStarted)
            {
                isGoalWalkStarted = true;

                player.animator.Play("Walk");
                player.animator.ClipFps = 2f;

                player.sprite.scale = new Vector3(player.sprite.scale.x * -1f, player.sprite.scale.y, player.sprite.scale.z);
            }
        }

        // Attempt to get ground position
        if (player.isGrounded)
        {
            tempGroundPosition  = lastGroundPositionY;
            lastGroundPositionY = player.transform.position.y;
        }

        if (!isFairyPause && player.isAlive && isGameReady)
        {
            // Falling death
            if (playerTransform.position.y < cameraTransform.position.y - camera.ScreenExtents.height / 2f)
            {
                player.Die(false, true);
            }

            if (player.isAlive)
            {
                UpdateScore();

                healthTimer -= Time.deltaTime;

                if (healthTimer < 0)
                {
                    healthTimer = healthTimerAmount;

                    Damage(1);
                }

                // FAIRY INVINCIBILITY COUNTDOWN
                if (isFairy)
                {
                    fairyTimer += Time.deltaTime;

                    if (fairyTimer >= fairyTime)
                    {
                        Fairy.instance.transform.DOLocalMove(new Vector2(8f, 18f), 2.5f).SetEase(Ease.Linear).OnComplete(() => {
                            isFairy = false;
                            Destroy(Fairy.instance.gameObject);
                        });

//						Fairy.instance.FlyAway ();
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }

            RaycastHit2D hit = Physics2D.Raycast(playerTransform.position, Vector2.down, 200f, LayerMask.GetMask("Ground TM"));

            if (hit)
            {
                tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1));

                if (tileInfo != null)
                {
                    if (tileInfo.intVal == 1)
                    {
                        isSlope = true;

                        tilemap.GetTileAtPosition(hit.point, out tileX, out tileY);
                    }
                    else
                    {
                        isSlope = false;
                    }
                }
                else
                {
                    isSlope = false;
                }

                int tileId = tilemap.GetTileIdAtPosition(hit.point, 1);

                tileInfo = tilemap.GetTileInfoForTileId(tilemap.GetTileIdAtPosition(hit.point, 1));
            }
        }
    }