示例#1
0
    /// <summary>
    /// This function remove items from the cart and return resources
    /// </summary>
    /// <param name="item_idx"></param>
    public void SubPurchase_item_remove(byte item_idx)
    {
        Equipable_generic item = purchasables[item_idx].GetComponent <Equipable_generic>();

        buffer_money += item.price;
        buffer_inventory_capacity -= item.get_size();
        cart.Remove(item_idx);
        //Render
        Text_money.text = "$ " + buffer_money;
        if (item.tag == CONSTANTS.TAG_GUN)
        {
            //purchase_buttons[item_idx].colors = set_button_color(0);
        }
        else if (item.tag == CONSTANTS.TAG_AMMO)
        {
            purchase_buttons[item_idx].GetComponent <digit_mod_generic>().subtract(item.GetComponent <Ammo_generic>().amount);

            /*
             * if (!cart.Contains(item_idx))//If this ammo has reached zero, turn button unselected
             * {
             *  purchase_buttons[item_idx].colors = set_button_color(0);
             * }
             */
        }
        SubPurchase_item_refresh();
    }
示例#2
0
    /// <summary>
    /// This function evaluate if player has enough resources to purchase
    /// </summary>
    /// <param name="item_idx"></param>
    public void SubPurchase_item_add(byte item_idx)
    {
        Equipable_generic item = purchasables[item_idx].GetComponent <Equipable_generic>();
        ushort            available_inventory = (ushort)(buffer_inventory_size - buffer_inventory_capacity);
        ushort            item_size           = item.get_size();

        if (item.price <= buffer_money && item_size <= available_inventory && body.experience >= item.required_experience)
        {
            buffer_money -= item.price;
            buffer_inventory_capacity += item_size;
            cart.Add(item_idx);
            //Render
            Text_money.text = "$ " + buffer_money;
            //purchase_buttons[item_idx].colors = set_button_color(1);

            if (item.tag == CONSTANTS.TAG_AMMO)
            {
                purchase_buttons[item_idx].GetComponent <digit_mod_generic>().add(item.GetComponent <Ammo_generic>().amount);
            }
        }
        else
        {
            //Debug.Log("not enough resources");
        }
        SubPurchase_item_refresh();
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        //Cursor
        if (cursor != null)
        {
            if (controller.equiped_item == null)
            {
                cursor_size = -1;
            }
            else
            {
                if (controller.equiped_item.tag == "pickup_ammo")
                {
                    cursor_size = -1;
                }
                else if (controller.equiped_item.tag == "pickup_grenade")
                {
                    cursor_size = -1;
                }
                else if (controller.equiped_item.tag == "pickup_gun")
                {
                    Gun_generic gun      = controller.equiped_item.GetComponent <Gun_generic>();
                    float       firecone = (gun.firecone_angle + gun.precise) * Mathf.PI / 180;
                    if (firecone != 90)
                    {
                        cursor_size = Mathf.Tan(firecone) * Vector2.Distance(controller.mousepos, transform.position);//controller.playerRB.position);
                    }
                    else
                    {
                        cursor_size = 0;
                    }
                }
            }
            cursor_anim.SetFloat(CONSTANTS.ANIM_PARAM_CURSOR_SIZE, cursor_size);
            if (cursor_size == -1)
            {
                Cursor.visible = true;
                //cursor.transform.localScale = new Vector3(0, 0, 0);
            }
            else
            {
                Cursor.visible              = false;
                cursor.transform.rotation   = main_camera.transform.rotation;
                cursor.transform.localScale = new Vector3(1, 1, 1);
                cursor.transform.position   = new Vector3(controller.mousepos.x, controller.mousepos.y, cursor.transform.position.z);
                float cam_cursor_scale = main_camera.orthographicSize / 10;

                cursor_l.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_r.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_u.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_d.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_se.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_sw.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_ne.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_nw.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
            }
        }



        //Follow camera
        //HUD_camera.GetComponent<Camera>().orthographicSize = main_camera.orthographicSize;
        float cam_scale = main_camera.orthographicSize / 5;

        //HUD.localScale = new Vector3(cam_scale, cam_scale, 1);

        //Health state effect & Damage flash screen
        overlay.color = new Color(Mathf.Clamp01(overlay.color.r - overlay_update_factor), Mathf.Clamp01(overlay.color.g - overlay_update_factor), Mathf.Clamp01(overlay.color.b - overlay_update_factor));

        if (controller.reloading)
        {
            icon_field.color = Color.red;
        }
        else
        {
            icon_field.color = Color.white;
        }

        //Turn on/off icon and ammo
        if (controller.equiped_item != null)
        {
            equip = controller.equiped_item.GetComponent <Equipable_generic>();
            icon_field.enabled = true;
            ammo_field.enabled = true;
        }
        else
        {
            equip = null;
            icon_field.enabled = false;
            ammo_field.enabled = false;
        }

        //Write to icon and ammo
        if (equip != null)
        {
            int ammo_num = 0;
            if (equip.item_type == Equipable_generic.ITEM_TYPE.gun)
            {
                ammo_num = equip.GetComponent <Gun_generic>().ammo;
            }
            else if (equip.item_type == Equipable_generic.ITEM_TYPE.ammo)
            {
                ammo_num = equip.GetComponent <Ammo_generic>().amount;
            }
            else if (equip.item_type == Equipable_generic.ITEM_TYPE.grenade)
            {
                ammo_num = equip.GetComponent <Grenade_generic>().ammo;
            }

            /*
             * if(equip.GetComponent<Equipable_generic>().hud_icon_anim != null)
             * {
             *  icon_field_anim.runtimeAnimatorController = equip.GetComponent<Equipable_generic>().hud_icon_anim;
             *  icon_field.sprite = null;
             * }
             * else */if (equip.hud_icon != null)
            {
                icon_field.sprite = equip.hud_icon;
                icon_field_anim.runtimeAnimatorController = null;
            }
            else
            {
                icon_field.sprite = missing_texture;
                icon_field_anim.runtimeAnimatorController = null;
            }
            ammo_field.text = ammo_num.ToString();
        }
        else
        {
            icon_field_anim.runtimeAnimatorController = null;
        }
    }