コード例 #1
0
ファイル: PlayerController.cs プロジェクト: alext236/Bomber-Z
    private void checkBombHitPlayer()
    {
        if (check_hit_bomb == null)
            return;
        if (check_hit_bomb.Count > 0)
        {
            bool mHit_flag = false;
            for (int i = 0; i < check_hit_bomb.Count && !mHit_flag; i++)
            {
                delta_time[i] = (float) (delta_time[i]) + Time.deltaTime;
                if ((float) (delta_time[i]) > 1.3f*(float) (bombFireTime[i]))
                {
                    check_hit_bomb[i] = false;
                }

                Vector3 p_pos = transform.position;
                float dis = (p_pos - (Vector3)last_bomb_pos[i]).magnitude;

                for (int j = 0; j < 5 && !mHit_flag; j++)
                {
                    if ((bool) ((ArrayList) check_directions_forEachBomb[i])[j] && dis <= (float)((ArrayList)bombFireLength[i])[j] && (bool)check_hit_bomb[i])
                    {
                        //cast rays on different directions
                        Vector3 mDir = getDirection(j);
                        Vector3 pos = (Vector3)last_bomb_pos[i];
                        float ray_dis = ((float)((ArrayList)bombFireLength[i])[j]) * (float)delta_time[i];
                        if ((float)delta_time[i] > 1.0f)
                            ray_dis = ((float)((ArrayList)bombFireLength[i])[j]);
                        if (mDir == Vector3.down)
                        {
                            ray_dis = 5 * ((float)((ArrayList)bombFireLength[i])[j]);
                            pos -= 3 * mDir;
                        }
                        Ray impactRay = new Ray(pos, mDir);
                        RaycastHit[] hit = Physics.RaycastAll(impactRay, ray_dis);

                        //sort rays based on the distance of objects
                        ArrayList hit_arr = new ArrayList();
                        for (int k = 0; k < hit.Length; k++)
                            hit_arr.Add(hit[k]);
                        if (hit_arr.Count > 0)
                        {
                            IComparer myComparer = new mySortClass();
                            hit_arr.Sort(myComparer);
                        }

                        bool flag_continue_on_ray = true;
                        for (int k = 0; k < hit_arr.Count && flag_continue_on_ray; k++)
                        {
                            RaycastHit m_hit = (RaycastHit)hit_arr[k];
                            Debug.DrawLine(pos, pos + mDir * ray_dis * (float) delta_time[i], Color.red);
                            if (m_hit.transform.name == "Player")
                            {
                                //Do something to the player
                                Debug.Log("The player is hit by the bomb ");
                                AudioSource.PlayClipAtPoint(playerHurtSound, transform.position);

                                mHit_flag = true;
                                check_hit_bomb[i] = false;
                                flag_continue_on_ray = false;
                            }
                            if (m_hit.collider.GetComponent<IndestructibleWall>() || m_hit.collider.GetComponent<DestructibleWall>())
                            {
                                flag_continue_on_ray = false;
                                ((ArrayList) check_directions_forEachBomb[i])[j] = false;
                            }
                        }
                    }//if direction j of bomb i
                }//for directions
            }

            for (int i = 0; i < check_hit_bomb.Count; i++)
            {
                if (!(bool) (check_hit_bomb[i]))
                {
                    check_hit_bomb.RemoveAt(i);
                    delta_time.RemoveAt(i);
                    last_bomb_pos.RemoveAt(i);
                    bombFireLength.RemoveAt(i);
                    bombFireTime.RemoveAt(i);
                    check_directions_forEachBomb.RemoveAt(i);
                    i--;
                }
            }

            if (mHit_flag)
            {
                HitPlayer();
            }
        }
    }
コード例 #2
0
ファイル: EnemyScript.cs プロジェクト: alext236/Bomber-Z
    private void checkBombHitEnemy()
    {
        if (check_hit_bomb == null)
            return;
        if (check_hit_bomb.Count > 0)
        {
            bool mHit_flag = false;
            for (int i = 0; i < check_hit_bomb.Count && !mHit_flag; i++)
            {
                delta_time[i] = (float) (delta_time[i]) + Time.deltaTime;
                if ((float)(delta_time[i]) > 1.3f * (float)(bombFireTime[i]))
                {
                    check_hit_bomb[i] = false;
                }

                Vector3 p_pos = transform.position;
                float dis = (p_pos - (Vector3)last_bomb_pos[i]).magnitude;

                for (int j = 0; j < 5 && !mHit_flag; j++)
                {
                    if ((bool) ((ArrayList) check_directions_forEachBomb[i])[j] && dis <= (float) ((ArrayList) bombFireLength[i])[j] && (bool) check_hit_bomb[i])
                    {
                        //cast rays on different directions
                        Vector3 mDir = getDirection(j);
                        Vector3 pos = (Vector3)last_bomb_pos[i];
                        float ray_dis = ((float)((ArrayList)bombFireLength[i])[j]) * (float)delta_time[i];
                        if ((float)delta_time[i] > 1.0f)
                            ray_dis = ((float)((ArrayList)bombFireLength[i])[j]);
                        if (mDir == Vector3.down)
                        {
                            pos -= 3 * mDir;
                            ray_dis = 5 * ray_dis;
                        }
                        Ray impactRay = new Ray(pos, mDir);
                        RaycastHit[] hit = Physics.RaycastAll(impactRay, ray_dis);

                        //sort rays based on the distance of objects
                        ArrayList hit_arr = new ArrayList();
                        for (int k = 0; k < hit.Length; k++)
                            hit_arr.Add(hit[k]);
                        if (hit_arr.Count > 0)
                        {
                            IComparer myComparer = new mySortClass();
                            hit_arr.Sort(myComparer);
                        }

                        bool flag_continue_on_ray = true;
                        for (int k = 0; k < hit_arr.Count && flag_continue_on_ray; k++)
                        {
                            RaycastHit m_hit = (RaycastHit)hit_arr[k];
                            Debug.DrawLine(pos, pos + mDir * ray_dis * (float) delta_time[i], Color.red);
                            if (m_hit.transform.name == this.transform.name)
                            {
                                //Do something to the player
                                Debug.Log("The " + this.transform.name + " is hit by the bomb ");

                                mHit_flag = true;
                                check_hit_bomb[i] = false;
                                flag_continue_on_ray = false;
                            }
                            if (m_hit.transform.name == "Cube")
                            {
                                flag_continue_on_ray = false;
                                ((ArrayList) check_directions_forEachBomb[i])[j] = false;
                            }
                        }
                    }//if direction j of bomb i
                }//for directions
            }

            for (int i = 0; i < check_hit_bomb.Count; i++)
            {
                if (!(bool) (check_hit_bomb[i]))
                {
                    check_hit_bomb.RemoveAt(i);
                    delta_time.RemoveAt(i);
                    last_bomb_pos.RemoveAt(i);
                    bombFireLength.RemoveAt(i);
                    bombFireTime.RemoveAt(i);
                    check_directions_forEachBomb.RemoveAt(i);
                    i--;
                }
            }

            if (mHit_flag)
            {
                if (EnemyType == myEnemyType.FollowingPlayer)
                    mPlayerInfo.IncreasePlayerPoint((float)myEnemyPoints.FollowingPlayer, PlayerController.myPointType.Enemy);
                else
                    mPlayerInfo.IncreasePlayerPoint((float)myEnemyPoints.NotFollowingPlayer, PlayerController.myPointType.Enemy);
                if (this.respawnedable)
                {

                }
                else
                {
                    DestroyObject(gameObject);
                }
                //                m_Agent.nextPosition = this.transform.position;
            }
        }
    }
コード例 #3
0
ファイル: Bomb.cs プロジェクト: alext236/Bomber-Z
    void DrawRaycast(Vector3 direction)
    {
        Vector3 mgrid_size = FindObjectOfType<CreateMap>().getGridSize();
        float max_size = Mathf.Max(mgrid_size[0], mgrid_size[2]);
        Vector3 pos = transform.position;
        if (direction == Vector3.down)
            pos -= 3*Vector3.down;
        float dis = (length * max_size + max_size / 2) * fireTime - max_size / 20;
        Ray impactRay = new Ray(pos, direction);

        RaycastHit[] hit = Physics.RaycastAll(impactRay, dis);
        ArrayList hit_arr = new ArrayList();
        for (int i = 0; i < hit.Length; i++)
            hit_arr.Add(hit[i]);
        if (hit_arr.Count > 0)
        {
            IComparer myComparer = new mySortClass();
            hit_arr.Sort(myComparer);
        }

        Debug.DrawLine(pos + new Vector3(0,1,0), new Vector3(0,1,0) + pos + direction * dis, Color.red);
        bool flag_continue = true;
        float animation_length = length;
        for (int i = 0; i < hit_arr.Count && flag_continue; i++)
        {
            RaycastHit m_hit = (RaycastHit)hit_arr[i];
            if (m_hit.collider.tag == "IndestructibleWall")
            {
                animation_length = GetDistanceToNearestWall(m_hit.collider.gameObject, direction);
                flag_continue = false;
            }
            else if (m_hit.collider.GetComponent<DestructibleWall>())//Change this to recognize 'DestructibleWall' class instead
            {
                // if the actual fire length is smaller than planned fire length then the time that fire reach to the object is the portion of the planned time
                animation_length = GetDistanceToNearestWall(m_hit.collider.gameObject, direction);
                animation_length = ((animation_length) * max_size + max_size / 20);
                float planned_length = ((length) * max_size + max_size / 2);
                float ratio_real_planned = animation_length / (planned_length * fireTime);

                for (int j = 0; j < m_enemies.Count; j++)
                {
                    GameObject m_enemy_j = (GameObject)m_enemies[j];
                    if (m_enemy_j != null)
                        m_enemy_j.GetComponent<EnemyScript>().mUpdateMyMap(m_hit.collider.gameObject.transform.position);
                }
                //Spawn a powerup based on its drop chance
                m_hit.collider.GetComponent<DestructibleWall>().SpawnAPowerUp();

        //                mPlayerInfo.IncreasePlayerPoint(1.0f, PlayerController.myPointType.Cube);

                Destroy(m_hit.collider.gameObject, ratio_real_planned * fireTime);
                flag_continue = false;

            }
            flagCheckPlayer = true;
            flagCheckEnemy = true;
            //Bomb can explode other bombs
            if (m_hit.collider.GetComponent<Bomb>())
            {
                Bomb bomb = m_hit.collider.GetComponent<Bomb>();
                //Trigger only the bomb that has not been triggered
                if (!bomb.BombTriggered)
                {
                    bomb.BombExplode();
                }

            }
        }
        Firelength_bomb_i.Add(animation_length * (max_size) + max_size / 2);
    }