예제 #1
0
 private void processCharge()
 {
     if (Input.GetButtonDown("Fire2"))
     {
         if (hasCharge == false)
         {
             hasCharge = true;
             Vector3 mouse3d = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             Vector2 mouse   = mouse3d;
             float   angle   = Mathf.Atan2(mouse.y - transform.position.y, mouse.x - transform.position.x);
             float   xVel    = Mathf.Cos(angle) * bombVel;
             float   yVel    = Mathf.Sin(angle) * bombVel;
             bomb = Instantiate(bombPrefab, transform.position, Quaternion.identity);
             Rigidbody2D rbBomb = bomb.GetComponent <Rigidbody2D>();
             rbBomb.velocity        = new Vector2(xVel, yVel);
             rbBomb.angularVelocity = UnityEngine.Random.Range(50f, 300f);
         }
         else
         {
             hasCharge = false;
             BombBehavior bombBehavior = bomb.GetComponent <BombBehavior>();
             bombBehavior.Explode();
         }
     }
 }
예제 #2
0
 //Everything that occurs when a Collider2D by the name of other enters the collision box
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Apple")                                         //if the other collider's tag is called "Apple"...
     {
         combo += 1;                                                   //combo is incremented by 1
         score += 10 * combo;                                          //score is updated by 10 * (the currect combo)
         aTimer = 1.0f;                                                //aTimer is reset to 1.0f
         sounds[0].Play();                                             //the apple pick sound is played
         Destroy(other.gameObject);                                    //the apple is destroyed
     }
     else if ((other.tag == "Bomb") && (iTimer <= 0.0f))               //if the other collider's tag is called "Bomb" and iTimer is less than or equal to 0...
     {
         health -= 1;                                                  //health is decremented by 1
         combo   = 0;                                                  //combo is set to 0
         BombBehavior otherBomb = other.GetComponent <BombBehavior>(); //a variable otherBomb of dataType BombBehavior (see BombBehavior script) is set to the attached component BombBehavior of the entering collider
         sounds[1].Play();                                             //the bomb sound is played
         otherBomb.Explode();                                          //otherBomb's Explode method is initialized
         iTimer = 3.0f;                                                //iframe Timer is set to 3 seconds
     }
     else if (other.tag == "Feather")                                  //if the other collider's tag is called "Feather"...
     {
         health += 1;                                                  //increment health by 1
         StartCoroutine(LifeUpAnimation());                            //start LifeUP animation
         sounds[2].Play();                                             //the LifeUP sound is played
         Destroy(other.gameObject);                                    //destroy the feather
     }
 }
예제 #3
0
    private void ConstructDefenseObject(BattleDefenseObjectParameter param)
    {
        PropsConfigData                    configData    = ConfigInterface.Instance.PropsConfigHelper.GetPropsData(param.PropsType);
        PropsDefenseScopeConfigData        defenseData   = configData.FunctionConfigData as PropsDefenseScopeConfigData;
        PropsDefenseScopeLastingConfigData lastingData   = configData.FunctionConfigData as PropsDefenseScopeLastingConfigData;
        DefenseObjectConfigWrapper         configWrapper = new DefenseObjectConfigWrapper(configData.FunctionConfigData);

        GameObject defenseObjectPrefab = Resources.Load(ClientStringConstants.BATTLE_SCENE_RESOURCE_PREFAB_PREFIX_NAME +
                                                        ClientStringConstants.DEFENSE_OBJECT_PREFAB_PREFIX_NAME + configWrapper.PrefabName) as GameObject;

        GameObject defenseObject = GameObject.Instantiate(defenseObjectPrefab) as GameObject;

        defenseObject.transform.position = PositionConvertor.GetWorldPositionFromBuildingTileIndex
                                               (new TilePosition(param.PositionColumn, param.PositionRow));

        DefenseObjectAI ai = defenseObject.GetComponent <DefenseObjectAI>();

        ai.enabled = false;

        DefenseObjectPropertyBehavior property = defenseObject.GetComponent <DefenseObjectPropertyBehavior>();

        property.DefenseObjectID      = param.DefenseObjectID;
        property.BuildingPosition     = new TilePosition(param.PositionColumn, param.PositionRow);
        property.ActorObstacleList    = new List <TilePosition>();
        property.BuildingObstacleList = new List <TilePosition>();

        if (defenseData != null)
        {
            BombBehavior bomb = defenseObject.GetComponent <BombBehavior>();
            bomb.AttackCategory = defenseData.AttackCategory;
            bomb.Damage         = defenseData.Damage;
            bomb.PushVelocity   = defenseData.PushVelocity;
            bomb.PushTicks      = defenseData.PushTicks;
            bomb.Scope          = defenseData.Scope;
            bomb.TriggerScope   = defenseData.TriggerScope;
            bomb.TriggerTick    = defenseData.TriggerTicks;
            bomb.TargetType     = (TargetType)defenseData.TargetType;
            bomb.ParentNode     = this.m_BulletParent;
        }
        else if (lastingData != null)
        {
            LastingEffectBehavior lasting = defenseObject.GetComponent <LastingEffectBehavior>();
            lasting.AttackCategory = lastingData.AttackCategory;
            lasting.Damage         = lastingData.Damage;
            lasting.IntervalTicks  = lastingData.IntervalTicks;
            lasting.TotalTimes     = lastingData.TotalTimes;
            lasting.Scope          = lastingData.Scope;
            lasting.TriggerScope   = lastingData.TriggerScope;
            lasting.TriggerTick    = lastingData.TriggerTicks;
            lasting.TargetType     = (TargetType)lastingData.TargetType;
            //lasting.ParentNode = this.m_ParentNode;
        }

        defenseObject.transform.parent = this.m_ParentNode;

        this.m_SceneHelper.ConstructDefenseObject(defenseObject);
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        BombBehavior bb = (BombBehavior)GetComponent("BombBehavior");

        if (bb.explosionDelay <= 0)
        {
            PlayEffects();
        }

        Debug.Log(bb.explosionDelay);
    }
 void Passive()
 {
     if (GetHealth() <= GetMaxHealth() / 2 && !isPhased)
     {
         isPhased = true;
         bomb     = smokeBomb.GetComponent <BombBehavior>();
     }
     //movement code
     //occasionally throw a bomb at the player
     throwTimer += Time.deltaTime;
     if (throwTimer >= 5f)
     {
         print("Throwing bomb");
         throwTimer = 0f;
         BombBehavior bullet = Instantiate(bomb);
         bullet.transform.position = transform.position;
         pointer.transform.LookAt(GetPlayer().transform.position);
         bullet.GetComponent <Rigidbody2D>().AddForce(pointer.transform.forward * 500);
     }
 }
예제 #6
0
 // Use this for initialization
 void Start()
 {
     BombScript = gameObject.transform.GetChild(0).GetComponent <BombBehavior>();
 }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        anim.SetBool("Angry", !sad);                                                                                                                                                  //sets "Angry" parameter in the anim component to what sad is not
        if (sad)                                                                                                                                                                      //if the tree is sad...
        {
            sadTimer       -= 1 * Time.deltaTime;                                                                                                                                     //decrement sadTimer over time
            nextAppleTimer -= 1 * Time.deltaTime;                                                                                                                                     //decrement nextAppleTimer over time
            if (nextAppleTimer <= 0)                                                                                                                                                  //if nextAppleTimer is less than or equal to 0...
            {
                featherChance = Random.Range((int)featherBoundsS[0], (int)featherBoundsS[1]);                                                                                         //Determines whether feather is to be spawned
                if (featherChance != (int)featherBoundsS[1] - 1)                                                                                                                      //if feather is not to be spawned...
                {
                    Instantiate(dropables[1], new Vector3(leaves.position.x + Random.Range(-5f, 5f), leaves.position.y + Random.Range(-2f, 2f), leaves.position.z), leaves.rotation); //spawn apple at randomized location from leaves anchor
                    nextAppleTimer = Random.Range(appleBounds[0], appleBounds[1]);                                                                                                    //reset the nextAppleTimer to a random value between the appleBounds
                }
                else                                                                                                                                                                  //if feather is to be spawned...
                {
                    Instantiate(dropables[2], new Vector3(leaves.position.x + Random.Range(-5f, 5f), leaves.position.y + Random.Range(-2f, 2f), leaves.position.z), leaves.rotation); //spawn feather at randomized location from leaves anchor
                    nextAppleTimer = Random.Range(appleBounds[0], appleBounds[1]);                                                                                                    //reset the nextAppleTimer to a random value between the appleBounds
                }
            }

            if (sadTimer <= 0.0f)                                    //if sadTimer is less than or equal to 0...
            {
                sad      = false;                                    //make the tree angry
                sadTimer = Random.Range(sadBounds[0], sadBounds[1]); //reset the sad timer to a random value between the sadBounds
            }
        }
        else                                                                                                                                                                          //if tree is angry...
        {
            angerTimer    -= 1 * Time.deltaTime;                                                                                                                                      //decrement anger timer over time
            nextBombTimer -= 1 * Time.deltaTime;                                                                                                                                      //decrement the next bomb timer over time
            if (nextBombTimer <= 0.0f)                                                                                                                                                //if nextBombTimer is less than or equal to 0...
            {
                featherChance = Random.Range((int)featherBoundsH[0], (int)featherBoundsH[1]);                                                                                         //Determines whether feather is to be spawned
                if (featherChance != (int)featherBoundsH[1] - 1)                                                                                                                      //if feather is not to be spawned...
                {
                    Instantiate(dropables[0], new Vector3(leaves.position.x + Random.Range(-5f, 5f), leaves.position.y + Random.Range(-2f, 2f), leaves.position.z), leaves.rotation); //spawn bomb at randomized location from leaves anchor
                    nextBombTimer = Random.Range(bombBounds[0], bombBounds[1]);                                                                                                       //reset the nextBombTimer to a random value between the bombBounds
                }
                else                                                                                                                                                                  //if feather is to be spawned...
                {
                    Instantiate(dropables[2], new Vector3(leaves.position.x + Random.Range(-5f, 5f), leaves.position.y + Random.Range(-2f, 2f), leaves.position.z), leaves.rotation); //spawn feather at randomized location from leaves anchor
                    nextBombTimer = Random.Range(bombBounds[0], bombBounds[1]);                                                                                                       //reset the nextBombTimer to a random value between the bombBounds
                }
            }
            if (angerTimer <= 0.0f)  //if angerTimer is less than or equal to 0...
            {
                sad        = true;   //make the tree sad
                angerTimer = 3.0f;   //reset the angerTimer to 3 seconds
            }
        }
        difficultyTimer += 1 * Time.deltaTime;                                            //difficulty timer is incremented as time goes on
        allBombs         = GameObject.FindGameObjectsWithTag("Bomb");                     //allBombs is set equal to allBombs currently in the scene
        if (difficultyLevel < 5)                                                          //if difficultyLevel is less than 5...
        {
            difficultyLevel = (int)(difficultyTimer / 60);                                //difficulty level is set equal to the closest integer to difficultyTimer / 60
        }
        for (int i = 0; i < allBombs.Length; ++i)                                         //iterates int i as many times as there are indices in allBombs
        {
            BombBehavior currentBombBehavior = allBombs[i].GetComponent <BombBehavior>(); //new variable currentBombBehavior is set equal to the BombBehavior component of the current index in loop
            currentBombBehavior.ChangeDifficulty(difficultyLevel);                        //changes difficulty level of currentBombBehavior to difficultyLevel
        }
    }