void Attack()
    {
        if (m_CharacterBase.m_Live == CharacterBase.E_Live.DEAD)
        {
            return;
        }
        if (m_CharacterBase.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.CAST)
        {
            return;
        }

        if (m_CharacterBase.m_UpperAnimState != CharacterBase.E_UpperBodyAnimState.ATTACK)
        {
            m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimGunAttackKey, 0.0f);
            m_CharacterBase.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.ATTACK;
            m_AttackDelay = 0.05f;
            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotActivate();
            }
        }

        if (m_AttackDelay <= 0.0f)
        {
            m_AttackDelay = 0.15f;
            for (int i = 0; i < m_CharacterBase.GetGunAttachCount(); ++i)
            {
                SoundManager.Instance.PlayInstanceSound(m_CharacterBase.GetGun(i).GetFirePoint().position, m_CharacterBase.GetGun(i).GetFireSound());
                BulletSystem.CreateBullet(m_CharacterBase.GetGun(i).GetFirePoint().position, 1.0f,
                                          m_CharacterBase.m_CharacterID, E_BulletType.ORANGE, 1, m_CharacterBase.GetUpperBodyDirection(), 30.0f, m_TargetLayerMask, 5);
            }
        }
    }
Пример #2
0
    public void OnBulletCollision(Collider collider)
    {
        // Check bullet source
        BulletSystem bullet = collider.GetComponent<BulletSystem>();
        if (bullet.shooter != this.gameObject)
        {
            // Take damage
            healthSystem.TakeDamage(bullet.damage);

            bool destroyBullet = true;

            // Check for bullet type
            switch (bullet.type)
            {
                case BaseWeapon.BulletType.Piercing:
                    destroyBullet = false;
                    break;
                case BaseWeapon.BulletType.Fire:
                    break;
                case BaseWeapon.BulletType.Ice:
                    break;
                default:
                    break;
            }

            if (destroyBullet)
                bullet.Destroy();
        }
    }
Пример #3
0
    private void TerminateShoot(Vector3 shootTo)
    {
        // Create object at shooter location
        GameObject bullet = Instantiate(bulletObject, shootFrom.transform.position, Quaternion.Euler(bulletObject.transform.eulerAngles));
        // Get default rotation
        Quaternion rotation = bullet.transform.rotation;

        // Orientate object
        Debug.DrawLine(bullet.transform.position, shootTo, Color.red);
        rotation.SetLookRotation(shootTo - bullet.transform.position, Vector3.up);
        // Remove x component, shoot parallel to ground
        Vector3 angles = rotation.eulerAngles;

        angles.x = angles.z = 0;
        bullet.transform.rotation = Quaternion.Euler(angles);
        // Set parameters
        BulletSystem bulletSystem = bullet.GetComponent <BulletSystem>();

        bulletSystem.damage   = equipedWeapon.DamagePerShot;
        bulletSystem.LifeTime = equipedWeapon.BulletLifeTime;
        // Set shooter, shooter don't trigger collisions from his bullets
        bulletSystem.shooter = gameObject;
        // Enable bullet lifetime
        bulletSystem.isActive = true;
        // Set force
        bullet.GetComponent <Rigidbody>().AddForce(BaseWeapon.SHOOT_SPEED_CONST_MOD * bullet.transform.forward * equipedWeapon.ShootSpeed, ForceMode.Force);
    }
Пример #4
0
 // Start is called before the first frame update
 void Start()
 {
     Application.targetFrameRate = 60;
     audioSource        = GetComponent <AudioSource>();
     playerBulletSystem = transform.Find("PlayerBulletSystem").GetComponent <BulletSystem>();
     enemyBulletSystem  = transform.Find("EnemyBulletSystem").GetComponent <BulletSystem>();
     cam = transform.Find("Main Camera").GetComponent <Camera>();
     //train = FindObjectOfType<Train>();
     levelProperties = FindObjectOfType <LevelProperties>();
     ui = GetComponentInChildren <UI_Controller>();
     // Load audio clip resources
     audioClips = new Dictionary <string, AudioClip>();
     AudioClip[] clips = Resources.LoadAll <AudioClip>("Sound");
     foreach (AudioClip clip in clips)
     {
         audioClips.Add(clip.name, clip);
         Debug.LogFormat("loaded audio resource {0}", clip.name);
     }
     // Make sure we found everything we need
     Debug.Assert(cam, "Cannot find Main Camera");
     Debug.Assert(playerBulletSystem, "Cannot find PlayerBulletSystem");
     Debug.Assert(enemyBulletSystem, "Cannot find EnemyBulletSystem");
     Debug.Assert(ui, "Cannot find UI_Controller");
     Debug.Assert(audioSource);
 }
Пример #5
0
    public void Init()
    {
        mStageSystem  = new StageSystem();
        mTankSystem   = new TankSystem();
        mBulletSystem = new BulletSystem();
        mCameraSystem = new CameraSystem();

        mStageSystem.Init();
        mTankSystem.Init();
        mBulletSystem.Init();
        mCameraSystem.Init();
    }
Пример #6
0
 private void OnCollision(Collider collider)
 {
     if (collider.tag == "Bullet")
     {
         // Collision between 2 bullet destroys them
         BulletSystem bullet = collider.GetComponent <BulletSystem>();
         if (bullet.shooter == shooter)
         {
             bullet.Destroy();
             this.Destroy();
         }
     }
 }
Пример #7
0
    //generates map using given generator
    void GenerateMap(MapGenerator mapGenerator)
    {
        floorTileLayer   = new GameObject[width, height];
        wallTileLayer    = new GameObject[width, height];
        worldObjectLayer = new GameObject[width, height];
        pickupSystem     = new PickupSystem();
        bulletSystem     = new BulletSystem();

        mapGenerator.Generate(this);

        Player player = GameManager.instance.GetPlayer();

        player.SetPosition(startX, startY);
    }
Пример #8
0
    public override void _Ready()
    {
        bulletSystem    = GetNode <BulletSystem>("BulletSystem");
        laserStream     = GetNode <AudioStreamPlayer3D>("LaserStream");
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");

        bulletSystem.container = GetParent();

        bulletSystem.Connect(nameof(BulletSystem.Fired), this, nameof(_OnFired));
        Connect("area_entered", this, nameof(_OnAreaEntered));

        ComputeRectLimits();

        initialPosition = GlobalTransform.origin;
    }
Пример #9
0
 // Start is called before the first frame update
 void Start()
 {
     if (control == Control.TargetTrain)
     {
         bulletSystem = GameController.self.enemyBulletSystem;
     }
     else
     {
         bulletSystem = GameController.self.playerBulletSystem;
     }
     tip        = transform.Find("Tip");
     attackable = transform.parent.GetComponent <Attackable>();
     Debug.Assert(tip, "Tip not found");
     Debug.Assert(bulletSystem);
 }
Пример #10
0
    private void Awake()
    {
        entities        = new List <Entity>();
        newEntities     = new Queue <Entity>();
        expiredEntities = new Queue <Entity>();

        entitySystem     = new EntitySystem(this);
        inputSystem      = new InputSystem(this);
        moveSystem       = new MoveSystem(this);
        controllerSystem = new ControllerSystem(this);
        gunSystem        = new GunSystem(this);
        bulletSystem     = new BulletSystem(this);
        buffSystem       = new BuffSystem(this);
        aiSystem         = new AISystem(this);
        levelSystem      = new LevelSystem(this);
    }
Пример #11
0
    public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);

        if (!m_AICharacter)
        {
            return;
        }
        if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD)
        {
            if (m_AICharacter.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.ATTACK)
            {
                m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.DEATH;
                m_AICharacter.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f);
            }
            return;
        }
        if (!m_AICharacter.m_TargetCharacter)
        {
            return;
        }

        if (m_AICharacter.GetAIState() != AICharacter.E_AIState.ATTACK)
        {
            return;
        }

        if (m_AICharacter.m_UpperAnimState != CharacterBase.E_UpperBodyAnimState.ATTACK)
        {
            m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.ATTACK;
            m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimGunAttackKey, 0.1f * GameManager.Instance.TimeScale);
            m_AttackDelay = 0.1f;
        }

        if (m_AttackDelay > 0.0f)
        {
            m_AttackDelay -= _DeltaTime;
            return;
        }

        m_AttackDelay = m_AICharacter.GetAIData().AttackDelay;

        if (m_AICharacter.GetAIData().Belligerence < (1.0f - Random.Range(0.0f, 1.0f)))
        {
            m_AttackDelay += m_AICharacter.GetAIData().Belligerence *(1.0f - Random.Range(0.0f, 1.0f));
        }

        Vector3 upperbodyDir       = m_AICharacter.GetUpperBodyDirection();
        Vector3 upperbodyDirNormal = upperbodyDir.normalized;
        Vector3 targetDir          = m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position;
        float   tdistance          = targetDir.magnitude;
        float   d = Vector3.Dot(upperbodyDirNormal, targetDir.normalized);

        if (d > 0.95f && tdistance <= m_AICharacter.GetAIData().AttackRange)
        {
            if (Physics.Raycast(m_AICharacter.GetBodyPositionWithWorld(), upperbodyDirNormal, tdistance * 0.3f, m_ObstacleLayerMask))
            {
                foreach (Gun g in m_CharacterBase.GetGuns())
                {
                    g.GunShotDisable();
                }
                return;
            }

            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotActivate();
            }
            for (int i = 0; i < m_AICharacter.GetGunAttachCount(); ++i)
            {
                BulletSystem.CreateBullet(m_AICharacter.GetGun(i).GetFirePoint().position, 1.0f,
                                          m_AICharacter.m_CharacterID, E_BulletType.ORANGE, 1, upperbodyDir, 30.0f, m_TargetLayerMask, 5);
            }
            SoundManager.Instance.PlayInstanceSound(m_CharacterBase.GetGun(0).GetFirePoint().position, m_CharacterBase.GetGun(0).GetFireSound());
        }
        else
        {
            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotDisable();
            }
        }
    }
Пример #12
0
    public static BulletSystem Instance;//Singleton

    private void Awake()
    {
        Instance = this;//Singleton
    }