Esempio n. 1
0
    //obj in this case is always the empty prefab
    public void SpawnPaint(Vector3 pos, PlayerScript.PaintColors color)
    {
        Debug.Log("spawning paint at position: " + pos);
        if (spawnedPaints.ContainsKey(pos))
        {
            Destroy(spawnedPaints[pos]);
            spawnedPaints.Remove(pos);
        }


        if (color == PlayerScript.PaintColors.Blue)
        {
            Debug.Log("spwaning blue");
            GameObject g = Instantiate(bluePrefab, pos, Quaternion.identity);
            spawnedPaints.Add(pos, g);
            //g.AddComponent<BluePaint>();
        }
        else
        {
            GameObject g = Instantiate(emptyPrefab, pos, Quaternion.identity);
            spawnedPaints.Add(pos, g);

            if (color == PlayerScript.PaintColors.Yellow)
            {
                g.tag = "Yellow";
                g.AddComponent <YellowPaint>();
            }
            if (color == PlayerScript.PaintColors.Red)
            {
                Debug.Log("here");
                g.AddComponent <RedPaint>();
            }
        }
    }
Esempio n. 2
0
    IEnumerator SelfCastSeq()
    {
        PlayerScript player = GetComponentInParent <PlayerScript>();

        PlayerScript.PaintColors color = GetComponentInParent <PlayerScript>().currColor;



        if (!is_colored)
        {
            StartCoroutine(GetComponentInParent <PlayerScript>().WaitSeq("SelfCast", 0.5f));

            yield return(new WaitForSeconds(0.5f));

            bool   go         = true;
            string prefabName = PlayerScript.paintPrefabs[color];
            if (color == PlayerScript.PaintColors.Orange)
            {
                if (p.GetComponent <PlayerScript>().o_val <= 0)
                {
                    go = false;
                }
                else
                {
                    tracker = p.GetComponent <OrangePaint>().Change(50, rendy.color, rendy);
                }
            }
            else if (color == PlayerScript.PaintColors.Green)
            {
                if (p.GetComponent <PlayerScript>().g_val <= 0)
                {
                    go = false;
                }
                else
                {
                    tracker = p.GetComponent <GreenPaint>().Change(50, rendy.color, rendy);
                }
            }
            else if (color == PlayerScript.PaintColors.Purple)
            {
                if (p.GetComponent <PlayerScript>().p_val <= 0)
                {
                    go = false;
                }
                else
                {
                    tracker = p.GetComponent <PurplePaint>().Change(50, rendy.color, rendy);
                }
            }
            if (go)
            {
                StartCoroutine(tracker); // Needs to be fixed for other/ curr color.
                Debug.Log("OKKKK");
                p.GetComponent <PlayerScript>().ui.GetComponent <HealthUI>().DecreasePaint(prefabName);
            }
        }
    }
Esempio n. 3
0
    void Shoot(PlayerScript.PaintColors color)
    {
        string prefabName = PlayerScript.paintPrefabs[color];

        GameObject obj   = (GameObject)Instantiate(Resources.Load("Prefabs/" + prefabName), transform.position, transform.rotation);
        Vector3    force = Vector3.Normalize(transform.position - paintStartPoint.transform.position) * hoseForce;

        obj.GetComponent <Rigidbody2D>().AddForce(force);
        //Debug.Log("shooting" + force.x + ", " + force.y + ", " + force.z);
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        //too lazy to refactor this
        ResetTracers();
        Vector3 point = new Vector3();

        PlayerScript.PaintColors color = GetComponentInParent <PlayerScript>().currColor;

        //Debug.Log("mouseDown = " + Input.mousePosition.x + " " + Input.mousePosition.y);

        point = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
        //Debug.Log("Point: " + point);
        PlayerScript player = GetComponentInParent <PlayerScript>();
        //Debug.Log("Self: " + transform.position);
        //Debug.Log("Magnitude: " + Vector3.Magnitude(point - transform.position));
        bool       facingRight       = player.facingRight;
        GameObject paintSpawnerToUse = null;

        if ((facingRight && point.x < sideSpawner.transform.position.x) || !facingRight && point.x > sideSpawner.transform.position.x)
        {
            float paintspawnerDist = Mathf.Abs(sideSpawner.transform.position.x - player.transform.position.x);
            if (Mathf.Abs(point.x - player.transform.position.x) < paintspawnerDist)
            {
                if (point.y > topSpawner.transform.position.y)
                {
                    paintSpawnerToUse = topSpawner;
                }
                else if (point.y < bottomSpawner.transform.position.y && player.feetContact == 0)
                {
                    Debug.Log("feet contact: " + player.feetContact);
                    paintSpawnerToUse = bottomSpawner;
                    //Debug.Log("USINGBOT SPAWNER!");
                }
            }
        }
        else
        {
            paintSpawnerToUse = sideSpawner;
        }

        if (shootableColors.Contains(color) && paintSpawnerToUse != null)
        {
            Vector3 force = Vector3.Normalize(point - paintSpawnerToUse.transform.position) * Mathf.Min(Vector3.Magnitude(point - paintSpawnerToUse.transform.position) * forceMultiplier, maxForceMagnitude);
            force.z = 0;

            PredictionLine(force, paintSpawnerToUse.transform.position);

            if (Input.GetMouseButtonDown(0))
            {
                string prefabName = PlayerScript.paintPrefabs[color];

                if (p.GetComponent <PlayerScript>().ui.GetComponent <HealthUI>().DecreasePaint(prefabName))
                {
                    StartCoroutine(GetComponentInParent <PlayerScript>().WaitSeq("Attack", 0.5f));

                    GameObject obj = (GameObject)Instantiate(Resources.Load("Prefabs/" + prefabName), paintSpawnerToUse.transform.position, paintSpawnerToUse.transform.rotation);

                    //Debug.Log("Force: " + force);

                    obj.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse);
                }
            }
        }



        //left click
        //testPredictionLine();


        //right click
        if (Input.GetMouseButtonDown(1))
        {
            StartCoroutine(SelfCastSeq());
        }
    }