Example #1
0
    void OnMouseDown()
    {
        if (ui.isGameOver == true)
        {
            return;
        }

        if (ui.isSelectWord < 2 && this.isSelect == false && anim.isPlaying == false)
        {
            if (ui.isSelectWord == 0)
            {
                Word word = (Word)ui.wordList[ui.chooseWords[cardIdx - 1]];
                battle.firstWord = ui.backWord = word;

                anim.clip = anim.GetClip("DestroyCard");
                anim.Play();
            }
            if (ui.isSelectWord == 1)
            {
                Word word = (Word)ui.wordList[ui.chooseWords[cardIdx - 1]];
                battle.secondWord = word;

                ui.ClearCanvas();
            }

            GameObject snd = (GameObject)Instantiate(chooseCardSound);
            Destroy(snd, 1.5f);

            this.isSelect = true;
            ui.isSelectWord++;

            //anim.clip = anim.GetClip("RotationToPositive");
            //anim.Play();
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (monsterAttackTime > 0.0f)
        {
            monsterAttackTime -= Time.deltaTime;
        }
        if (bulletTime > 0.0f)
        {
            bulletTime -= Time.deltaTime;
        }
        if (cTimer > 0.0f)
        {
            cTimer -= Time.deltaTime;
            if (cTimer <= 0.0f)
            {
                circle.gameObject.SetActive(false);
                cTimer = 0.0f;
            }
        }

        //HP of enemy
        if (Mathf.Abs(HP_enemy_now - HP_enemy) >= 5.0f)
        {
            if (HP_enemy_now > HP_enemy)
            {
                HP_enemy_now -= Time.deltaTime * HP_enemy_max / 3.0f;
                GameObject snd = (GameObject)Instantiate(HP_Down);
                Destroy(snd, 0.3f);
            }
            else
            {
                HP_enemy_now += Time.deltaTime * HP_enemy_max / 3.0f;
                GameObject snd = (GameObject)Instantiate(HP_Up);
                Destroy(snd, 0.3f);
            }

            if (Mathf.Abs(HP_enemy_now - HP_enemy) < 5.0f)
            {
                HP_enemy_now = HP_enemy;
            }
        }
        // HP of player
        if (Mathf.Abs(HP_player_now - HP_player) >= 5.0f)
        {
            if (HP_player_now > HP_player)
            {
                HP_player_now -= Time.deltaTime * HP_player_max / 3.0f;
            }
            else
            {
                HP_player_now += Time.deltaTime * HP_player_max / 3.0f;
            }

            if (Mathf.Abs(HP_player_now - HP_player) < 5.0f)
            {
                HP_player_now = HP_player;
            }
        }

        if (monsterCreateTime > 0.0f)
        {
            monsterCreateTime -= Time.deltaTime;
        }

        if (monsterCreateTime > 0.0f)
        {
            return;
        }
        if (monsterCreateTime < 0.0f)
        {
            monsterCreateTime = 0.0f;
            HP_initial();
        }

        if (ui.isGameOver)
        {
            return;
        }

        if (ui.isSelectWord == 2)
        {
            if (isFireBall == false)
            {
                lastCount   = 0;
                isFireBall  = true;
                fireBallNum = ui.backWord.finishIndex;
                fireBalls   = new GameObject[fireBallNum];
                for (int i = 0; i < fireBallNum; i++)
                {
                    fireBalls[i] = (GameObject)Instantiate(fireBall);

                    if (i == 0)
                    {
                        fireBalls[i].transform.position = new Vector3(-0.2083941f, 35.57512f, 5.812185f);
                    }
                    else if (i % 2 != 0)
                    {
                        fireBalls[i].transform.position = fireBalls[0].transform.position -
                                                          new Vector3((i + 1) / 2.0f * 3.0f, 0, 0);
                    }
                    else
                    {
                        fireBalls[i].transform.position = fireBalls[0].transform.position +
                                                          new Vector3(i / 2.0f * 3.0f, 0, 0);
                    }
                }
            }

            if (ui.frontWord.finishIndex > lastCount)
            {
                lastCount = ui.frontWord.finishIndex;
                Destroy(fireBalls[ui.backWord.finishIndex - lastCount]);
            }

            if (ui.frontWord.finishIndex >= ui.backWord.finishIndex)
            {
                ui.isSelectWord = 0;
                isFireBall      = false;
                bulletNum       = ui.frontWord.finishIndex;
                bulletTime      = 0.15f;

                // store record to database
                ui.saveScore();

                /*
                 * bool isFind = false;
                 * foreach(wordRecord word in ui.rcd.records)
                 * {
                 *      if(word.word == firstWord.wordName)
                 *      {
                 *              isFind = true;
                 *              word.addRecord(ui.error, System.DateTime.Now.ToString());
                 *              print(word.records.Count);
                 *      }
                 * }
                 * // this is a new word record
                 * if(isFind == false)
                 * {
                 *      ui.db.addRecord(new writeRecord(firstWord.wordName, ui.error, System.DateTime.Now.ToString()));
                 *      ui.rcd.wordRecord = ui.db.getRecords();
                 * }//*/


                /*if(ui.db.isTerm(firstWord, secondWord))
                 * {
                 *      print("is Term!!");
                 * }
                 * else
                 * {
                 *      print("no Term!!");
                 * }*/
                //print(firstWord.wordName + " " + secondWord.wordName);
            }
        }
        else
        {
            if (ui.isFight == false)
            {
                if (bulletNum > 0 && bulletTime < 0.0f)
                {
                    Fight();

                    bulletTime = 0.15f;
                    bulletNum--;
                }

                if (bulletNum == 0)
                {
                    if (ui.db.isTerm(firstWord, secondWord))
                    {
                        isTermAttack      = true;
                        monsterAttackTime = 2.8f;
                    }
                    else
                    {
                        monsterAttackTime = 1.6f;
                    }
                    ui.isFight = true;
                    ui.ClearCanvas();

                    for (int i = 0; i < 4; i++)
                    {
                        //remainWordIdx[i] = -1;
                        t_Card card = GameObject.Find("Card" + (i + 1).ToString()).GetComponent <t_Card>();

                        //if(card.isSelect)
                        //{
                        card.anim.clip = card.anim.GetClip("RotationToNegative");
                        card.anim.Play();
                        //}
                        //else
                        //	remainWordIdx[i] = ui.chooseWords[i];
                    }

                    if (isRecover)
                    {
                        HP_player += (int)(ui.backWord.ATK);
                        if (HP_player > HP_player_max)
                        {
                            HP_player = HP_player_max;
                        }

                        isRecover = false;
                    }
                }
            }
        }

        if (HP_enemy > 0 && monsterAttackTime < 2.2f && monsterAttackTime != 0.0f)
        {
            if (ui.db.isTerm(firstWord, secondWord) && isTermAttack == true && Word.Judge(ui.showE) != "Fail")
            {
                isTermAttack = false;
                print("is Term!!");
                Instantiate(Terms);
            }
        }

        if (HP_enemy > 0 && monsterAttackTime < 0.0f)
        {
            monsterAttackTime = 0.0f;

            GameObject bullet = (GameObject)Instantiate(Bullet, monster.transform.position - new Vector3(0, 0, 10), Quaternion.identity);
            bullet.GetComponent <t_Bullet>().attackObj       = GameObject.Find("Canvas");
            bullet.GetComponent <t_Bullet>().ATK             = ATK_enemy;
            bullet.GetComponent <TrailRenderer>().time       = 0.1f;
            bullet.GetComponent <TrailRenderer>().startWidth = 3.0f;
            bullet.GetComponent <TrailRenderer>().endWidth   = 3.0f;
            //bullet.SetActive(false);
            bullet.renderer.enabled = false;
        }

        // Game over?
        if (HP_enemy == 0 && bulletNum == 0)
        {
            monsterAttackTime         = 0.0f;
            monsterCreateTime         = CreateTime;
            monster.renderer.material = mat_black_monster;
            HP_enemy      = -1;
            HP_enemy_max += 200;
            ATK_enemy    += 10;
            ui.levelNow  += 1;
            ui.Initial();
        }

        if (HP_player <= 0 || ui.levelNow > ui.levelNum)
        {
            // game over
            ui.isGameOver = true;
            AudioSource music = GameObject.Find("Global").GetComponent <AudioSource>();
            music.Stop();
        }
    }