Inheritance: MonoBehaviour
コード例 #1
0
    void OnTriggerEnter2D(Collider2D other)  //TODO
    {
        BlazeFoxController controller = other.GetComponent <BlazeFoxController>();

        if (controller != null)
        {
            controller.changeHealth(1);
        }
        projectile noTouch = other.GetComponent <projectile>();

        if (noTouch != null)
        {
            return;
        }

        if (other.tag == "projectile platform")
        {
            speed     = 0;
            TempSpeed = 0;
            return;
        }
        if (other.tag == "ground")
        {
            HighScore.instance.changeScore(1);
        }
        Instantiate(Particle, transform.position, Quaternion.identity);
        Destroy(gameObject);
    }
コード例 #2
0
ファイル: myServe.cs プロジェクト: coreyschulz/space-wars
 public void checkIfOffScreen(projectile pro, bool extra)
 {
     if (extra == false) // If Touhou is off, make the projectiles kill when they get offscreen.
     {
         if (pro.GetLocation().GetX() > universeSize / 2 + 50 || pro.GetLocation().GetX() < -universeSize / 2 - 50)
         {
             pro.kill();
         }
         if (pro.GetLocation().GetY() > universeSize / 2 + 50 || pro.GetLocation().GetY() < -universeSize / 2 - 50)
         {
             pro.kill();
         }
     }
     else
     {
         if (pro.GetLocation().GetX() > universeSize / 2 || pro.GetLocation().GetX() < -universeSize / 2)
         {
             //we will want it to keep the y position and just rotate to the other side of the screen.
             double   yLocation    = pro.GetLocation().GetY();
             double   oldxLocation = pro.GetLocation().GetX();
             Vector2D newLocation  = new Vector2D(-(oldxLocation), yLocation);
             //Set the projectile location to the new location
             pro.setLocation(newLocation);
         }
         if (pro.GetLocation().GetY() > universeSize / 2 || pro.GetLocation().GetY() < -universeSize / 2)
         {
             //we will want it to keep the y position and just rotate to the other side of the screen.
             double   yLocation   = pro.GetLocation().GetY();
             double   xLocation   = pro.GetLocation().GetX();
             Vector2D newLocation = new Vector2D(xLocation, -yLocation);
             pro.setLocation(newLocation); // Set projectile to modified location.
         }
     }
 }
コード例 #3
0
    public void FireProjectile(Vector2 dirNormal)
    {
        GameObject portaleffectPrefab = Resources.Load("Portaleffect") as GameObject;
        GameObject Portaleffect       = Instantiate(portaleffectPrefab);
        Vector3    playerPos          = _fireposition.transform.position;
        projectile proj = Portaleffect.GetComponent <projectile>();

        proj.Init(dirNormal);
        ParticleSystem ps = Portaleffect.GetComponent <ParticleSystem>();

        //float offset_x = 0.0f;
        //float offset_y = 0.0f;
        float offset_z = 0.0f;

        if (_right)
        {
            //offset_x = 1.0f;
            // offset_y = 0.3f;
            offset_z         = -1.0f;
            proj._flyForce  += -1.0f;
            ps.startRotation = Mathf.Deg2Rad * -90.0f;
        }
        else
        {
            //offset_x = -1.0f;
            // offset_y = -0.3f;
            offset_z         = 1.0f;
            proj._flyForce  *= 1.0f;
            ps.startRotation = Mathf.Deg2Rad * 90.0f;
        }
        Portaleffect.transform.position = new Vector3(playerPos.x, playerPos.y, playerPos.z * offset_z);
    }
コード例 #4
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        // 우클릭 이동
        if (Physics.Raycast(ray, out hit, 1000) && Input.GetMouseButton(1))
        {
            if (hit.transform.name != "Player")
            {
                GetComponent <NavMeshAgent>().isStopped   = false;
                GetComponent <NavMeshAgent>().destination = hit.point;
            }
        }

        // 좌클릭 사격
        if (Physics.Raycast(ray, out hit, 1000) && Input.GetMouseButtonDown(0))
        {
            if (hit.transform.name != "Player")
            {
                projectile p = Instantiate(proj, transform.position, Quaternion.identity);
                p.fire(hit.point - transform.position);
            }
        }

        // 정지
        if (Input.GetKeyDown(KeyCode.S))
        {
            GetComponent <NavMeshAgent>().isStopped = true;
        }
    }
コード例 #5
0
        public void TestProjectileMethod()
        {
            world world1 = new world();

            projectile p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1);
            star       s = new star(0, new Vector2D(0, 0), 1);

            world1.addStar(s);
            String     A  = p.ToString();
            projectile s1 = JsonConvert.DeserializeObject <projectile>(A);

            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            Assert.AreEqual(p.getID(), 0);
            Assert.AreEqual(new Vector2D(0, 0), p.getloc());
            Assert.AreEqual(new Vector2D(0, 0), p.getdir());
            Assert.AreEqual(p.checkAlive(), true);
            Assert.AreEqual(p.getOwner(), 1);
            p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1);
            p.update(750, world1.getStar().Values);
            p.die();

            projectile p1 = new projectile(1, new Vector2D(0, 376), new Vector2D(0, 0), true, 2);

            p1.update(750, world1.getStar().Values);
        }
コード例 #6
0
ファイル: myServe.cs プロジェクト: coreyschulz/space-wars
        /// <summary>
        /// Fires the projectile in a line from the ship, straight.
        /// </summary>
        /// <param name="proj"></param>
        private void updateProjectileLocation(projectile proj, star starry)
        {
            if (bulletGravity == false)
            {
                Vector2D direction = proj.GetDirections(); // We have the direction
                direction *= projectileSpeed;

                proj.loc = proj.loc + direction;// Apply new velocity to position.

                checkIfOffScreen(proj, touhouMode);
            }
            else
            {
                Vector2D gravity = starry.loc - proj.loc; // Find the vector from the ship to the star.
                gravity.Normalize();                      // Turn the vector into a unit-length direction by normalizing.
                gravity *= starry.mass;                   // Adjust strentth of vector by multiplying star's mass.

                Vector2D thrust = new Vector2D(0, 0);     // no thrust for you.

                Vector2D acceleration = gravity + thrust; // combine all forces.

                proj.velocity += acceleration;            // Add acceleration to velocity.

                proj.loc = proj.loc + proj.velocity;      // Apply new velocity to position.

                checkIfOffScreen(proj, touhouMode);       // Wraparound if offscreen.
            }
        }
コード例 #7
0
    public virtual void fire()
    {
        canfire = false;
        if (Time.time < nextFireAllowed)
        {
            return;
        }

        if (reloader != null)
        {
            if (reloader.isReloading)
            {
                return;
            }

            if (reloader.RoundRemainingInClip == 0)
            {
                return;
            }

            reloader.TakeFromClip(1);
        }

        nextFireAllowed = Time.time + rateoffire;

        bool islocalPlayerControllrd = AimTarget == null;

        if (!islocalPlayerControllrd)
        {
            muzzle.LookAt(AimTarget.position + AimTargetOffSet);
        }


        projectile newbullet = (projectile )Instantiate(Projectile, muzzle.position, muzzle.rotation);

        if (islocalPlayerControllrd)
        {
            Ray ray = Camera.main.ViewportPointToRay(new Vector3(.5f, .5f, 0));

            RaycastHit hit;
            Vector3    targetPosition = ray.GetPoint(500);

            if (Physics.Raycast(ray, out hit))
            {
                targetPosition = hit.point;
            }

            newbullet.transform.LookAt(targetPosition + AimTargetOffSet);
        }
        if (this.Weaponrecoil)
        {
            this.Weaponrecoil.Activate();
        }

        FireEffect();
        audioFire.play();

        canfire = true;
    }
コード例 #8
0
ファイル: world.cs プロジェクト: jiiehe/SpaceWars
 /// <summary>
 /// fire projectile for a ship
 /// </summary>
 /// <param name="shipID"></param>
 public void Fire(int shipID)
 {
     if (shipgroup[shipID].checkFire(this.time, this.shootFrame))
     {
         projectile proj = new projectile(generatePorj(), shipgroup[shipID].getloc(), shipgroup[shipID].getdir(), true, shipID);
         this.projectileGroup[proj.getID()] = proj;
     }
 }
コード例 #9
0
ファイル: Entities.cs プロジェクト: coreyschulz/space-wars
        /// <summary>
        /// Creates a projectile from passed in ship.
        /// </summary>
        /// <param name="ship_"></param>
        public void createProjectile(ship ship_)
        {
            Vector2D   dur     = new Vector2D(ship_.dir.GetX(), ship_.dir.GetY());
            projectile project = new projectile(countOfProjectil, ship_.ID, ship_.loc, dur);

            projectilesInWorld.TryAdd(countOfProjectil, project);
            countOfProjectil++;
        }
コード例 #10
0
    public static void spawnProjectile(projectile proj, Vector3 pos, Vector3 velocity, float shootRange = 20, Transform owner = null)
    {
        projectile thisProjectile = proj.Spawn(pos);

        thisProjectile.Owner = owner;

        thisProjectile.startShoot(velocity, shootRange);
    }
コード例 #11
0
 public void ReturnToPool(projectile pr)
 {
     pr.gameObject.SetActive(false);
     pr.transform.position = Vector3.zero;
     pr.transform.rotation = Quaternion.identity;
     pr.RB.angularVelocity = Vector3.zero;
     pr.RB.velocity        = Vector3.zero;
     bullets.Push(pr);
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: jiiehe/SpaceWars
        /// <summary>
        /// drawing the projectile
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void drawProjectile(object o, PaintEventArgs e)
        {
            int        projWidth = 20;
            projectile s         = o as projectile;

            Image image = arrays2[s.getOwner() % arrays2.Length];

            e.Graphics.DrawImage(image, 0 - (projWidth / 2), 0 - (projWidth / 2), projWidth, projWidth);
        }
コード例 #13
0
 void OnTriggerEnter(Collider collider)
 {
     if (collider.tag == "projectile")
     {
         projectile proj = collider.GetComponentInParent <projectile>();
         proj.destroy();
         divideAsteroid();
     }
 }
コード例 #14
0
 public void ShootAndStun(projectile bullet, Transform target, AnimationCurve arc)
 {
     Physic = Random.Range(MinDmg, MaxDmg);
     Fire   = 0;
     Water  = 0;
     Air    = 0;
     Earth  = 0;
     bullet.Seek(target, Physic, Fire, Water, Air, Earth, AOEradius, arc);
 }
コード例 #15
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        projectile projectile = collision.GetComponent <projectile>();

        if (collision.name == ("Projectile 1(Clone)"))
        {
            Destroy(gameObject);
        }
        //Debug.Log("Brick//: " + collision.name);
    }
コード例 #16
0
    void Shoot()
    {
        GameObject bulletGO = (GameObject)Instantiate(ProjectailPrefab, firePoint.position, firePoint.rotation);
        projectile bullet   = bulletGO.GetComponent <projectile>();

        if (bullet != null)
        {
            Stats.Shoot(bullet, target, bularc);
        }
    }
コード例 #17
0
 public void Shoot(projectile bullet, Transform target, AnimationCurve arc)
 {
     Physic = Random.Range(MinDmg, MaxDmg);
     Fire   = Physic * FireParcent;
     Water  = Physic * WaterParcent;
     Air    = Physic * AirParcent;
     Earth  = Physic * EarthParcent;
     Enemy  = target.gameObject.GetComponent <EnemyStats>();
     bullet.Seek(target, Physic, Fire, Water, Air, Earth, AOEradius, arc);
 }
コード例 #18
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("BroomTrigger") && state == State.Broom)
        {
            other.SendMessage("OnBroomCollide");
        }

        if (other.CompareTag("Liftable") && AtlasInputManager.getKeyPressed("Up", true))
        {
            liftObject(other.gameObject);
        }

        if (other.CompareTag("ResetDamaging"))
        {
            if (graceFrames > 0)
            {
                graceFrames--;
            }
            else
            {
                resetPosition = true;
            }
        }
        ;

        if (other.CompareTag("ResetDrown"))
        {
            drown();
        }

        if (intangibleStates.Contains(state))
        {
            return;
        }
        if (other.gameObject.layer == LayerMask.NameToLayer("Danger") && (!invulnerable || other.CompareTag("ResetDamaging")))
        {
            if (other.CompareTag("ResetDamaging") && graceFrames > 0)
            {
                return;
            }

            if (other.CompareTag("Projectile"))
            {
                projectile p = other.GetComponent <projectile>();
                if (p.hurtPlayer)
                {
                    p.hit();
                }
            }

            startBonk(1, resetPosition);

            return;
        }
    }
コード例 #19
0
 void Awake()
 {
     bullets = new Stack <projectile>(maxCapacity);
     for (int i = 0; i < 24; i++)
     {
         projectile pr = Instantiate(projectilePrefab);
         pr.gameObject.SetActive(false);
         bullets.Push(pr);
         pr.GetComponent <projectile>().Pool = this;
     }
 }
コード例 #20
0
 void OnTriggerEnter(Collider collider)
 {
     if (collider.tag == "projectile")
     {
         projectile proj = collider.GetComponentInParent <projectile>();
         proj.destroy();
         int       i          = Random.Range(0, 100) % powerupNum;
         Rigidbody newPowerup = Instantiate(powerUps[i], transform.position, transform.rotation);
         Destroy(this.gameObject);
     }
 }
コード例 #21
0
 public void shoot()
 {
     if (Time.time > nextShotTime)
     {
         nextShotTime = randomness + Time.time + (msBetweenShots * (2 - reloadMultiplier)) / 1000; // milliseconds to seconds, =  1500 * ( 2 - 1+0.05 * 10) which is half speed
         randomness   = 0;
         projectile newBullet = Instantiate(bullet, bulletOrigin.position, bulletOrigin.rotation) as projectile;
         newBullet.setSpeed(bulletVelocity * bltSpeedMultiplier); // simple, speed * 1 or 1.1 all the way up tp 2 double speed
         newBullet.bulletDmg = newBullet.bulletDmg * dmgMultiplier;
     }
 }
コード例 #22
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        projectile projectile = collision.GetComponent <projectile>();

        //Debug.Log("Star Col//: " + collision.gameObject.tag);
        BlockDestroyed();
        if (gameObject.name == "star")
        {
            SceneManager.LoadScene(2);
        }
    }
コード例 #23
0
ファイル: Enemy.cs プロジェクト: GillianYue/Bubbla
    IEnumerator launchProjectiles()
    {
        //wait for 2 reasons: 1) enemy's position is set relatively late (might provide wrong source loc for projectile)
        //2) more fair to start launch projectile after enemy visually shows up in screen
        yield return(new WaitUntil(() => Global.gameObjectInView(transform)));

        while (true)
        {
            if (genProjectile && projectileSprite && Global.percentChance((int)(shootChanceIndividual * 100)))
            {
                GameObject p = Instantiate(myProjectilePrefab, this.transform.localPosition, myProjectilePrefab.transform.rotation);
                p.transform.parent = null;
                p.SetActive(true);
                p.GetComponent <SpriteRenderer>().sprite = projectileSprite;
                Destroy(p.GetComponent <CircleCollider2D>());
                CircleCollider2D circ = p.AddComponent <CircleCollider2D>();                //TODO check here; supposedly auto generates appropriately sized collider
                circ.isTrigger = true;

                p.transform.localScale = transform.lossyScale;

                projectile proj = p.GetComponent <projectile>();
                proj.damage = projectileAttack;
                proj.setSpeed(projectileSpeed);
                proj.setAcceleration(projectileAccl);

                Vector3 direction = Vector3.down; float angle = 0; bool rotateProjectile = false;
                switch (projectileType)
                {
                case 0:
                    break;

                case 1:
                    direction = gameControl.player.transform.position - transform.position;
                    float tan = direction.x / direction.y;
                    angle = Mathf.Atan(tan);
                    if (direction.y > 0)
                    {
                        Destroy(proj);                                              //if player is above, this type of projectile will not be launched
                    }
                    rotateProjectile = true;
                    break;
                }

                if (proj)
                {
                    proj.setDirection(direction, angle, rotateProjectile);
                }
            }

            //effectively, noise = 0.2 will make shoot time range from 0.8x to 1.2x
            yield return(new WaitForSeconds(shootInterval + Random.Range(-shootNoise, shootNoise) * shootInterval));
        }
    }
コード例 #24
0
 public void StartTrail(projectile proj)
 {
     FollowTransform    = proj.transform;
     transform.position = proj.transform.position;
     if (part)
     {
         part.Clear();
         part.Play();
         //part.enableEmission=true;
         StartCoroutine(StartEmitting());
     }
 }
コード例 #25
0
 void Flip(projectile projectileInstance)
 {
     if (transform.localScale.x <= 0)
     {
         projectileInstance.transform.localScale = new Vector3(-projectileInstance.transform.localScale.x, projectileInstance.transform.localScale.y, projectileInstance.transform.localScale.z);
         projectileInstance.speed = 0 - projectileSpeed;
     }
     else
     {
         projectileInstance.speed = projectileSpeed;
     }
 }
コード例 #26
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     //sound.Play();
     tile = other.gameObject.GetComponent <projectile>();
     if (tile)
     {
         Health -= tile.GetDamage();
         if (Health <= 0)
         {
             Died();
         }
     }
 }
コード例 #27
0
ファイル: projectile.cs プロジェクト: TsarCorp/ForTheWind3D
    void OnCollisionEnter(Collision collision)
    {
        projectile projectile = collision.gameObject.GetComponent <projectile>();

        if (collision.collider.tag == "anyShip")
        {
            if (projectile)
            {
                Destroy(gameObject);
                AudioSource.PlayClipAtPoint(hitSound1, transform.position);
            }
        }
    }
コード例 #28
0
 public void Fire()
 {
     if (projectileSpawnpoint)
     {
         projectile projectileInstance = Instantiate(projectilePrefab, projectileSpawnpoint.position, projectileSpawnpoint.rotation);
         flip(projectileInstance);
     }
     else
     {
         projectile projectileInstance = Instantiate(projectilePrefab, projectileSpawnpoint.position, projectileSpawnpoint.rotation);
         flip(projectileInstance);
     }
 }
コード例 #29
0
 void FireProjectile()
 {
     if (!movement.isCrouching)
     {
         projectile projectileInstance = Instantiate(projectilePrefab, spawnPointStanding.position, spawnPointStanding.rotation);
         Flip(projectileInstance);
     }
     else
     {
         projectile projectileInstance = Instantiate(projectilePrefab, spawnPointCrouch.position, spawnPointCrouch.rotation);
         Flip(projectileInstance);
     }
 }
コード例 #30
0
    void ShootStunFirePoint()
    {
        if (StunFirePoint == true)
        {
            GameObject bulletGO3      = (GameObject)Instantiate(ProjectailStunPrefab, stunFirePoint.position, stunFirePoint.rotation);
            projectile stunningBullet = bulletGO3.GetComponent <StunningBullet>();
            Stats.ShootAndStun(stunningBullet, target, stunningBulletarc);

            if (stunningBullet != null)
            {
                Stats.ShootAndStun(stunningBullet, target, stunningBulletarc);
            }
        }
    }