Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (GameOver)
     {
         return;
     }
     place           = (KeyCode)Enum.Parse(typeof(KeyCode), GetComponent <PlayerAttribute>().GetPlaceBoom());
     leftBombNumbers = GetComponent <PlayerAttribute> ().GetLeftBombNumber();
     if (Input.GetKeyDown(place) && leftBombNumbers != 0)
     {
         var offset = GetComponent <BoxCollider2D> ().offset;
         var pos    = new Vector3(
             T.position.x,
             T.position.y + offset.y * T.localScale.y,
             T.position.z);
         pos.x     = Mathf.Round(pos.x);
         pos.y     = Mathf.Round(pos.y);
         bombpos.x = pos.x;
         bombpos.y = pos.y;
         source.PlayOneShot(placeBomb, 0.7f);
         if (!BombList.ContainsKey(bombpos))
         {
             GameObject bomb = (GameObject)Instantiate(prefab[0], pos, Quaternion.identity);
             GetComponent <PlayerAttribute> ().SetLeftBombNumber(leftBombNumbers - 1);
             var playernum = GetComponent <PlayerAttribute> ().GetplayerNum();
             bomb.GetComponent <BombAttribute> ().SetBelongToPlayer(playernum);
             var BombRange = GetComponent <PlayerAttribute> ().GetRangeOfBomb();
             bomb.GetComponent <BombAttribute> ().SetRange(BombRange);
             bomb.layer         = 10 + playernum;
             BombList [bombpos] = bomb;
         }
     }
 }
Ejemplo n.º 2
0
    private int destroyItem(Vector3 nextpos, int leftRange)
    {
        GameObject fire = (GameObject)Instantiate(prefab [0], nextpos, Quaternion.identity);

        objectPos.x = nextpos.x;
        objectPos.y = nextpos.y;
        if (WoodBoxList.ContainsKey(objectPos))
        {
            Destroy(WoodBoxList[objectPos]);
            leftRange = 1;
        }
        if (SpecialBoxList.ContainsKey(objectPos))
        {
            Destroy(SpecialBoxList[objectPos]);
            leftRange = 1;
        }
        if (BombList.ContainsKey(objectPos))
        {
            Destroy(BombList[objectPos]);
        }
        if (ItemList.ContainsKey(objectPos))
        {
            var ItemNumber = ItemList [objectPos].GetComponent <ItemAttribute> ().GetItemNumber();
            if (ItemNumber != 8 && ItemNumber != 9)
            {
                Destroy(ItemList [objectPos]);
            }
        }
        if (BaseList.ContainsKey(objectPos))
        {
            BaseList [objectPos].GetComponent <BaseAttribute> ().DamageBase();
        }
        destroyPlayer(objectPos.x, objectPos.y);
        nextpos.y++;
        leftRange--;
        return(leftRange);
    }
Ejemplo n.º 3
0
    void OnDestroy()
    {
        var belongToPlayer = GetComponent <BombAttribute> ().GetBelongToPlayer();
        int LeftBombnumber;

        if (playerLive [belongToPlayer])
        {
            LeftBombnumber = playerList[belongToPlayer].GetComponent <PlayerAttribute> ().GetLeftBombNumber();
            playerList[belongToPlayer].GetComponent <PlayerAttribute> ().SetLeftBombNumber(LeftBombnumber + 1);
        }
        var pos = GetComponent <Transform> ().position;

        bombpos.x = Mathf.Round(pos.x);
        bombpos.y = Mathf.Round(pos.y);
        var range = GetComponent <BombAttribute> ().GetRange();

        if (BombList.ContainsKey(bombpos))
        {
            BombList.Remove(bombpos);
        }
        T          = GetComponent <Transform> ();
        T.position = new Vector3(Mathf.Round(T.position.x), Mathf.Round(T.position.y), T.position.z);
        GameObject fire0 = (GameObject)Instantiate(prefab[0],
                                                   new Vector3(T.position.x, T.position.y, T.position.z),
                                                   Quaternion.identity);
        var nextpos = new Vector3(T.position.x, T.position.y, T.position.z);

        destroyPlayer(nextpos.x, nextpos.y);

        //Up
        nextpos = new Vector3(T.position.x, T.position.y + 1, T.position.z);
        var leftRange = range;

        while (checkPosition(nextpos, leftRange))
        {
            leftRange = destroyItem(nextpos, leftRange);
            nextpos.y++;
        }

        //Down
        nextpos   = new Vector3(T.position.x, T.position.y - 1, T.position.z);
        leftRange = range;
        while (checkPosition(nextpos, leftRange))
        {
            leftRange = destroyItem(nextpos, leftRange);
            nextpos.y--;
        }

        //Left
        nextpos   = new Vector3(T.position.x - 1, T.position.y, T.position.z);
        leftRange = range;
        while (checkPosition(nextpos, leftRange))
        {
            leftRange = destroyItem(nextpos, leftRange);
            nextpos.x--;
        }

        //Right
        nextpos   = new Vector3(T.position.x + 1, T.position.y, T.position.z);
        leftRange = range;
        while (checkPosition(nextpos, leftRange))
        {
            leftRange = destroyItem(nextpos, leftRange);
            nextpos.x++;
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (GameOver)
        {
            return;
        }
        var number = GetComponent <PlayerAttribute> ().GetSpecialObject();

        if (Input.GetKeyDown(tick))
        {
            if (number == 0)
            {
                return;
            }
            source.PlayOneShot(kick, 0.7f);
            var T      = GetComponent <Transform> ();
            var offset = GetComponent <BoxCollider2D> ().offset;
            var pos    = new Vector3(
                T.position.x,
                T.position.y + offset.y * T.localScale.y,
                T.position.z);
            objectPos.x = Mathf.Round(pos.x);
            objectPos.y = Mathf.Round(pos.y);
            direc       = ani.GetInteger("Direction");
            switch (direc)
            {
            case 1:
                objectPos.y--;
                break;

            case 2:
                objectPos.y++;
                break;

            case 3:
                objectPos.x++;
                break;

            case 4:
                objectPos.x--;
                break;

            default:
                break;
            }
            if (BombList.ContainsKey(objectPos))
            {
                GetComponent <PlayerAttribute> ().SetSpecialObject(GetComponent <PlayerAttribute> ().GetSpecialObject() - 1);
                var BombSpeed = 4;
                switch (direc)
                {
                case 1:
                    BombList [objectPos].GetComponent <Rigidbody2D> ().velocity = new Vector2(0, -BombSpeed);
                    break;

                case 2:
                    BombList [objectPos].GetComponent <Rigidbody2D> ().velocity = new Vector2(0, BombSpeed);
                    break;

                case 3:
                    BombList [objectPos].GetComponent <Rigidbody2D> ().velocity = new Vector2(BombSpeed, 0);
                    break;

                case 4:
                    BombList [objectPos].GetComponent <Rigidbody2D> ().velocity = new Vector2(-BombSpeed, 0);
                    break;

                default:
                    break;
                }
                BombList [objectPos].layer = 0;
                BombList.Remove(objectPos);
            }
        }
    }