Exemple #1
0
    public void showWuping()
    {
        for (int i = 0; i <= wupinglist.Count - 1; i++)
        {
            //获取物品种类、位置
            wupingType type    = wupinglist[i].thisType;
            int[]      ZuoBiao = wupinglist[i].zuobiao;

            int    newhp = 0, newatk = 0, newdef = 0, newyellow = 0, newblue = 0, newred = 0, newem = 0, newcoin = 0;
            string prefabUrl = "";//prefab路径
            string info      = "";

            //实例化物品
            switch (type)
            {
            case wupingType.Atkup:
                prefabUrl = "wuping/item_0";
                newatk    = 5;
                info      = "发现红宝石!攻击力上升5!";
                break;

            case wupingType.Defup:
                prefabUrl = "wuping/item_1";
                newdef    = 5;
                info      = "发现蓝宝石!防御力上升5!";
                break;

            case wupingType.smallHp:
                prefabUrl = "wuping/item_4";
                newhp     = 300;
                info      = "喝下小生命药水!生命恢复300!";
                break;

            case wupingType.normalHp:
                prefabUrl = "wuping/item_5";
                newhp     = 500;
                info      = "喝下生命药水!生命恢复500!";
                break;

            case wupingType.bigHp:
                prefabUrl = "wuping/item_6";
                newhp     = 1000;
                info      = "喝下大生命药水!生命恢复1000!";
                break;

            case wupingType.maxHP:
                prefabUrl = "wuping/item_7";
                newhp     = 1500;
                info      = "喝下圣水,生命恢复1500!";
                break;

            case wupingType.yellowKey:
                prefabUrl = "wuping/item_14";
                newyellow = 1;
                info      = "找到一把黄色钥匙!";
                break;

            case wupingType.blueKey:
                prefabUrl = "wuping/item_15";
                newblue   = 1;
                info      = "找到一把蓝色钥匙!";
                break;

            case wupingType.redKey:
                prefabUrl = "wuping/item_16";
                newred    = 1;
                info      = "找到一把红色钥匙!";
                break;

            case wupingType.Shieldlevel_1:
                prefabUrl = "wuping/item_50";
                newdef    = 50;
                info      = "装备盾牌!防御力上升50!";
                break;

            case wupingType.Shieldlevel_2:
                prefabUrl = "wuping/item_53";
                newdef    = 80;
                info      = "装备精良盾牌!防御力上升80!";
                break;

            case wupingType.Shieldlevel_3:
                prefabUrl = "wuping/item_54";
                newdef    = 120;
                info      = "装备先锋盾!防御力上升120!";
                break;

            case wupingType.Swordlevel_1:
                prefabUrl = "wuping/item_45";
                newatk    = 50;
                info      = "装备铁剑!攻击力上升50!";
                break;

            case wupingType.Swordlevel_2:
                prefabUrl = "wuping/item_47";
                newatk    = 80;
                info      = "装备战士剑!攻击力上升80!";
                break;

            case wupingType.Swordlevel_3:
                prefabUrl = "wuping/item_49";
                newatk    = 120;
                info      = "装备退魔剑!攻击力上升120!";
                break;
            }
            //加载位置
            GameObject wuping = (GameObject)Instantiate(Resources.Load(prefabUrl));
            wuping.transform.position = new Vector3(ZuoBiao[0] * 0.32f + 0.16f, -ZuoBiao[1] * 0.32f - 0.16f, 0f);
            wuping.GetComponent <SpriteRenderer>().sortingOrder = 10;
            //挂载物品属性脚本
            wupingMain wm = wuping.AddComponent <wupingMain>();
            wm.hpVar        = newhp;
            wm.atkVar       = newatk;
            wm.defVar       = newdef;
            wm.yellowKeyVar = newyellow;
            wm.blueKeyVar   = newblue;
            wm.redKeyVar    = newred;
            wm.emVar        = newem;
            wm.coinVar      = newcoin;
            wm.Infostring   = info;

            gameObject.GetComponent <myTweenAlpha>()._thisSprite.Add(wuping);
        }
    }
Exemple #2
0
    private bool isCollider(KeyCode dir)
    {
        bool    result = false;
        Vector2 v2     = transform.position;
        Vector2 dirv2  = new Vector2();
        Vector2 v3     = new Vector2();

        switch (dir)
        {
        case KeyCode.W:
            //Debug.Log(v2);
            dirv2 = Vector2.up;
            v3    = v2 + new Vector2(0f, 0.32f);
            break;

        case KeyCode.S:
            dirv2 = -Vector2.up;
            v3    = v2 + new Vector2(0f, -0.32f);
            break;

        case KeyCode.A:
            dirv2 = -Vector2.right;
            v3    = v2 + new Vector2(-0.32f, 0f);
            break;

        case KeyCode.D:
            dirv2 = Vector2.right;
            v3    = v2 + new Vector2(0.32f, 0f);
            break;
        }

        if (v3.x < 0.158f || v3.x > 3.36f || v3.y < -3.36f || v3.y > -0.158f)
        {
            result = true;
        }

        if (Physics2D.Raycast(v2, -Vector2.up))
        {
            hitInfo = Physics2D.RaycastAll(v2, dirv2, 0.32f);
            if (hitInfo.Length > 1)
            {
                //Debug.Log(hitInfo.Length);
                foreach (RaycastHit2D info in hitInfo)
                {
                    //遇到墙的事件
                    if (info.collider.name == "Collision")
                    {
                        //Debug.Log(info.collider.name);
                        result = true;
                    }
                    //遇到怪物时的事件
                    else if (info.collider.tag == "enemy" && !isBattle && !isShop)
                    {
                        //弹出战斗面板,禁止主角移动
                        isBattle = true;
                        GameObject labels = GameObject.Find("UI Root").transform.Find("main").Find("battlePanel").gameObject;
                        labels.gameObject.SetActive(true);
                        //增加动画组件
                        UISpriteAnimation usa = labels.transform.Find("enemysprite").gameObject.AddComponent <UISpriteAnimation>();
                        usa.framesPerSecond = 6;
                        //根据属性给面板赋值
                        UIAtlas atlasX = (UIAtlas)Resources.Load("enemy_" + info.collider.gameObject.GetComponent <enemypro>().enemyTypeID.ToString() + "Ani", typeof(UIAtlas));
                        labels.transform.Find("enemysprite").GetComponent <UISprite>().atlas = atlasX;
                        Debug.Log(atlasX.spriteList[0].name + "lll" + atlasX.spriteList.Count);
                        labels.transform.Find("enemysprite").GetComponent <UISprite>().spriteName = atlasX.spriteList[0].name;
                        labels.transform.Find("enemy_hp").GetComponent <UILabel>().text           = info.collider.GetComponent <enemypro>().hp.ToString();
                        labels.transform.Find("enemy_atk").GetComponent <UILabel>().text          = info.collider.GetComponent <enemypro>().atk.ToString();
                        labels.transform.Find("enemy_def").GetComponent <UILabel>().text          = info.collider.GetComponent <enemypro>().def.ToString();
                        labels.transform.Find("hero_hp").GetComponent <UILabel>().text            = gameObject.GetComponent <playerpro>().hp.ToString();
                        labels.transform.Find("hero_atk").GetComponent <UILabel>().text           = gameObject.GetComponent <playerpro>().atk.ToString();
                        labels.transform.Find("hero_def").GetComponent <UILabel>().text           = gameObject.GetComponent <playerpro>().def.ToString();

                        gameObject.GetComponent <battleMain>().duel(gameObject, info.collider.gameObject);
                    }
                    //遇到门的事件
                    else if (info.collider.tag == "door" && !isOpenDoor)
                    {
                        if (info.collider.GetComponent <delDoor>().isOpened())
                        {
                            //同步钥匙数量面板,并开门
                            GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("yellowCount").GetComponent <UILabel>().text = player.yellowKey.ToString();
                            GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("blueCount").GetComponent <UILabel>().text   = player.blueKey.ToString();
                            GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("redCount").GetComponent <UILabel>().text    = player.redKey.ToString();

                            info.collider.GetComponent <delDoor>().setOpen();
                            isOpenDoor = true;
                        }
                        else
                        {
                            isDoor = true;
                        }
                    }
                    //遇到道具时的事件
                    else if (info.collider.tag == "wuping" && !isBattle)
                    {
                        isBattle = true;
                        result   = true;
                        wupingMain wm = info.collider.GetComponent <wupingMain>();
                        wm.useWuping();
                    }
                    //遇到楼梯时的事件
                    else if (info.collider.tag == "floor")
                    {
                        if (info.collider.name == "up_floor")
                        {//上楼
                            isOpenDoor      = true;
                            player.upOrdown = "up";
                            Debug.Log("battle0" + player.playerInfloor.ToString() + "(Clone)");
                            GameObject.Find("battle0" + player.playerInfloor.ToString() + "(Clone)").GetComponent <myTweenAlpha>().tweenOut();
                        }
                        else if (info.collider.name == "down_floor")
                        {//下楼
                            isOpenDoor      = true;
                            player.upOrdown = "down";
                            GameObject.Find("battle0" + player.playerInfloor.ToString() + "(Clone)").GetComponent <myTweenAlpha>().tweenOut();
                        }
                    }
                    //遇到NPC时的事件
                    else if (info.collider.tag == "npc" && !isBattle)
                    {
                        info.collider.GetComponent <npcScript>().showShop();
                    }
                }
            }
            //Debug.Log(v2);
            //Debug.DrawRay(v2, -Vector2.up);
        }

        //Debug.Log(result);
        return(result);
    }