示例#1
0
文件: Player.cs 项目: paupul/dugcra
    public void AttemptMove(int xDir, int yDir)
    {
        if (Time.timeScale == 1)
        {
            Vector2      end = rb2D.position + new Vector2(xDir, yDir);
            RaycastHit2D fogDetect;
            RaycastHit2D walldetect;

            fogDetect  = Physics2D.Linecast(rb2D.position, end, fog);
            walldetect = Physics2D.Linecast(rb2D.position, end, wall); //nekeisti

            WorldPos pos = EditTerrain.GetBlockPos(fogDetect);
            //Debug.Log(pos.x + " " + pos.y);

            if (fogDetect)
            {
                fogWorld.SetTile(pos.x, pos.y, new GridTile(GridTile.TileTypes.Empty));
                scoreManager.AddPoints(1);
            }
            //if (fogDetect)
            //{
            //    GameObject.Find(fogDetect.transform.name).GetComponent<SpriteRenderer>().enabled = false;
            //    print(fogDetect.transform.name);
            //    GameObject.Find(fogDetect.transform.name).GetComponent<BoxCollider2D>().enabled = false;
            //    Destroy(GameObject.Find(fogDetect.transform.name).GetComponent<GameObject>());
            //}
            if (!walldetect && !fogDetect)
            {
                gameSounds.PlaySound(rnd.Next(0, 2));
                rb2D.MovePosition(end);
            }
        }
        StartCoroutine(Delay());
    }
示例#2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Spear")
        {
            gameSounds.PlaySound(4);
            spear++;
            scoreManager.AddPoints(pointsForItem);
            // print("Spear count:" + spear);
            other.gameObject.SetActive(false);
        }
        else if (other.tag == "Ladder")
        {
            gameSounds.PlaySound(4);
            ladder++;
            scoreManager.AddPoints(pointsForItem);
            //print("Ladder count:" + ladder);
            other.gameObject.SetActive(false);
        }

        else if (other.tag == "Monster")
        {
            if (spear <= 0)
            {
                game_over_text.text = "You got butchered by the monster.";
                //print("Game over...:");
                game_over.SetActive(true);
                gameSounds.PlaySound(2);
                Time.timeScale = 0;
                //   SceneManager.LoadScene(0);
            }
            else
            {
                spear--;
                gameSounds.PlaySound(5);
                //print("Spear count:" + spear);
                scoreManager.AddPoints(pointsForEnemy);
                other.gameObject.SetActive(false);
            }
        }
        else if (other.tag == "Pit")
        {
            if (ladder <= 0)
            {
                Time.timeScale      = 0;
                game_over_text.text = "You died in agony inside a pit.";
                //print("Game over...:");
                game_over.SetActive(true);
                gameSounds.PlaySound(2);
                //  SceneManager.LoadScene(0);
            }
            else
            {
                ladder--;
                gameSounds.PlaySound(5);
                //print("Ladder count:" + ladder);
                scoreManager.AddPoints(pointsForEnemy);
                other.gameObject.SetActive(false);
            }
        }
        else if (other.tag == "Chest")
        {
            if (LevelManager.levelIndex + 1 < LevelManager.levels.Count)
            {
                scoreManager.AddPoints(pointsForChest);
                scoreManager.SaveCurrentPoints();
                Time.timeScale = 0;
                gameSounds.PlaySound(3);
                next_level.SetActive(true);
            }
            else
            {
                scoreManager.AddPoints(pointsForChest);
                scoreManager.SaveCurrentPoints();
                Time.timeScale = 0;
                game_finished.SetActive(true);
            }
        }
    }