This class manages what happens to the bomb depending on what it hits and which way it is going
Inheritance: MonoBehaviour
示例#1
0
    private void FixedUpdate()
    {
        if (firePressed)
        {
            firePressed = false;
            if (timeSinceLastCannonball > cannonballCooldown)
            {
                animator.SetTrigger(animateFire);
                float spawnX;
                if (transform.rotation.w < 0)       // Turret facing right
                {
                    spawnX = sprite.bounds.max.x;
                }
                else                                // Turret facing left
                {
                    spawnX = sprite.bounds.min.x;
                }
                Vector3    spawnVector           = new Vector3(spawnX - spriteWidth, sprite.bounds.max.y, transform.position.z);
                GameObject initialisedCannonball = Instantiate(CannonballPrefab, spawnVector, transform.rotation);
                Cannonball newCannonball         = initialisedCannonball.GetComponentInChildren <Cannonball>();
                if (newCannonball == null)
                {
                    Debug.LogError("Could not find component Cannonball!");
                }
                newCannonball.SetSpeed(cannonballSpeed);

                timeSinceLastCannonball = 0f;
            }
        }
    }
示例#2
0
    private void Start()
    {
        backgroundLoot = GameObject.Find("TreasureChests_BackgroundLoot").GetComponent <CoinLoot>();

        dataManager      = DataManager.singleton;
        Cursor.visible   = true;
        Cursor.lockState = CursorLockMode.None;
        if (dataManager.playedGame == true)
        {
            gameEndMenu.SetActive(true);
            GetComponent <GameEndManager>().Initialize();
            GetComponent <GameEndManager>().UpdateText();
            mainMenu.SetActive(false);
        }
        else
        {
            gameEndMenu.SetActive(false);
        }

        dataManager.FixValues();
        coinsText.text = dataManager.GetSaveValue(ESave_Values_Keys.COINS_AMOUNT).ToString() + " coins";
        Cannonball.ResetKillCounter();
        GetComponent <HighscoresManager>().Initialize();
        GetComponent <StatsManager>().Initialize();
    }
示例#3
0
    protected virtual IEnumerator AnimateCellLock(Cannonball cannonball)
    {
        Transform goalTransform = transform;         // Initialize

        if (cannonball.player.playerType == PlayerType.ONE)
        {
            goalTransform = blueCell.transform.GetChild(0);
        }
        else if (cannonball.player.playerType == PlayerType.TWO)
        {
            goalTransform = redCell.transform.GetChild(0);
        }
        Vector3 startPosition = transform.position;
        Vector3 startRotation = cannonball.transform.localEulerAngles;
        Vector3 startScale    = cannonball.transform.localScale;
        float   i             = 0;
        float   rate          = 1 / cellLockAnimTime;

        while (i < 1)
        {
            i += Time.deltaTime * rate;
            cannonball.transform.position         = Vector3.Lerp(startPosition, transform.position, i);
            cannonball.transform.localScale       = Vector3.Lerp(startScale, goalTransform.localScale, i);
            cannonball.transform.localEulerAngles = Vector3.Lerp(startRotation, goalTransform.localEulerAngles, i);
            yield return(null);
        }
    }
示例#4
0
    ////////////////////////////////////////////////////////////

    public void EndGame()
    {
        if (dataManager != null)
        {
            dataManager.AddLog("Killed: " + Cannonball.GetKillCount());
            dataManager.AddLog("Coins collected : " + TreasureChestDropzone.coins);
            dataManager.AddLog("Chests stolen: " + TreasureChestDropzone.chestsStolen);

            dataManager.ChangeSaveValue(ESave_Values_Keys.HIGHEST_KILLSAMOUNT, Cannonball.GetKillCount());
            dataManager.ChangeSaveValue(ESave_Values_Keys.HIGHEST_COINSAMOUNT, TreasureChestDropzone.coins);
            dataManager.ChangeSaveValue(ESave_Values_Keys.HIGHEST_TREASURECHESTAMOUNT, TreasureChestDropzone.chestsStolen);

            dataManager.SetHighScore(Cannonball.GetKillCount() + TreasureChestDropzone.coins);

            foreach (Quest quest in questList)
            {
                if (quest.currentStage >= quest.questConditions.Length)
                {
                    continue;
                }

                if (quest.questConditions[quest.currentStage].conditionID == Quest_Conditions.EARNEDXCOINSONEPLAY && TreasureChestDropzone.coins >= quest.questConditions[quest.currentStage].x)
                {
                    quest.currentStage++;
                }
            }

            dataManager.ReplaceQuests(questList);
        }

        PlayerPrefs.SetFloat("Beer_Multiplier", 1.0f);

        SceneManager.LoadScene(0);
    }
示例#5
0
    /// <summary>
    ///  Event that is called when a cannon hits the player.
    /// </summary>
    /// <param name="ball">The cannonball that hit the player</param>
    public void OnPlayerHit(Cannonball ball)
    {
        ScoreManager.Instance.SubtractScore (ScoreManager.PlayerHitReduction);

        if (currExplosion == null)
            currExplosion = Instantiate (explosionPrefab.gameObject, transform.position, new Quaternion ()) as GameObject;
    }
示例#6
0
    void simulateCannonballs()
    {
        for (int i = 0; i < cannonballs.Count; i++)
        {
            Cannonball curr = cannonballs[i];
            if (intersectCannonballWithScene(ref curr))
            {
                cannonballs.RemoveAt(i);
                i--;
                continue;
            }
            if (curr.velocity.magnitude <= ballMinSpeed)
            {
                cannonballs.RemoveAt(i);
                i--;
                continue;
            }

            float locGrav = (curr.isGrounded) ? 0.0f : gravity;
            curr.velocity.y -= locGrav * Time.deltaTime;
            if (curr.centre.y >= mountainTopY)
            {
                curr.velocity.x += (currWindForce / Cannonball.mass) * Time.deltaTime;
            }
            curr.centre += curr.velocity * Time.deltaTime;
        }
    }
示例#7
0
    void OnCollisionEnter2D(Collision2D col)
    {
        Player p = col.collider.GetComponent <Player>();
        Enemy  e = col.collider.GetComponent <Enemy>();

        if (p)
        {
            Cannonball c = p.GetComponent <Cannonball>();
            if (c && c.active && Controller.inst.currentSave.upgrades[Upgrade.cannonballShield])
            {
                Destroy(gameObject);
            }
            else
            {
                p.Damage(damage);
                Destroy(gameObject);
            }
        }
        else if (reflected && e)
        {
            e.Die(transform.position.x < e.transform.position.x);
            Destroy(gameObject);
        }
        else
        {
            print(col.collider.name);
            rigidbody.gravityScale = 2;
            Destroy(gameObject, 0.5f);
        }
    }
示例#8
0
 public Cannonball(Cannonball other)
 {
     this.centre     = other.centre;
     this.velocity   = other.velocity;
     this.radius     = other.radius;
     this.isGrounded = other.isGrounded;
 }
示例#9
0
 /// <summary>
 /// Makes the argument objectToMakeUnused marked as unused.  This method is generated to be used
 /// by generated code.  Use Destroy instead when writing custom code so that your code will behave
 /// the same whether your Entity is pooled or not.
 /// </summary>
 public static void MakeUnused(Cannonball objectToMakeUnused, bool callDestroy)
 {
     if (callDestroy)
     {
         objectToMakeUnused.Destroy();
     }
 }
示例#10
0
    public void TryAttack(bool cursed, Vector3 boatSpeed)
    {
        if (this.timer > this.cooldown)
        {
            for (int i = 0; i < this.offsets.Length; i++)
            {
                GameObject go = Instantiate(
                    this.cannonball,
                    this.GetStartPos(i),
                    Quaternion.identity
                    );

                Rigidbody rb = go.GetComponent <Rigidbody>();
                rb.velocity = this.BallVelocity + boatSpeed;

                if (cursed)
                {
                    Cannonball c = go.GetComponent <Cannonball>();
                    c.AddCurse();
                }

                this.source.Play();
            }

            this.timer = 0.0f;
        }
    }
示例#11
0
        public static Cannonball CreateNew(Layer layer, float x = 0, float y = 0)
        {
            Cannonball instance = null;

            instance = new Cannonball(mContentManagerName ?? FlatRedBall.Screens.ScreenManager.CurrentScreen.ContentManagerName, false);
            instance.AddToManagers(layer);
            instance.X = x;
            instance.Y = y;
            foreach (var list in ListsToAddTo)
            {
                if (SortAxis == FlatRedBall.Math.Axis.X && list is PositionedObjectList <Cannonball> )
                {
                    var index = (list as PositionedObjectList <Cannonball>).GetFirstAfter(x, Axis.X, 0, list.Count);
                    list.Insert(index, instance);
                }
                else if (SortAxis == FlatRedBall.Math.Axis.Y && list is PositionedObjectList <Cannonball> )
                {
                    var index = (list as PositionedObjectList <Cannonball>).GetFirstAfter(y, Axis.Y, 0, list.Count);
                    list.Insert(index, instance);
                }
                else
                {
                    // Sort Z not supported
                    list.Add(instance);
                }
            }
            if (EntitySpawned != null)
            {
                EntitySpawned(instance);
            }
            return(instance);
        }
示例#12
0
    //instantiates a cannonball upon firing
    private void Shoot()
    {
        GameObject projectile = new GameObject();

        //all the cannonballs are referenced in a list
        cannonballList.Add(projectile);

        //Spawns the projectile in the current cannon's nozzle
        if (shootingFromTheLeft == true)
        {
            projectile.transform.position = nozzleLeft.transform.position;
        }
        else
        {
            projectile.transform.position = nozzleRight.transform.position;
        }

        //set and scale cannonballSprite and attach script to the cannonball obj
        projectile.name = "Cannonball";
        projectile.transform.rotation = Quaternion.identity;
        SpriteRenderer renderer = projectile.AddComponent <SpriteRenderer>();

        renderer.sprite = cannonballSprite;
        projectile.transform.localScale = new Vector2(0.07f, 0.07f);
        Cannonball script = projectile.AddComponent <Cannonball>();
    }
示例#13
0
    void Update()
    {
        // Light cannon if it is selected
        Transform canbase = transform.Find("base");
        Behaviour halo    = (Behaviour)canbase.GetComponent("Halo");

        if (props.IsGoatCannon())
        {
            halo.enabled = false;
        }
        else
        {
            halo.enabled = true;
        }

        // Cannon fired
        if (Input.GetKeyDown(KeyCode.Space) && !props.IsGoatCannon())
        {
            // set random angle and create an object with a cannonball with velocity at that angle
            float      randangle    = Random.Range(minangle, maxangle);
            Vector3    tempvelocity = new Vector3(0.23f, 0, 0);
            Quaternion q            = Quaternion.Euler(0, 0, randangle);
            Quaternion q2           = Quaternion.Euler(-randangle, 90f, 0);
            tempvelocity = q * tempvelocity;

            GameObject control = GameObject.CreatePrimitive(PrimitiveType.Cube);
            control.transform.position = new Vector3(-20, -20, 0);

            Cannonball cb  = control.AddComponent <Cannonball> ();
            Transform  bar = transform.Find("barrel");
            bar.rotation = q2;
            cb.pos       = transform.position + new Vector3(-0.2f, 0.2f, 0.3f);
            cb.velocity  = tempvelocity;
        }
    }
示例#14
0
        public void SpawnCannonball()
        {
            Cannonball ball = new Cannonball();
            ball.Position = Camera.GetCurrentCamera().Position;

            //Level.GetCurrentLevel().RootGameObject.Childs["Cannonballs"].AddChild(ball);
            Level.GetCurrentLevel().RootGameObject.AddChild(ball);
        }
示例#15
0
    private void SpawnCannonball()
    {
        GameObject _spawnedCannonball = GameObject.Instantiate(cannonballGameObject, ejectionPositionGameObject.transform.position, Quaternion.identity);
        Cannonball _cannonball        = _spawnedCannonball.GetComponent <Cannonball>();

        _cannonball.Speed = power;
        AudioManager.Instance.PlayShootEffect();
    }
    void Shoot()
    {
        GameObject cb       = Instantiate(cannonball, barrel.position, barrel.rotation);
        Cannonball cbScript = cb.GetComponent <Cannonball>();

        cbScript.speed = ballSpeed;
        cbScript.GoFast();
    }
示例#17
0
    private void SpawnCannonball()
    {
        // Pick a treasure
        Treasure   target = treasures.PickRandom();
        Cannonball cb     = Instantiate(cannonballPrefab);

        cb.transform.position = new Vector3(5f, Random.Range(-3f, 3f));
        cb.Launch(target);
    }
示例#18
0
    void OnTriggerEnter(Collider collider)
    {
        Cannonball cannonball = collider.gameObject.GetComponent <Cannonball>();

        if (cannonball != null)
        {
            HandleCannonballCollision(cannonball);
        }
    }
示例#19
0
    void OnCollisionEnter(Collision collision)
    {
        Cannonball cannonball = collision.gameObject.GetComponent <Cannonball>();

        if (cannonball != null)
        {
            HandleCannonballCollision(cannonball);
        }
    }
示例#20
0
    /// <summary>
    ///  Event that is called when a cannon hits the player.
    /// </summary>
    /// <param name="ball">The cannonball that hit the player</param>
    public void OnPlayerHit(Cannonball ball)
    {
        ScoreManager.Instance.SubtractScore(ScoreManager.PlayerHitReduction);

        if (currExplosion == null)
        {
            currExplosion = Instantiate(explosionPrefab.gameObject, transform.position, new Quaternion()) as GameObject;
        }
    }
示例#21
0
    void SpawnCannonball()
    {
        smokeFX.Play();
        Cannonball ball = Instantiate(CannonballPrefab, transform.position, Quaternion.identity);

        ball.GetComponent <Rigidbody>().AddForce(transform.TransformVector(new Vector3(1f, 0f, 0f)) * Force, ForceMode.Impulse);

        Destroy(ball, 3f);
    }
示例#22
0
    private void OnTriggerEnter(Collider other)
    {
        Cannonball cannonball = other.gameObject.GetComponent <Cannonball>();

        if (cannonball != null)
        {
            cannonball.Splash();
            return;
        }
    }
示例#23
0
        private static void FactoryInitialize()
        {
            const int numberToPreAllocate = 20;

            for (int i = 0; i < numberToPreAllocate; i++)
            {
                Cannonball instance = new Cannonball(mContentManagerName, false);
                mPool.AddToPool(instance);
            }
        }
示例#24
0
    private void OnTriggerEnter(Collider other)
    {
        Cannonball cannonball = other.gameObject.GetComponent <Cannonball>();

        if (cannonball != null)
        {
            Destroy(cannonball.gameObject);
            Destroy(this);
            return;
        }
    }
示例#25
0
 protected virtual void OnTriggerEnter(Collider other)
 {
     if (owner == null)
     {
         Cannonball cannonball = other.GetComponent <Cannonball>();
         if (cannonball != null)
         {
             ClaimCell(cannonball);
         }
     }
 }
示例#26
0
    private void HandleFireInput()
    {
        if (Input.GetButtonDown("Fire"))
        {
            Vector3?mouseoverPos = GetMouseoverPosition();
            if (mouseoverPos.HasValue)
            {
                Vector3 target        = mouseoverPos.Value;
                float   angle         = Util.AngleTowards(transform.position, target);
                float   relativeAngle = Util.Clamp180(angle - transform.rotation.eulerAngles.y);

                // Angle will be the following:
                // * 0: Front
                // * 180: Back
                // * 0 to 180: Right
                // * -180 to 0: Left

                // Ensure the angle is within bounds (must not be too close to the front or the back)
                if (Mathf.Abs(relativeAngle) < MaxFiringAngle || Mathf.Abs(relativeAngle) > 180 - MaxFiringAngle)
                {
                    return;
                }

                int cannonIndex = relativeAngle <= 0 ?
                                  _Caravel.GetNextLeftCannonIndex() :
                                  _Caravel.GetNextRightCannonIndex();
                var cannon = _Caravel.GetCannon(cannonIndex);

                // Check that we can fire the cannon (aren't reloading)
                float timeSinceFired = Time.time - cannon.LastFireTime;
                if (timeSinceFired < _ReloadTime)
                {
                    return;
                }
                cannon.LastFireTime = Time.time;

                // Fire a cannonball from the cannon
                Vector3 spawnPos = cannon.SpawnPos.transform.position;

                GameObject instantiated       = Instantiate(CannonballPrefab, spawnPos, Quaternion.identity);
                Vector3    cannonballVelocity = CalculateCannonballTrajectory(spawnPos, target, CannonballSpeed, CannonballGravity) + _Rigidbody.velocity;

                Cannonball cannonball = instantiated.GetComponent <Cannonball>();
                cannonball.Velocity         = cannonballVelocity;
                cannonball.Gravity          = CannonballGravity;
                cannonball.IgnoreCollisions = this.gameObject;

                // Play cannon effects
                _Caravel.PlayCannonEffects(cannonIndex);
                ApplyCannonTorque(cannonballVelocity, spawnPos);
            }
        }
    }
示例#27
0
    void Start()
    {
        rd     = this.gameObject.GetComponent <SpriteRenderer>();
        ca     = this.gameObject.transform.parent.GetComponent <Cannonball>();
        basesc = this.gameObject.transform.localScale;

        if (!hasBase)
        {
            baseLoc = this.gameObject.transform.position;
        }
        y = baseLoc.y;
    }
示例#28
0
    void Fire()
    {
        attackCooldownTimer = DELAYBETWEENATTACKS;
        Vector3    itemSpawnPos  = new Vector3(transform.position.x, transform.position.y + 1.85f, transform.position.z) + transform.forward * 3f;
        Vector3    dir           = targetUnit.transform.position - itemSpawnPos;
        Cannonball newCannonball = Instantiate(cannonballPrefab, itemSpawnPos, Quaternion.identity);

        newCannonball.Initialize(team, DAMAGE);
        NetworkServer.Spawn(newCannonball.gameObject);
        //newShuriken.transform.Rotate(90, 0, 0);
        newCannonball.GetComponent <Rigidbody>().AddForce(Vector3.Normalize(dir) * 50f, ForceMode.Impulse);
    }
示例#29
0
    IEnumerator FireCannonEnum(GameObject contactPoint)
    {
        // get the templates
        GameObject ball_template = (GameObject)Resources.Load("Models/cannonball", typeof(GameObject));
        //string effect = effects.effect;
        //GameObject effect_template = string.IsNullOrEmpty(effect) ? null : (GameObject)Resources.Load("Models/" + effect, typeof(GameObject));

        // lock in the target position (just in case the actual target is destroyed by previous balls)
        Vector3 targetPos = contactPoint.transform.position;

        // keep track of used mounts
        List <GameObject> used_mounts = new List <GameObject>();

        // fire each round
        int count = 0;

        while (count < RateOfFire)
        {
            // instantiate
            GameObject ball_instance = (GameObject)Instantiate(ball_template);
            foreach (var collider in SelfColliders)
            {
                Physics.IgnoreCollision(ball_instance.GetComponent <Collider>(), collider);
            }
            //GameObject effect_instance = (effect_template == null) ? null : (GameObject)Instantiate(effect_template, mount.transform.position, mount.transform.rotation);

            // determine the velocity and start position
            float   offset   = Random.Range(-100.0f, 100.0f);
            Vector3 position = new Vector3(transform.position.x + offset, transform.position.y, transform.position.z);

            // enter play
            ball_instance.transform.position = position;
            ball_instance.transform.rotation = transform.rotation;
            if (FiringArc > 0.0f)
            {
                Vector3 full     = targetPos - transform.position;
                Vector3 partial  = Vector3.RotateTowards(transform.forward, full, Mathf.Deg2Rad * FiringArc / 2.0f, 0.0f);
                Ray     ray      = new Ray(transform.position, partial);
                var     distance = Vector3.Distance(transform.position, contactPoint.transform.position);
                ball_instance.transform.LookAt(ray.GetPoint(distance));
                Debug.DrawRay(transform.position, partial * 5000.0f, Color.green, 1.0f);
            }

            // cannonball script actions
            Cannonball cannonball = ball_instance.GetComponent <Cannonball>();
            cannonball.OwnedByShip = GetComponentInParent <Ship>();

            // iterate
            count++;
            yield return(new WaitForSeconds(0.25f));
        }
    }
示例#30
0
    private void Awake()
    {
        cannonballs = new Cannonball[instanceCount];

        for (int i = 0; i < instanceCount; i++)
        {
            Cannonball cannonball = Instantiate(cannonballPrefab) as Cannonball;
            cannonball.transform.parent = transform;
            cannonball.gameObject.SetActive(false);

            cannonballs[i] = cannonball;
        }
    }
示例#31
0
 protected virtual void ClaimCell(Cannonball cannonball)
 {
     if (!cannonball.expended)
     {
         Debug.Log("HIT!");
         cannonball.OnHitCell();
         Vector3 destination = transform.position;
         cannonball.transform.SetParent(transform);
         StartCoroutine(AnimateCellLock(cannonball));
         owner = cannonball.player;
         GetComponent <Collider>().isTrigger = false;
         board.CheckGameOver(this);
     }
 }
示例#32
0
    private static float SinkTime = 5f; //the time it takes for the ship to sink in seconds

    #endregion Fields

    #region Methods

    /// <summary>
    /// Method callback for when the cannonball hits the ship. This method adds some randomness to the effect of the ship sinking.
    /// </summary>
    public void OnShipHit(Cannonball ball)
    {
        ScoreManager.Instance.AddScore (ScoreManager.ShipHitIncrease);

        StopAllCoroutines ();

        shipExplosion.Play ();

        Instantiate (explosionPrefab.gameObject, transform.position, new Quaternion ()); //explosion
        Vector3 dirEuler = (new Vector3 (Random.Range (0f, 1f), Random.Range (0f, 1f), Random.Range (0f, 1f))).normalized*90f;

        Vector3 dest = transform.position;
        dest.y -= SinkDist;

        iTween.MoveTo(gameObject, iTween.Hash("position", dest, "easeType", "linear", "time", SinkTime, "oncomplete", "OnSinkComplete", "oncompletetarget", gameObject));
        iTween.RotateTo(gameObject, iTween.Hash("rotation", dirEuler, "easeType", "linear", "time", SinkTime));
    }
        /// <summary>
        /// Loads the content.
        /// </summary>
        public void LoadContent()
        {
            ////this.castles = new Castle[Ballerburg.Gameplay.Constants.NumCastles];
              castles[0] = contentManager.Castle1;
              castles[1] = contentManager.Castle2;
              castles[2] = contentManager.Castle3;
              castles[3] = contentManager.Castle4;
              castles[4] = contentManager.Castle5;
              castles[5] = contentManager.Castle6;
              castles[6] = contentManager.Castle7;
              castles[7] = contentManager.Castle8;

              // Init the cannonball array
              this.activeCannonballs = new Cannonball[MaxCannonBalls];
              for (var i = 0; i < MaxCannonBalls; i++)
              {
            activeCannonballs[i] = new Cannonball(contentManager);
              }

              skyBox = contentManager.SkyBox;

              terrain = new Terrain(contentManager, graphicsDevice);

              explosionBillboard = new AnimatedBillboard(false, contentManager);
              explosionBillboard.LoadContent();
              explosionBillboard.InitGraphics(graphicsDevice.GraphicsDevice);

              explosionBillboard.PrepareAnimation();
              explosionBillboard.Pause();
        }