Inheritance: MonoBehaviour
Esempio n. 1
0
    void Update()
    {
        if (!canShoot && !isWrecked)
        {
            shootTimer -= Time.deltaTime;
            if (shootTimer <= 0f)
            {
                canShoot   = true;
                shootTimer = timeBetweenShots;
            }
        }

        if (fireLeft)
        {
            if (canShoot)
            {
                CannonBall cannonBallClone = Instantiate(cannonBall, leftGun.position, leftGun.rotation) as CannonBall;
                //fireLeft = false;
                canShoot = false;
            }
        }
        else if (fireRight)
        {
            if (canShoot)
            {
                CannonBall cannonBallClone = Instantiate(cannonBall, rightGun.position, rightGun.rotation) as CannonBall;
                //fireLeft = false;
                canShoot = false;
            }
        }
    }
    //function for the friction on the horizontal ground
    void applyFrictionOfGround(CannonBall ball)
    {
        //use a friction coefficient to decelerate the ball
        float frictionCoeff = 0.95f;

        ball.addVelocity(new Vector2(-ball.getVelocity().x *(1 - frictionCoeff), 0));
    }
Esempio n. 3
0
    public IEnumerator dropDemonicBalls()
    {
        if (timeToWaitToDrop > 0.0f)
        {
            yield return(new WaitForSeconds(timeToWaitToDrop));
        }

        for (int i = 0; i < numDrops; i++)
        {
            CannonBall ball = createDemonicBall();

            if (i == (numDrops - 1))
            {
                ball.ammoDeathCb = delegate(Ammo ammo)
                {
                    character.setFeetPos(ammo.transform.position);
                    character.changeAnimation("emerge", onEndAttack);
                    character.faceTarget();
                    character.canBeAttacked = true;
                };
            }
            else
            {
                if (timeBetweenDrops != null && timeBetweenDrops.Length > 0)
                {
                    int index = i;
                    index = Mathf.Min(index, timeBetweenDrops.Length - 1);
                    yield return(new WaitForSeconds(timeBetweenDrops[index]));
                }
            }
        }

        yield return(0);
    }
Esempio n. 4
0
    public void Shoot()
    {
        // Check cooldown timer to see if we can shoot

        if (canShoot)
        {
            // Instantiate cannon ball - fix
            GameObject firedCannonBall = Instantiate(cannonBallPrefab, firePoint.transform.position, firePoint.transform.rotation);


            // Shoot the cannon ball forward with Rigidbody.AddForce()
            firedCannonBall.GetComponent <Rigidbody>().AddForce(transform.forward * ballSpeed);

            // Cannon ball data needed: who, and how much damage will it cause
            CannonBall cannonBall = firedCannonBall.GetComponent <CannonBall>();
            cannonBall.attacker     = this.gameObject;
            cannonBall.attackDamage = data.cannonBallDamage;

            Debug.Log("Instantiate success");

            //Can no longer shoot, have to wait for timer to expire to shoot again
            canShoot = false;
            ResetTimer();
        }
    }
Esempio n. 5
0
 public void Teleport(CannonBall ball, Vector3 velocity)
 {
     ball.transform.position  = muzzle.position;
     ball._Renderer.enabled   = true;
     ball._Collider.enabled   = true;
     ball._Rigidbody.velocity = muzzle.forward * velocity.magnitude;
 }
    private void Update()
    {
        float hozAxis = Input.GetAxis("Horizontal");

        if (!Mathf.Approximately(hozAxis, 0.0f))
        {
            m_pivot.Rotate(Vector3.up, hozAxis * m_rotateSpeed);
        }

        m_lastFire += Time.deltaTime;
        if (m_lastFire >= m_fireRate)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                CannonBall ball = Instantiate(m_cannonBall, m_turret.position, m_turret.rotation);
                ball.Shoot((m_turret.position - m_origin.position).normalized);

                // Play the particles & sfx
                m_particles.Play();
                AudioEvent e = Helpers.RandomElement(m_cannonBlasts);
                AudioController.Instance.PlaySfx(e);

                m_lastFire = 0.0f;
            }
        }
        else
        {
            float scale_t = Mathf.Clamp01(m_lastFire / m_fireRate);
            m_turret.localScale = Vector3.Lerp(new Vector3(1.5f, 1.5f, 1.5f), Vector3.one, scale_t);
        }
    }
    /// <summary>
    /// 当数组中炮弹不够使用时,实例化新的炮弹,并赋值到数组中
    /// </summary>
    /// <param name="ball"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    CannonBall InitNewCannonBall(BulletType type)
    {
        int        index         = (int)type;
        CannonBall newCannonBall = null;

        //遍历数组找到未被利用的子弹
        for (int i = 0; i < initCount_CannonBall[index]; i++)
        {
            if (cannonBall[index][i])                                   //当前引用不为空
            {
                if (!cannonBall[index][i].gameObject.activeInHierarchy) //当前未被使用
                {
                    newCannonBall = cannonBall[index][i];
                    break;
                }
            }
            else                                                                                      //当前引用为空!
            {
                newCannonBall = cannonBall[index][i] = Instantiate(cannonballs[index]) as CannonBall; //赋值
                break;
            }
        }
        //如果所有子弹全部都在被利用,建立新的数组,并扩大存储上限
        if (null == newCannonBall)
        {
            CannonBall[] newCannonBalls = new CannonBall[initCount_CannonBall[index] + 8];
            Array.Copy(cannonBall[index], newCannonBalls, initCount_CannonBall[index]);
            useIndex_CannonBall[index]   = initCount_CannonBall[index];
            initCount_CannonBall[index] += 8;
            cannonBall[index]            = newCannonBalls; //赋值给缓存
        }
        newCannonBall = cannonBall[index][useIndex_CannonBall[index]] = Instantiate(cannonballs[index]) as CannonBall;
        return(newCannonBall);
    }
    //function for changing the string motion after it's collided with cannon ball (the string shouldn't intersect will cannon ball)
    //the paramters are the cannon ball and the balloon whose string is collided with, and also the position of the two end of the line segment of the string
    void movingAfterCannonBallCollision(CannonBall ball, Balloon balloon, Vector3 startPoint, Vector3 endPoint)
    {
        //find the 2 Point objects of the balloon string according to the startPoint and endPoint
        //Balloon.Point point1 = null;
        Balloon.Point point2    = null;
        ArrayList     strPoints = balloon.getStringPoints();

        for (int i = 0; i < strPoints.Count; i++)
        {
            /*
             * if( ((Balloon.Point) strPoints[i]).getPosition().Equals(startPoint))
             * {
             *  point1 = (Balloon.Point) strPoints[i];
             * }*/
            if (((Balloon.Point)strPoints[i]).getPosition().Equals(endPoint))
            {
                point2 = (Balloon.Point)strPoints[i];
            }
        }


        Vector2 unitNormal = CollisionCalculation.getNormal(startPoint.x, startPoint.y, point2.getPosition().x, point2.getPosition().y); //calculate the unit normal of the line
        float   epsilon    = 0.1f;                                                                                                       //the coefficient of restitution (0~1, when it's 1 we have perfect bouncing)
        float   mass       = 1f;                                                                                                         //mass of the string

        float VnCollided = unitNormal.x * ball.getVelocity().x + unitNormal.y * ball.getVelocity().y;                                    //Vn-: the normal component of collided velocity = dot product of normal and velocity

        float   j       = -(1 + epsilon) * mass * VnCollided;                                                                            //the impulse scalar j = -(1+epsilon) * m * Vn-
        Vector2 impulse = -j * unitNormal;                                                                                               //the force will apply to the line, not the cannon ball, so we use negative of the impulse

        point2.setAcceleration((impulse / mass));                                                                                        //update the acceleration based on the impulse
    }
        private void AddCannonBall(Vector2 position)
        {
            CannonBall cannonBall = new CannonBall();

            cannonBall.Initialize(GraphicsDevice.Viewport, cannonBallTexture, new Vector2(player.Position.X, random.Next(100, GraphicsDevice.Viewport.Height - 100)));
            cannonBalls.Add(cannonBall);
        }
Esempio n. 10
0
    void Shoot()
    {
        GameObject cb       = Instantiate(cannonBall, barrel.position, barrel.rotation);
        CannonBall cbScript = cb.GetComponent <CannonBall>();

        cbScript.speed = ballSpeed;
        cbScript.GoFast();
    }
 protected override void Start()
 {
     base.Start();
     m_player = FindObjectOfType <CannonBall>();
     StartCoroutine(animateChangingAmountOfMoney((int)m_player.Experience));
     m_player.OnExperienceAdded     += (experienceCount) => StartCoroutine(animateChangingAmountOfMoney((int)experienceCount));
     m_player.OnExperienceDecreased += (experienceCount) => StartCoroutine(animateChangingAmountOfMoney(-(int)experienceCount));
 }
Esempio n. 12
0
 public void OnReceiveDamage(CannonBall cannonball)
 {
     if (cannonball.data.belongTo == transform)
     {
         return;
     }
     //TODO
     BrokenState(0); //根据损坏程度,显示不同的毁坏状态
 }
Esempio n. 13
0
    private void Fire(float force)
    {
        //Disparo
        smokeParticles.Play();
        CannonBall bullet = Instantiate(cannonBallPrefab, muzzle.position, muzzle.rotation);

        bullet.PlaySound(shootSound);//Lo sonamos desde la bala porque cada bala es una instancia diferencte con su propio audioSource
        bullet._Rigidbody.AddForce(muzzle.forward * force, ForceMode.Impulse);
    }
Esempio n. 14
0
        protected override void LaunchProjectile(Enemy enemy)
        {
            CannonBall projectile = Instantiate(_projectile, transform.position, Quaternion.identity).GetComponent <CannonBall>();

            // Update stats
            projectile.Speed  = CurrentLevelInfo.projectileSpeed;
            projectile.Damage = CurrentLevelInfo.projectileDamage;

            projectile.Launch(enemy);
        }
Esempio n. 15
0
    void Shoot()
    {
        GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        CannonBall bullet   = bulletGO.GetComponent <CannonBall>();

        if (bullet != null)
        {
            bullet.Seek(target, damage);
        }
    }
    public void FollowNew(Transform target)
    {
        targetFollow = target;
        CannonBall ball = target.GetComponent <CannonBall>();

        if (ball != null)
        {
            StartCoroutine("CheckForSleep", ball.GetComponent <Rigidbody2D>());
        }
    }
Esempio n. 17
0
    public void Travel(CannonBall ball, Vector3 velocity, int sender)
    {
        int index = -1;

        do
        {
            index = Random.Range(0, portals.Length);
        } while (index == sender);
        portals[index].Teleport(ball, velocity);
    }
Esempio n. 18
0
 public void TakeDamage(CannonBall ball)
 {
     // Maybe use ball speed?
     blockHp = blockHp - 1;
     if (blockHp <= 0)
     {
         Grd.Score.IncrementScore(1);
         Destroy(gameObject);
     }
 }
Esempio n. 19
0
    private void Shoot(GameObject cannonBall, Vector3 SpawnPoint)
    {
        _animator.SetTrigger("Shoot");
        _shootSound.Play();
        cannonBall.SetActive(true);
        cannonBall.transform.position = SpawnPoint;
        CannonBall ball = cannonBall.GetComponent <CannonBall>();

        ball.SetImpulse(Vector2.right, _force);
    }
Esempio n. 20
0
    public static CannonBall CreateCannonBall(Vector3 inPosition, Vector3 inDirNormalized, Vector3 inCurrentVelocity)
    {
        Transform pfCannonBall        = Resources.Load <Transform>("pfCannonBall");
        Transform cannonBallTransform = Instantiate(pfCannonBall, inPosition, Quaternion.identity);

        CannonBall cannonBall = cannonBallTransform.GetComponent <CannonBall>();

        cannonBall.rb.velocity = inDirNormalized * cannonBall.speed + inCurrentVelocity;

        return(cannonBall);
    }
Esempio n. 21
0
        public CannonBall CreateCannonBall(Vector2 position, Vector2 firingForce, int collisionGroup)
        {
            var cannonBall = new CannonBall(this.Game, position, collisionGroup);
            var cannonBallView = new GameObjectView(base.Game, Content.CannonBall, Color.White, spriteBatch, cannonBall, ZIndexManager.getZIndex(ZIndexManager.drawnItemOrders.cannonBall));
            base.Game.Components.Add(cannonBall);
            base.Game.Components.Add(cannonBallView);
            cannonBall.ApplyFiringForce(firingForce);
            cannonBalls.Add(cannonBall);

            return cannonBall;
        }
Esempio n. 22
0
    public void DamageTaken(CannonBall cannonBall)
    {
        _enemyHealth -= cannonBall.GetDamage();
        cannonBall.Hit();

        if (_enemyHealth <= 0)
        {
            SpawnDrop();
            Die();
        }
    }
Esempio n. 23
0
    void Shot()
    {
        GameObject InstCannon = Instantiate(cannonBallPref, ShootPart.transform.position, Quaternion.identity) as GameObject;

        CannonBall cannonScrpt = InstCannon.GetComponent <CannonBall>();

        if (cannonScrpt != null)
        {
            cannonScrpt.SearchEnemy(target);
        }
    }
Esempio n. 24
0
    public void FireCannon()
    {
        CannonBall newBall = Instantiate(cannonBallPrefab, transform.position, transform.rotation);

        newBall.setTimeToArm(30f);
        newBall.setTimeToDetonate(cannonsController.CannonBallDistance);
        Rigidbody rigidbody;

        rigidbody = newBall.GetComponent <Rigidbody>();
        rigidbody.AddForce(transform.up * cannonsController.CannonThrustForce * cannonsController.CannonsThrustMaxForce);
    }
Esempio n. 25
0
    void OnTriggerEnter2D(Collider2D other)
    {
        CannonBall cannonBall = other.gameObject.GetComponent <CannonBall>();

        if (!cannonBall)
        {
            return;
        }

        DamageTaken(cannonBall);
    }
Esempio n. 26
0
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "CannonBall")                                                    //Checking for collision between ship and CannonBall
     {
         CannonBall cannonball = collision.gameObject.GetComponent(typeof(CannonBall)) as CannonBall; //Reference to the CannonBall script
         Health -= cannonball.damage;                                                                 //Calculates health after collision
         if (Health <= 0)                                                                             //Check if the ship has health
         {
             Destroy(gameObject);                                                                     //Destroys the ship
         }
     }
 }
Esempio n. 27
0
    // Start is called before the first frame update
    void Awake()
    {
        cannonScript = GameObject.Find("CannonWScript").GetComponent <CannonBall>();
        GameObject[] levelLoader = GameObject.FindGameObjectsWithTag("LevelLoader");

        /*  if (levelLoader.Length > 1)
         * {
         *    Destroy(this.gameObject);
         * }
         * DontDestroyOnLoad(this.gameObject);
         *
         */
    }
Esempio n. 28
0
    IEnumerator GhostShipping()
    {
        while (true)
        {
            yield return(new WaitForSeconds(Random.Range(4f, 8f) / GameManager.gSpeed));

            Vector3    target = Player.P.transform.position + new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
            Vector3    dir    = (target - transform.position).normalized;
            CannonBall obj    = Instantiate(ball, transform.position + .5f * dir, Quaternion.identity);

            obj.SetVelocity(dir * 4f);
        }
    }
Esempio n. 29
0
    public void Shoot()
    {
        // Instantiate a bullet
        GameObject ourCannonBall       = Instantiate(cannonBall, firePoint.transform.position, firePoint.transform.rotation);
        CannonBall cannonBallComponent = ourCannonBall.GetComponent <CannonBall>();
        Rigidbody  cannonBody          = ourCannonBall.GetComponent <Rigidbody>();

        // Apply Force
        cannonBody.AddForce(data.shellForce * transform.forward, ForceMode.Impulse);

        // Tell the cannon ball how much damage it should do.
        cannonBallComponent.damage = data.damageDone;
    }
Esempio n. 30
0
    private void ShootVolley(Vector3 direction)
    {
        int[] cannonBallPositions          = new int[] { -2, -1, 0, 1 };
        float cannonBallSeperationDistance = 1.5f;

        for (int i = 0; i < cannonBallPositions.Length; i++)
        {
            Vector3 verticalOffset   = transform.up * cannonBallSeperationDistance * cannonBallPositions[i];
            Vector3 horizontalOffset = transform.right * Random.Range(0, 0.5f);

            CannonBall.CreateCannonBall((transform.position + verticalOffset + horizontalOffset), direction, rb.velocity);
        }
    }
Esempio n. 31
0
    //supposed to shoot the cannon ball. Still needs work.
    public void Shoot(GameObject cannonBallPrefab)
    {
        if (Time.time > lastFireTime + data.fireCooldown)
        {
            GameObject firedcannonBall = Instantiate(cannonBallPrefab, firePoint.position, firePoint.rotation) as GameObject;
            CannonBall cannonBall      = firedcannonBall.GetComponent <CannonBall>();
            if (cannonBall != null)
            {
                cannonBall.attacker = data;
            }

            lastFireTime = Time.time;
        }
    }
Esempio n. 32
0
 public void RemoveCannonBall(CannonBall cannonBall)
 {
     //cannonBall.RemoveFromPhysicsSimulator();
     base.Game.Components.Remove(cannonBall);
     cannonBalls.Remove(cannonBall);
 }
 public ObjectDamagedEventArgs(GameTime damagedTime, CannonBall damagingObject)
 {
     this.DamagedTime = damagedTime;
     this.DamagingObject = damagingObject;
 }
 void RaiseObjectDamagedEvent(GameTime damagedTime, CannonBall damagingObject)
 {
     if (ObjectDamaged != null)
     {
         ObjectDamaged(this, new ObjectDamagedEventArgs(damagedTime, damagingObject));
     }
 }
 /// <summary>
 /// Object status reaction to being hit by a cannon ball.
 /// </summary>
 private void hitByCannonBall(CannonBall cannonBall, GameTime gameTime)
 {
     RaiseObjectDamagedEvent(gameTime, cannonBall);
 }