void Fire()
    {
        if (weaponChoice < particlePrefabs.Count)
        {
            GameObject projectile = Instantiate(particlePrefabs[weaponChoice], transform.position, transform.rotation);
            projectile.GetComponent <Particle2D>().mpPhysicsData.vel = projectile.transform.up * projectile.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;

            BouyancyForceGenerator2D bfg = new BouyancyForceGenerator2D(projectile.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg);
        }
        else if (weaponChoice == particlePrefabs.Count)
        {
            GameObject projectile1 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile1.GetComponent <Particle2D>().mpPhysicsData.vel = projectile1.transform.up * projectile1.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            GameObject projectile2 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.vel = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            Vector3 tmp = (projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos  = projectile2.transform.position;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos += new Vector2(tmp.x, tmp.y).normalized * 4.0f;
            projectile2.transform.position = projectile2.GetComponent <Particle2D>().mpPhysicsData.pos;

            SpringForceGenerator2D fg = new SpringForceGenerator2D(projectile1.GetComponent <Particle2D>(), projectile2.GetComponent <Particle2D>(), 1, 2);
            ForceManager.AddForceGenerator(fg);
            BouyancyForceGenerator2D bfg1 = new BouyancyForceGenerator2D(projectile1.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg1);
            BouyancyForceGenerator2D bfg2 = new BouyancyForceGenerator2D(projectile2.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg2);
        }
        else
        {
            GameObject projectile1 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile1.GetComponent <Particle2D>().mpPhysicsData.vel = projectile1.transform.up * projectile1.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            GameObject projectile2 = Instantiate(particlePrefabs[0], transform.position, transform.rotation);
            projectile2.GetComponent <Particle2D>().mpPhysicsData.vel = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            Vector3 tmp = projectile2.transform.up * projectile2.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos  = projectile2.transform.position;
            projectile2.GetComponent <Particle2D>().mpPhysicsData.pos += new Vector2(tmp.x, tmp.y).normalized * 3.0f;
            projectile2.transform.position = projectile2.GetComponent <Particle2D>().mpPhysicsData.pos;

            //<<<<<<< Updated upstream
            RodForceGenerator2D fg = new RodForceGenerator2D(projectile1.GetComponent <Particle2D>(), projectile2.GetComponent <Particle2D>(), 10, 3);
            ForceManager.AddForceGenerator(fg);
            //=======
            //            RodForceGenerator2D fg = new RodForceGenerator2D();
            //            fg.startingObject1 = projectile1.GetComponent<Particle2D>();
            //            fg.startingObject2 = projectile2.GetComponent<Particle2D>();
            //            //ForceManager.AddForceGenerator(fg);
            //>>>>>>> Stashed changes

            BouyancyForceGenerator2D bfg1 = new BouyancyForceGenerator2D(projectile1.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg1);
            BouyancyForceGenerator2D bfg2 = new BouyancyForceGenerator2D(projectile2.GetComponent <Particle2D>(), .5f, .25f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg2);
        }
    }
Esempio n. 2
0
    // Start is called before the first frame update
    void Start()
    {
        PlanetaryForceGenerator.powerOfConstant = powerOfConstant;

        particleManager = GetComponent <ParticleManager>();
        foreach (Particle2D par in GameObject.FindObjectsOfType <Particle2D>())
        {
            particleManager.AddParticle(par);
            ForceManager.AddForceGenerator(new PlanetaryForceGenerator(par));
        }
    }
Esempio n. 3
0
    void CheckForTarget()
    {
        if (target == null)
        {
            Vector3 pos = new Vector3(Random.Range(xRange.x, xRange.y), Random.Range(yRange.x, yRange.y), 0);
            target = Instantiate(targetPrefab, pos, Quaternion.identity);

            ForceManager.DeleteForceGenerator(bfg);
            bfg = new BouyancyForceGenerator2D(target.GetComponent <Particle2D>(), 1.0f, 0.5f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg);
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            Vector3 origin  = Camera.main.ScreenToWorldPoint(Input.mousePosition, Camera.MonoOrStereoscopicEye.Mono);
            Vector3 changeZ = new Vector3(origin.x, origin.y, asteroid.transform.position.z);

            //Instantiate(asteroid).transform.position = changeZ;
            //GetComponent<ParticleManager>().AddParticle(asteroid.GetComponent<Particle2D>());
            //ForceManager.AddForceGenerator(new PlanetaryForceGenerator(asteroid.GetComponent<Particle2D>()));

            GameObject obj = Instantiate(asteroid);
            obj.transform.position = changeZ;
            GetComponent <ParticleManager>().AddParticle(obj.GetComponent <Particle2D>());
            ForceManager.AddForceGenerator(new PlanetaryForceGenerator(obj.GetComponent <Particle2D>()));
        }
    }
    public void GenerateRandomParticle()
    {
        float x = Random.Range(-Camera.main.orthographicSize, Camera.main.orthographicSize);
        float y = Random.Range(-Camera.main.orthographicSize * Camera.main.aspect,
                               Camera.main.orthographicSize * Camera.main.aspect);
        GameObject newPar = Instantiate(particlePrefab, new Vector3(x, y, 0), Quaternion.identity);
        float      angle  = Random.Range(0.0f, 360.0f);

        newPar.GetComponent <Particle2D>().mpPhysicsData.vel = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0.0f)
                                                               * newPar.GetComponent <Particle2D>().mpPhysicsData.vel.magnitude;

        PlanetaryForceGenerator pfg = new PlanetaryForceGenerator(newPar.GetComponent <Particle2D>());

        ForceManager.AddForceGenerator(pfg);

        AddParticle(newPar.GetComponent <Particle2D>());

        //Vector2.Dot(new Vector2(), new Vector2());
    }
    //Create Target
    void CreateTarget(Vector3 targetPosition)
    {
        //Create Target & Set Position
        GameObject newTarget = Instantiate(target);

        //newTarget.transform.position = new Vector3(-2.75f, 3.26f, 0.0f);
        newTarget.transform.position = targetPosition;

        //Set Variables
        //particleManager.AddParticle(newTarget);
        newTarget.GetComponent <Target>().SetTargetVariables(newTarget);
        ForceGenerator2D bouyancyGenerator = forceManager.CreateBouyancyForceGenerator(newTarget, (waterSprite.transform.localScale.y) / 2.0f, 75.0f, 5.0f, -(waterSprite.transform.localScale.y) / 2.0f);

        forceManager.AddForceGenerator(bouyancyGenerator);
        newTarget.GetComponent <Target>().forceGen = bouyancyGenerator;

        //Update score
        score++;
        scoreText.text = "Score: " + score;
        isTarget       = true;
    }
Esempio n. 7
0
    public void CreateProjectile(GameObject projectile, Transform spawnPoint, Transform playerPos)
    {
        float           speed = 0.0f;
        Vector2         angle = new Vector2(spawnPoint.position.x - playerPos.position.x, spawnPoint.position.y - playerPos.position.y);
        Vector2         gravity;
        PhysicsObject2D proj;
        GameObject      part;

        switch (mCurrentWeaponType)
        {
        case WeaponType.SPRING:
        {
            speed = 20.0f;
            float speed2 = 15.0f;
            gravity = new Vector2(0.0f, -6.0f);

            float mass1, mass2;
            mass1 = 1.0f;
            mass2 = 2.0f;

            part = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation);
            mParticleManager.AddParticle(part.GetComponent <Particle2D>());
            proj = part.GetComponent <PhysicsObject2D>();
            proj.SetVel(angle * speed);
            proj.SetAcc(gravity);
            proj.SetInverseMass(mass1);
            proj.SetDamping(0.99f);
            mPhysicsObjects.Add(proj);

            PhysicsObject2D proj2;
            part  = Instantiate(projectile, spawnPoint.position - new Vector3(1.0f, 0.0f, 0.0f), spawnPoint.rotation);
            proj2 = part.GetComponent <PhysicsObject2D>();
            mParticleManager.AddParticle(part.GetComponent <Particle2D>());
            proj2.SetVel(angle * speed2);
            proj2.SetAcc(gravity);
            proj2.SetInverseMass(mass2);
            proj2.SetDamping(0.99f);
            mPhysicsObjects.Add(proj2);
            proj2.gameObject.AddComponent <DestroyOnExit>();

            SpringForceGenerator springForceGenerator = new SpringForceGenerator(proj, proj2, 1.0f, 50.0f, true);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(springForceGenerator);
            mForceManager.AddForceGenerator(springForceGenerator);
            BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
            bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
        }
        break;

        case WeaponType.ROD:
        {
            speed   = 30.0f;
            gravity = new Vector2(0.0f, -6.0f);

            proj = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation).GetComponent <PhysicsObject2D>();
            proj.SetVel(angle * speed);
            proj.SetAcc(gravity);
            proj.SetInverseMass(1.0f);
            proj.SetDamping(0.99f);
            mPhysicsObjects.Add(proj);

            PhysicsObject2D proj2;
            proj2 = Instantiate(projectile, spawnPoint.position + new Vector3(2.5f, 0.0f), spawnPoint.rotation).GetComponent <PhysicsObject2D>();
            proj2.SetVel(angle * speed);
            proj2.SetAcc(gravity);
            proj2.SetInverseMass(1.0f);
            proj2.SetDamping(0.99f);
            mPhysicsObjects.Add(proj2);
            proj2.gameObject.AddComponent <DestroyOnExit>();

            Particle2DLink link = new ParticleRod(proj, proj2, 5.0f);
            AddParticleLink(link);

            BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
            bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0);
            mForceManager.AddForceGenerator(bGenerator);
            proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator);
        }
        break;
        }
    }
Esempio n. 8
0
 private void Start()
 {
     ForceManager.AddForceGenerator(this);
 }
    void AddStyleToCollision(Particle2D obj1, Particle2D obj2)
    {
        bool       obj1Smaller = obj1.mpPhysicsData.inverseMass > obj2.mpPhysicsData.inverseMass;
        Particle2D lesserObj   = obj1Smaller ? obj1 : obj2;
        Particle2D greaterObj  = obj1Smaller ? obj2 : obj1;

        float greaterMass = greaterObj.GetMass();
        float lesserMass  = lesserObj.GetMass();

        if (lesserMass * ratioToIgnoreBreakage <= greaterMass)
        {
            greaterObj.AddMass(lesserMass);
            particlesToDelete.Add(lesserObj);
        }
        else if (1 - lesserMass / greaterMass < 1 / ratioToIgnoreBreakage)
        {
            greaterObj.AddMass(lesserMass);
            particlesToDelete.Add(lesserObj);
            greaterObj.mpPhysicsData.vel = (greaterObj.mpPhysicsData.vel + lesserObj.mpPhysicsData.vel).normalized * greaterObj.mpPhysicsData.vel.magnitude;

            Vector2 diff   = greaterObj.mpPhysicsData.pos - lesserObj.mpPhysicsData.pos;
            Vector2 offset = -diff.normalized * greaterObj.radius / diff.magnitude;

            greaterObj.mpPhysicsData.pos += offset;
            return;
        }
        else
        {
            float proportion = (lesserMass / greaterMass);
            greaterObj.AddMass(lesserMass * (1 - proportion));
            lesserObj.AddMass(-lesserMass * (1 - proportion));

            if (piecesPlanetsBreakInto > 1)
            {
                GameObject[] newParts = new GameObject[piecesPlanetsBreakInto];
                lesserMass = lesserObj.GetMass();
                for (int i = 0; i < piecesPlanetsBreakInto; i++)
                {
                    newParts[i] = Instantiate(lesserObj.gameObject, lesserObj.transform.position, lesserObj.transform.rotation);
                }

                float   angleSpread = 180.0f / (piecesPlanetsBreakInto + 1);
                Vector2 oldVec      = lesserObj.mpPhysicsData.vel;
                Vector2 newVel      = new Vector2(Mathf.Cos(180) * oldVec.x - Mathf.Sin(180) * oldVec.y,
                                                  Mathf.Sin(180) * oldVec.x + Mathf.Cos(180) * oldVec.y);

                for (int i = 0; i < piecesPlanetsBreakInto; i++)
                {
                    Particle2D par = newParts[i].GetComponent <Particle2D>();
                    par.AddMass(-(lesserMass * (1 - 1.0f / piecesPlanetsBreakInto)));
                    newVel = new Vector2(Mathf.Cos(angleSpread) * newVel.x - Mathf.Sin(angleSpread) * newVel.y,
                                         Mathf.Sin(angleSpread) * newVel.x + Mathf.Cos(angleSpread) * newVel.y);
                    par.mpPhysicsData.vel          = newVel;                                                                           //* piecesPlanetsBreakInto;
                    par.mpPhysicsData.pos         += newVel.normalized * (1.0f / (Mathf.Cos(90 - (angleSpread / 2.0f)) / par.radius)); // par.radius/2);
                    newParts[i].transform.position = par.mpPhysicsData.pos;
                    newParts[i].GetComponent <Particle2D>().mpPhysicsData = par.mpPhysicsData;
                    AddParticle(newParts[i].GetComponent <Particle2D>());
                    ForceManager.AddForceGenerator(new PlanetaryForceGenerator(newParts[i].GetComponent <Particle2D>()));
                }
                particlesToDelete.Add(lesserObj);
            }
        }
    }