Example #1
0
File: Saw.cs Project: kidundead/ow
        public override void Fire(float deltaTime)
        {
            //gunfire.renderer.enabled = true;
            if (shootAudio != null)
            {
                if (!shootAudio.isPlaying)
                {
                    AudioPlayer.PlayAudio(shootAudio);
                }
            }


            Hashtable enemyList = gameScene.GetEnemies();

            foreach (Enemy enemy in enemyList.Values)
            {
                Collider c = enemy.GetCollider();
                if (gun.GetComponent <Collider>().bounds.Intersects(c.bounds))
                {
                    DamageProperty dp = new DamageProperty();
                    dp.damage = damage;
                    enemy.OnHit(dp, WeaponType.Saw, true);
                }
            }


            GameObject[] woodboxes = gameScene.GetWoodBoxes();
            foreach (GameObject woodbox in woodboxes)
            {
                if (woodbox != null)
                {
                    Collider c = woodbox.GetComponent <Collider>();
                    if (gun.GetComponent <Collider>().bounds.Intersects(c.bounds))
                    {
                        WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>();
                        ws.OnHit(damage * player.PowerBuff);
                    }
                }
            }


            lastShootTime = Time.time;
        }
Example #2
0
        public bool Rush(float deltaTime)
        {
            Collider pcollider = player.GetCollider();

            enemyTransform.LookAt(rushingTarget);
            Vector3 moveDir = enemyTransform.TransformDirection(Vector3.forward) * rushingSpeed + Physics.gravity * 0.5f;


            controller.Move(moveDir * deltaTime);
            if (!rushingCollided)
            {
                if (pcollider != null)
                {
                    Vector3 relativePos = enemyTransform.InverseTransformPoint(player.GetTransform().position);
                    //Debug.Log(relativePos);
                    if (relativePos.sqrMagnitude < 5.0f * 5.0f && relativePos.z > 1.0f)
                    {
                        player.OnHit(rushingDamage);
                        //player.GetHit(attackDamage * 2.0f,getHitFlySpeed);
                        lastAttackTime  = Time.time;
                        rushingCollided = true;
                    }

                    /*
                     * if (collider.bounds.Intersects(pcollider.bounds))
                     * {
                     *  //Vector3 getHitFlySpeed = (rushingTarget - enemyTransform.position).normalized *10.0f + Vector3.up*10;
                     *  player.OnHit(rushingDamage);
                     *  //player.GetHit(attackDamage * 2.0f,getHitFlySpeed);
                     *  lastAttackTime = Time.time;
                     *  rushingCollided = true;
                     * }*/
                }
            }

            foreach (Enemy enemy in gameScene.GetEnemies().Values)
            {
                if (enemy.GetState() == Enemy.DEAD_STATE || enemy.EnemyType == EnemyType.E_TANK)
                {
                    continue;
                }

                if (collider.bounds.Intersects(enemy.GetCollider().bounds))
                {
                    DamageProperty dp = new DamageProperty();
                    dp.damage = rushingDamage;
                    enemy.OnHit(dp, WeaponType.NoGun, true);
                }
            }

            GameObject[] woodboxes = gameScene.GetWoodBoxes();
            foreach (GameObject woodbox in woodboxes)
            {
                if (woodbox != null)
                {
                    if (collider.bounds.Intersects(woodbox.GetComponent <Collider>().bounds))
                    {
                        WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>();
                        ws.OnHit(attackDamage);
                    }
                }
            }

            if ((enemyTransform.position - rushingTarget).sqrMagnitude < 1.0f || (enemyTransform.position - player.GetTransform().position).sqrMagnitude < 4.0f || Time.time - lastRushingTime > 3.0f)
            {
                animation[AnimationName.ENEMY_RUSHINGEND].wrapMode = WrapMode.ClampForever;
                animation.CrossFade(AnimationName.ENEMY_RUSHINGEND);
                return(true);
            }

            return(false);
        }
Example #3
0
        public override void Fire(float deltaTime)
        {
            gunfire.GetComponent <Renderer>().enabled = true;


            Ray ray = new Ray();

            if (gameCamera.GetCameraType() == CameraType.TPSCamera)
            {
                Vector3 tempTargetPoint = cameraComponent.ScreenToWorldPoint(new Vector3(gameCamera.ReticlePosition.x, Screen.height - gameCamera.ReticlePosition.y, 0.1f));

                ray = new Ray(cameraTransform.position, (tempTargetPoint - cameraTransform.position));
            }
            else if (gameCamera.GetCameraType() == CameraType.TopWatchingCamera)
            {
                ray = new Ray(player.GetTransform().position + Vector3.up * 0.5f, player.GetTransform().TransformDirection(Vector3.forward));
            }


            RaycastHit hit = new RaycastHit();

            RaycastHit[] hits;
            float        tan = Mathf.Tan(Mathf.Deg2Rad * 60.0f);

            hits = Physics.RaycastAll(ray, 1000, 1 << PhysicsLayer.ENEMY | 1 << PhysicsLayer.WALL | 1 << PhysicsLayer.FLOOR | 1 << PhysicsLayer.WOODBOX);


            float minDistance = 1000000f;

            for (int i = 0; i < hits.Length; i++)
            {
                Vector3 relativePos = Vector3.zero;
                if (hits[i].collider.gameObject.layer == PhysicsLayer.ENEMY)
                {
                    relativePos = gunfire.transform.InverseTransformPoint(hits[i].collider.transform.position);
                }
                else
                {
                    relativePos = gunfire.transform.InverseTransformPoint(hits[i].point);
                }

                if (relativePos.z < 1)// || Mathf.Abs(relativePos.z / relativePos.x) > tan
                {
                    float dis = (hits[i].point - gunfire.transform.position).sqrMagnitude;
                    if (dis < minDistance)
                    {
                        hit         = hits[i];
                        minDistance = dis;
                    }
                }
            }


            if (hit.collider != null)
            //if (Physics.Raycast(ray, out hit, 1000, 1 << PhysicsLayer.ENEMY | 1 << PhysicsLayer.WALL | 1 << PhysicsLayer.FLOOR | 1 << PhysicsLayer.WOODBOX))
            {
                //Debug.Log(hit.collider.name);

                aimTarget = hit.point;
                Vector3 dir = (aimTarget - rightGun.position).normalized;

                Vector3 relativeDir = player.GetTransform().InverseTransformPoint(aimTarget);
                if (relativeDir.z > Constant.SPARK_MIN_DISTANCE)
                {
                    GameObject fireLineObj = firelineObjectPool.CreateObject(gunfire.transform.position + dir * 2, dir);
                    fireLineObj.transform.Rotate(180, 0, 0);
                    if (fireLineObj == null)
                    {
                        Debug.Log("fire line obj null");
                    }
                    else
                    {
                        FireLineScript f = fireLineObj.GetComponent <FireLineScript>();
                        f.transform.Rotate(90, 0, 0);
                        f.beginPos = rightGun.position;
                        f.endPos   = hit.point;
                    }
                }

                bulletsObjectPool.CreateObject(rightGun.position, dir);

                GameObject hitObject = hit.collider.gameObject;

                if (hitObject.name.StartsWith(ConstData.ENEMY_NAME))
                {
                    Enemy enemy = gameScene.GetEnemyByID(hitObject.name);

                    if (enemy.GetState() != Enemy.DEAD_STATE)
                    {
                        if (relativeDir.z > Constant.SPARK_MIN_DISTANCE)
                        {
                            sparksObjectPool.CreateObject(hit.point, -ray.direction);
                        }
                        DamageProperty dp = new DamageProperty();
                        dp.hitForce = ray.direction * hitForce;
                        dp.damage   = damage * player.PowerBuff;
                        bool criticalAttack = false;

                        int rnd = Random.Range(0, 100);
                        if (rnd < 70)
                        {
                            criticalAttack = true;
                        }

                        float dis       = (enemy.GetPosition() - player.GetTransform().position).sqrMagnitude;
                        float radiusSqr = range * range;
                        if (dis < radiusSqr)
                        {
                            enemy.OnHit(dp, GetWeaponType(), criticalAttack);
                        }
                        else
                        {
                            if (rnd < accuracy)
                            {
                                enemy.OnHit(dp, GetWeaponType(), criticalAttack);
                            }
                        }
                    }
                }
                else
                {
                    if (relativeDir.z > Constant.SPARK_MIN_DISTANCE)
                    {
                        sparksObjectPool.CreateObject(hit.point, -ray.direction);
                    }
                    if (hitObject.layer == PhysicsLayer.WOODBOX)
                    {
                        Debug.Log(hitObject.name);
                        WoodBoxScript ws = hitObject.GetComponent <WoodBoxScript>();
                        ws.OnHit(damage * player.PowerBuff);
                    }
                }

                if (Time.time - lastPlayAudioTime >= shootAudio.clip.length)
                {
                    lastPlayAudioTime = Time.time;
                    AudioPlayer.PlayAudio(shootAudio);
                }
                sbulletCount--;
                sbulletCount = Mathf.Clamp(sbulletCount, 0, maxCapacity);

                player.LastHitPosition = hit.point;

                lastShootTime = Time.time;
            }
            else
            {
                aimTarget = cameraTransform.TransformPoint(0, 0, 1000);
                Vector3 dir = (aimTarget - rightGun.position).normalized;

                bulletsObjectPool.CreateObject(rightGun.position, dir);



                GameObject fireLineObj = firelineObjectPool.CreateObject(gunfire.transform.position + dir * 2, dir);
                if (fireLineObj == null)
                {
                    Debug.Log("fire line obj null");
                }
                else
                {
                    FireLineScript f = fireLineObj.GetComponent <FireLineScript>();
                    f.transform.Rotate(90, 0, 0);
                    f.beginPos = rightGun.position;
                    f.endPos   = hit.point;
                }



                if (!shootAudio.isPlaying)
                {
                    AudioPlayer.PlayAudio(shootAudio);
                }
                sbulletCount--;
                sbulletCount = Mathf.Clamp(sbulletCount, 0, maxCapacity);

                player.LastHitPosition = hit.point;

                lastShootTime = Time.time;
            }
        }
Example #4
0
        public override void Fire(float deltaTime)
        {
            AudioPlayer.PlayAudio(shootAudio);

            gun.GetComponent <UnityEngine.Animation>()[AnimationName.SHOTGUN_RELOAD].wrapMode = WrapMode.Once;
            gun.GetComponent <UnityEngine.Animation>().Play(AnimationName.SHOTGUN_RELOAD);


            gunfire.GetComponent <Renderer>().enabled = true;
            shotgunFireTimer.SetTimer(0.2f, false);

            Object.Instantiate(rConf.shotgunBullet, rightGun.position, player.GetTransform().rotation);
            player.LastHitPosition = player.GetTransform().position;

            GameObject shotgunfireObj = Object.Instantiate(rConf.shotgunfire, gunfire.transform.position, player.GetTransform().rotation) as GameObject;

            shotgunfireObj.transform.parent = player.GetTransform();

            float tan60 = Mathf.Tan(Mathf.Deg2Rad * 60.0f);

            int oneShotKills = 0;

            foreach (Enemy enemy in gameScene.GetEnemies().Values)
            {
                if (enemy.GetState() == Enemy.DEAD_STATE)
                {
                    continue;
                }
                Vector3 relativeEnemyPos = player.GetTransform().InverseTransformPoint(enemy.GetPosition());
                float   dis       = (enemy.GetPosition() - player.GetTransform().position).sqrMagnitude;
                float   radiusSqr = range * range;

                if (relativeEnemyPos.z > 0)
                {
                    if (Mathf.Abs(relativeEnemyPos.z / relativeEnemyPos.x) > tan60)
                    {
                        DamageProperty dp = new DamageProperty();
                        dp.damage = damage * player.PowerBuff;
                        if (dis < radiusSqr)
                        {
                            enemy.OnHit(dp, GetWeaponType(), true);
                        }
                        else if (dis < radiusSqr * 2 * 2)
                        {
                            int rnd = Random.Range(0, 100);
                            if (rnd < accuracy)
                            {
                                enemy.OnHit(dp, GetWeaponType(), true);
                            }
                        }
                        else if (dis < radiusSqr * 3 * 3)
                        {
                            int rnd = Random.Range(0, 100);
                            if (rnd < accuracy / 2)
                            {
                                enemy.OnHit(dp, GetWeaponType(), true);
                            }
                        }
                        else if (dis < radiusSqr * 4 * 4)
                        {
                            int rnd = Random.Range(0, 100);
                            if (rnd < accuracy / 4)
                            {
                                enemy.OnHit(dp, GetWeaponType(), true);
                            }
                        }
                    }
                }

                if (enemy.HP <= 0)
                {
                    oneShotKills++;
                }
            }

            if (oneShotKills >= 4)
            {
                GameApp.GetInstance().GetGameState().Achievement.CheckAchievemnet_WeaponMaster();
            }

            GameObject[] woodboxes = gameScene.GetWoodBoxes();
            foreach (GameObject woodbox in woodboxes)
            {
                if (woodbox != null)
                {
                    Vector3 relativeBoxPos = player.GetTransform().InverseTransformPoint(woodbox.transform.position);
                    float   dis            = (woodbox.transform.position - player.GetTransform().position).sqrMagnitude;
                    float   radiusSqr      = range * range;
                    if ((dis < radiusSqr * 2 * 2) && relativeBoxPos.z > 0)
                    {
                        WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>();
                        ws.OnHit(damage * player.PowerBuff);
                    }
                }
            }


            lastShootTime = Time.time;
            sbulletCount--;
            sbulletCount = Mathf.Clamp(sbulletCount, 0, maxCapacity);
        }
Example #5
0
        public override void FireUpdate(float deltaTime)
        {
            if (laserObj != null)
            {
                sbulletCount -= (20f * deltaTime);
                sbulletCount  = Mathf.Clamp(sbulletCount, 0, maxCapacity);

                Vector3    tempTargetPoint = cameraComponent.ScreenToWorldPoint(new Vector3(gameCamera.ReticlePosition.x, Screen.height - gameCamera.ReticlePosition.y, 50));
                Ray        ray             = new Ray(cameraTransform.position, (tempTargetPoint - cameraTransform.position));
                RaycastHit hit;
                //aimTarget = cameraTransform.TransformPoint(0, 0, 20);

                if (Physics.Raycast(ray, out hit, 1000, 1 << PhysicsLayer.WALL | 1 << PhysicsLayer.FLOOR))
                {
                    aimTarget = hit.point;
                }
                else
                {
                    aimTarget = cameraTransform.TransformPoint(0, 0, 1000);
                }

                Vector3 dir = (aimTarget - gunfire.transform.position).normalized;
                float   dis = (aimTarget - gunfire.transform.position).magnitude;
                laserObj.transform.position = (gunfire.transform.position);
                laserObj.transform.LookAt(aimTarget);
                if (hit.collider != null)
                {
                    laserObj.transform.localScale = new Vector3(laserObj.transform.localScale.x, laserObj.transform.localScale.y, dis * 0.5f / 30);
                }


                if (Time.time - lastLaserHitInitiatTime > 0.03f)
                {
                    if ((aimTarget - dir - cameraTransform.position).sqrMagnitude > 3.0f * 3.0f)
                    {
                        Object.Instantiate(rConf.laserHit, aimTarget - dir, Quaternion.identity);
                        lastLaserHitInitiatTime = Time.time;
                    }
                }

                if (CouldMakeNextShoot())
                {
                    /*
                     * foreach (Enemy enemy in gameScene.GetEnemies().Values)
                     * {
                     *  if (enemy.GetState() == Enemy.DEAD_STATE)
                     *  {
                     *      continue;
                     *  }
                     *
                     *  if (laserObj.collider.bounds.Intersects(enemy.GetCollider().bounds))
                     *  {
                     *      Object.Instantiate(rConf.laserHit, enemy.GetPosition(), Quaternion.identity);
                     *      DamageProperty dp = new DamageProperty();
                     *      dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce;
                     *      dp.damage = damage;
                     *      enemy.OnHit(dp, GetWeaponType(), false);
                     *
                     *  }
                     *
                     *
                     * }
                     */
                    GameObject[] woodboxes = gameScene.GetWoodBoxes();
                    foreach (GameObject woodbox in woodboxes)
                    {
                        if (woodbox != null)
                        {
                            if (laserObj.GetComponent <Collider>().bounds.Intersects(woodbox.GetComponent <Collider>().bounds))
                            {
                                WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>();
                                ws.OnHit(damage);
                            }
                        }
                    }



                    if (shootAudio != null)
                    {
                        if (!shootAudio.isPlaying)
                        {
                            AudioPlayer.PlayAudio(shootAudio);
                        }
                    }
                    lastShootTime = Time.time;
                }
            }
        }
Example #6
0
    void OnTriggerEnter(Collider other)
    {
        GameScene gameScene = GameApp.GetInstance().GetGameScene();
        Player    player    = gameScene.GetPlayer();

        /*
         * if (gunType == WeaponType.Sniper)
         * {
         *
         *  Object.Instantiate(rConf.rocketExlposion, proTransform.position, Quaternion.identity);
         *  Object.DestroyObject(gameObject);
         *
         *
         *  if (other.gameObject.layer == PhysicsLayer.ENEMY)
         *  {
         *      Enemy enemy = gameScene.GetEnemyByID(other.gameObject.name);
         *      DamageProperty dp = new DamageProperty();
         *      //dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce;
         *      dp.damage = damage;
         *      enemy.OnHit(dp, gunType, true);
         *  }
         *
         *
         * }
         */

        if (gunType == WeaponType.RocketLauncher || gunType == WeaponType.GrenadeRifle || gunType == WeaponType.Sniper)
        {
            GameObject.Instantiate(rConf.rpgFloor, new Vector3(proTransform.position.x, Constant.FLOORHEIGHT + 0.1f, proTransform.position.z), Quaternion.Euler(270, 0, 0));
            Object.Instantiate(explodeObject, proTransform.position, Quaternion.identity);
            Object.DestroyObject(gameObject);

            player.LastHitPosition = proTransform.position;

            int oneShotKills = 0;

            foreach (Enemy enemy in gameScene.GetEnemies().Values)
            {
                if (enemy.GetState() == Enemy.DEAD_STATE)
                {
                    continue;
                }

                float dis       = (enemy.GetPosition() - proTransform.position).sqrMagnitude;
                float radiusSqr = explodeRadius * explodeRadius;
                if (dis < radiusSqr)
                {
                    DamageProperty dp = new DamageProperty();
                    dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce;

                    if (dis * 4 < radiusSqr)
                    {
                        dp.damage = damage * player.PowerBuff;
                        enemy.OnHit(dp, gunType, true);
                    }
                    else
                    {
                        dp.damage = damage / 2 * player.PowerBuff;
                        enemy.OnHit(dp, gunType, false);
                    }
                }

                if (enemy.HP <= 0)
                {
                    oneShotKills++;
                }
            }

            if (oneShotKills >= 4)
            {
                GameApp.GetInstance().GetGameState().Achievement.CheckAchievemnet_WeaponMaster();
            }

            GameObject[] woodboxes = gameScene.GetWoodBoxes();
            foreach (GameObject woodbox in woodboxes)
            {
                if (woodbox != null)
                {
                    float dis       = (woodbox.transform.position - proTransform.position).sqrMagnitude;
                    float radiusSqr = explodeRadius * explodeRadius;
                    if ((dis < radiusSqr))
                    {
                        WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>();
                        ws.OnHit(damage * player.PowerBuff);
                    }
                }
            }
            return;
        }
        else if (gunType == WeaponType.LaserGun)
        {
            if (other.gameObject.layer == PhysicsLayer.ENEMY)
            {
                Enemy enemy = gameScene.GetEnemyByID(other.gameObject.name);
                if (enemy != null)
                {
                    if (enemy.GetState() != Enemy.DEAD_STATE)
                    {
                        //Object.Instantiate(laserHitObject, enemy.GetPosition(), Quaternion.identity);
                        DamageProperty dp = new DamageProperty();
                        dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce;
                        dp.damage   = damage;
                        enemy.OnHit(dp, gunType, false);
                    }
                }
            }
            else if (other.gameObject.layer == PhysicsLayer.WOODBOX)
            {
                //Debug.Log("hit wood");
                WoodBoxScript ws = other.gameObject.GetComponent <WoodBoxScript>();
                ws.OnHit(damage);
            }
            //Object.Instantiate(laserHitObject, proTransform.position + dir * 2, Quaternion.identity);
        }
        else if (gunType == WeaponType.NurseSaliva)
        {
            if (other.gameObject.layer != PhysicsLayer.ENEMY)
            {
                Ray        ray = new Ray(proTransform.position + Vector3.up * 1.0f, Vector3.down);
                RaycastHit hit;
                float      floorY = Constant.FLOORHEIGHT;
                if (Physics.Raycast(ray, out hit, 100, 1 << PhysicsLayer.FLOOR))
                {
                    floorY = hit.point.y;
                }

                Object.Instantiate(smallExplodeObject, new Vector3(proTransform.position.x, floorY + 0.1f, proTransform.position.z), Quaternion.identity);
                GameObject salivaObj = Object.Instantiate(rConf.nurseSaliva, new Vector3(proTransform.position.x, floorY + 0.1f, proTransform.position.z), Quaternion.Euler(0, 0, 0)) as GameObject;
                salivaObj.transform.Rotate(270, 0, 0);
                Object.DestroyObject(gameObject);
                if ((player.GetTransform().position - proTransform.position).sqrMagnitude < explodeRadius * explodeRadius)
                {
                    player.OnHit(damage);
                }
            }
        }
    }