Exemplo n.º 1
0
        void SpawnBullet()
        {
            Vector3    newBulletPosition = transform.position + transform.rotation * new Vector3(0, bulletOffset, 0);
            PoolObject newBullet         = BulletPool.instance.GetFromPool(newBulletPosition, Quaternion.identity);

            Vector3 scale = transform.lossyScale;

            newBullet.transform.localScale = new Vector3(scale.x * bulletSize, scale.x * bulletSize, scale.z * bulletSize);

            var newBulletRenderer = newBullet.GetComponent <MeshRenderer>();

            newBulletRenderer.material = tank.bodyMaterial;

            var newBulletController = newBullet.GetComponent <Bullet>();
            var newBulletRigidbody  = newBullet.GetComponent <Rigidbody>();

            float halfBulletSpread  = bulletSpread / 2;
            var   newBulletRotation = transform.rotation * Quaternion.Euler(
                Random.Range(-halfBulletSpread, halfBulletSpread),
                0,
                Random.Range(-halfBulletSpread, halfBulletSpread)
                );

            float bulletSpeed    = tank.stats.bulletSpeed.Value * statsMultipliers.bulletSpeed;
            var   bulletVelocity = newBulletRotation * Vector3.up * bulletSpeed;

            newBulletController.normalVelocity = bulletVelocity;
            newBulletRigidbody.velocity        = bulletVelocity + tankRigidbody.velocity;

            newBulletController.tank      = tank;
            newBulletController.damage    = statsMultipliers.bulletDamage * tank.stats.bulletDamage.Value;
            newBulletController.health    = statsMultipliers.bulletPenetration * tank.stats.bulletPenetration.Value;
            newBulletController.knockback = bulletKnockback;
            newBulletController.flyTime   = bulletFlyTime;
        }
Exemplo n.º 2
0
    /// <summary>
    /// Метод, который определяет поведение корабля при его стрельбе
    /// </summary>
    public virtual void Shoot()
    {
        PoolObject  bulletObject    = PoolManager.Get(POOL_BULLET_ID);
        Bullet      bullet          = bulletObject.GetComponent <Bullet>();
        Transform   bulletTransform = bulletObject.transform;
        Rigidbody2D bulletRb        = bulletObject.GetComponent <Rigidbody2D>();

        bulletTransform.rotation = transform.rotation;
        bulletTransform.position = transform.position;

        AudioManager.PlaySoundOnce(S_ENEMY_BULLET);


        if (target != null)
        {
            Vector3 playerDirection = target.position - transform.position;
            playerDirection = playerDirection.normalized;
            bulletRb.AddForce(playerDirection * shootForce);
        }
        else
        {
            bulletRb.AddForce(-transform.up * shootForce);
        }

        bullet.damage = damage;
    }
Exemplo n.º 3
0
    public PoolObject UseObject(PoolObject prefab, Vector3 position, Quaternion rotation, bool setActive = true)
    {
        int id = prefab.GetInstanceID();

        //Controls if dictionary have created pool. if not creates a new one
        if (!poolDictionary.ContainsKey(id))
        {
            CreatePool(prefab, 1);
        }

        //Controls if pool have object that can be used. if not creates new poolobject
        if (poolDictionary[id].Count == 0)
        {
            poolDictionary[id].Enqueue(CreatePoolObject(prefab, id));
        }

        PoolObject gObject = poolDictionary[id].Dequeue();

        pooledObjects.Add(gObject);
        if (gObject.GetComponent <Rigidbody>() != null)
        {
            gObject.GetComponent <Rigidbody>().velocity        = Vector3.zero;
            gObject.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        }

        gObject.transform.position = position;
        gObject.transform.rotation = rotation;
        gObject.gameObject.SetActive(setActive ? true : false);
        return(gObject);
    }
Exemplo n.º 4
0
        private void CreatePlatform()
        {
            int        idPlatform = Random.Range(1, 4);
            PoolObject platform   = PoolManager.Get(idPlatform);
            float      distansFromCenterToEdgeCurrentPlatform      = platform.GetComponent <BoxCollider2D>().size.x *platform.transform.localScale.x / 2;
            float      radiusCreativeZoneRelativeToCurrentPlatform = radiusCreativeZone + distansFromCenterToEdgeCurrentPlatform - 1;

            float yPossitionCurrentPlatformRelativeToZero      = Random.Range(2, jumpHeight);
            float yPossitionCurrentPlatformRelativeToCharacter = yPossitionCurrentPlatformRelativeToZero + oldPlatformPosition.y;

            float currentJumpLenghtForThisY = MaxXforThisY(FindAforThisParabola(jumpLenght, 0, jumpHeight), yPossitionCurrentPlatformRelativeToZero, jumpHeight)
                                              + distansFromCenterToEdgeCurrentPlatform + distansFromCenterToEdgeOldPlatform;

            leftRandomLimitX = oldPlatformPosition.x - currentJumpLenghtForThisY < -radiusCreativeZoneRelativeToCurrentPlatform ?
                               -radiusCreativeZoneRelativeToCurrentPlatform : oldPlatformPosition.x - currentJumpLenghtForThisY;
            rightRandomLimitX = oldPlatformPosition.x + currentJumpLenghtForThisY > radiusCreativeZoneRelativeToCurrentPlatform ?
                                radiusCreativeZoneRelativeToCurrentPlatform : oldPlatformPosition.x + currentJumpLenghtForThisY;

            currentPlatformPosition = new Vector3(RandomWithConditions(leftRandomLimitX, rightRandomLimitX,
                                                                       oldPlatformPosition.x - currentJumpLenghtForThisY / 2, oldPlatformPosition.x + currentJumpLenghtForThisY / 2),
                                                  yPossitionCurrentPlatformRelativeToCharacter, oldPlatformPosition.z);
            platform.transform.position        = currentPlatformPosition;
            oldPlatformPosition                = currentPlatformPosition;
            distansFromCenterToEdgeOldPlatform = distansFromCenterToEdgeCurrentPlatform;

            platform.GetComponent <Platform>().mainCamera = camera;
        }
    public void WizzardAttack()
    {
        PoolObject magic = PoolManager.Instance.UsePoolObject(poolMagic, magicPoint.position, magicPoint.rotation);

        magic.GetComponent <Rigidbody2D>().velocity      = new Vector2(-0.5f, 0) * multiplierOfMagic;
        magic.GetComponent <PoolMagic>().damageableLayer = towerLayer;
        magic.GetComponent <PoolMagic>().damage          = damage;
    }
Exemplo n.º 6
0
    public void RangeAttack()
    {
        PoolObject arrow = PoolManager.Instance.UsePoolObject(poolBullet, bulletPoint.position, bulletPoint.rotation);

        //FindObjectOfType<AudioManager>().PlaySound("ArrowShoot");
        arrow.GetComponent <Rigidbody2D>().velocity       = new Vector2(-0.5f, Random.Range(0.35f, 0.65f)) * multiplierOfArrow;
        arrow.GetComponent <PoolBullet>().damageableLayer = towerLayer;
        arrow.GetComponent <PoolBullet>().damage          = damage;
    }
Exemplo n.º 7
0
    public void PushVisual(int score, VisualType type)
    {
        PoolObject po = _pool.ActivateObject("ScoreVisual");

        po.transform.SetParent(VisualParent);
        po.transform.localScale    = new Vector3(0.25f, 0.25f, 0.25f);
        po.transform.localPosition = new Vector3(0, 0, 0);
        string text = "";

        switch (type)
        {
        case VisualType.SWEET:
            text = "Sweet";
            break;

        case VisualType.COOL:
            text = "Cool";
            break;

        case VisualType.AWESOME:
            text = "Awesome!";
            break;

        case VisualType.MAJESTIC:
            text = "Majestic";
            break;

        case VisualType.ONFIRE:
            text = "On fire";
            break;

        case VisualType.GODLIKE:
            text = "Godlike";
            break;

        case VisualType.CHEAT:
            text = "CHEAT!";
            break;

        case VisualType.SOCLOSE:
            text = "So close";
            break;

        case VisualType.SUPERCLOSE:
            text = "Superclose!";
            break;

        case VisualType.WTF:
            text = "What the...";
            break;
        }
        po.GetComponent <VisualScript>().VisualText.text = text + " +" + score;
        po.GetComponent <Animator>().Play("Score_Addition");

        _visualList.Add(new Visual(0.5f, po));
    }
Exemplo n.º 8
0
    /// <summary>
    /// Метод для вызоыва атаки игрока
    /// </summary>
    public void Attack()
    {
        isShooting = true;

        PoolObject bullet = PoolManager.Get(POOL_PLAYER_BULLET_ID);

        bullet.GetComponent <Bullet>().damage = damage;
        bullet.transform.position             = transform.position;
        bullet.GetComponent <Rigidbody2D>().AddForce(transform.up * shootForce);

        AudioManager.PlaySoundOnce(S_PLAYER_BULLET);
        LeanTween.delayedCall(reloadingTime, () => isShooting = false);
    }
Exemplo n.º 9
0
    public void Start()
    {
        player = Instantiate(cars.cars[GameDataReferences.Instance.carIndex], new Vector3(-3f, 0.55f, -90f), Quaternion.identity);
        player.GetComponent <PoolPlayer>().enabled = true;
        player.GetComponent <PoolCars>().enabled   = false;
        player.GetComponent <ObjectType>().enabled = false;
        vcam.Follow = player.transform;

        themaChooser = GameObject.FindObjectOfType <ThemaChooserScript>();
        themaChooser.OnThemaEvent      += OnThemaEvent;
        playerController                = GameObject.FindObjectOfType <PoolPlayer>();
        playerController.OnPlayerEvent += OnPlayerEvent;
        PauseSystem(true);
    }
Exemplo n.º 10
0
    void SpawnBall()
    {
        PoolObject ballPO = PoolManager.Instance.GetObjectFromPool(PoolObjectItem.ePoolItem.Ball);

        ballPO.ActivatePoolObject();
        ball = ballPO.GetComponent <Ball>();
    }
Exemplo n.º 11
0
    private void CreateCubes()
    {
        _size = Vector2Int.zero;
        foreach (var cubeData in _sectionData.CubeDatas)
        {
            PoolObject poolObject = PoolerManager.Instance.GetPoolObject("Cube", transform);
            Cube       cube       = poolObject.GetComponent <Cube>();
            cube.CellPosition = cubeData.CellPosition + _sectionOffset;
            cube.ChangeCubeType(cubeData.CubeType);
            _cubesByCellPos.Add(cubeData.CellPosition + _sectionOffset, cube);

            if (cubeData.CellPosition.x > _size.x)
            {
                _size.x = cubeData.CellPosition.x;
            }

            if (cubeData.CellPosition.z > _size.y)
            {
                _size.y = cubeData.CellPosition.z;
            }
        }

        foreach (var barrierData in _sectionData.BarrierDatas)
        {
            PoolObject  poolObject  = PoolerManager.Instance.GetPoolObject("BarrierCube", transform);
            BarrierCube barrierCube = poolObject.GetComponent <BarrierCube>();
            barrierCube.StartCellPosition = barrierData.StartCellPosition + _sectionOffset;
            barrierCube.EndCellPosition   = barrierData.EndCellPosition + _sectionOffset;
            barrierCube.Init();
            barrierCube.TriggeredFillingCube += BarrierCube_TriggerFillingCube;
            _barrierCubes.Add(barrierCube);
        }

        _size += Vector2Int.one;
    }
Exemplo n.º 12
0
    private void CastProjectile(PoolObject projectile, SkillUser user, bool rotateProjectile = true)
    {
        PoolObject p = user.userPool.SpawnTargetObject(projectile, 10);

        if (soundOnCastEach)
        {
            EazySoundManager.PlaySound(soundOnCastEach, 0.1f);
        }
        if (user.skillSpawnPoint)
        {
            p.transform.position = user.skillSpawnPoint.position;
        }
        else
        {
            p.transform.position = user.transform.position;
        }
        //p.transform.position += user.userAim.aimDirection.normalized * spawnDistanceMultiplier;
        if (rotateProjectile)
        {
            user.userAim.RotateObjectToAim(p.transform);
        }
        p.GetComponent <ProjectileObject>().InitializeProjectile(user);
        if (castingKnockback > 0)
        {
            user.userStats.rb.velocity = Vector3.zero;
            Vector3 kDirection = user.userAim.aimDirection.normalized;
            if (!forwardCastingKnockback)
            {
                kDirection.y *= -1; kDirection.x *= -1; //eu sei que dava pra fazer numa conta só, mas só assim vai
            }
            user.userStats.rb.AddForce(kDirection * castingKnockback);
        }
    }
Exemplo n.º 13
0
    IEnumerator SpawnBlocks()
    {
        yield return(new WaitForSeconds(1)); // hold the spawner for the countdown

        UnlockLine();
        while (true)                                                                             // sounds so bad
        {
            List <SpawnPointScript> _possibleLocations = SpawnPoints.FindAll(e => e.IsUnlocked); // Lambda again, a little bit heavier but its on separate thread

            float delay = _level.CurrentSpawnDelay;
            if (_possibleLocations.Count > 0)
            {
                int line = Random.Range(0, _possibleLocations.Count); // Range is exclusive the max value
                                                                      // TTT Fix this for the amount we have
                                                                      // get a random size

                if (!_spawnCredit)
                {
                    int size = Random.Range(2, 5);
                    delay *= size;
                    PoolObject block = _pool.ActivateObject("L1Block" + size);
                    block.GetComponent <Rigidbody2D>().transform.rotation = Quaternion.Euler(0, 0, 90);
                    block.GetComponent <BlockScript>().MovementSpeed      = 250.0f;

                    block.transform.position = _possibleLocations[line].transform.position;

                    _activeLevelBlocks.Add(block);
                }
                else
                {
                    int size = Random.Range(2, 5);
                    delay *= size;

                    PoolObject credit = _pool.ActivateObject("Credit");
                    credit.GetComponent <CreditScript>().MovementSpeed = 250.0f;

                    credit.transform.position = _possibleLocations[line].transform.position;

                    _activeLevelBlocks.Add(credit);

                    _spawnCredit = false;
                }
            }
            yield return(new WaitForSeconds(delay));
        }
    }
Exemplo n.º 14
0
    void SpawnPaddle()
    {
        PoolObject paddle = PoolManager.Instance.GetObjectFromPool(PoolObjectItem.ePoolItem.Paddle);

        paddle.ActivatePoolObject();
        paddle.transform.position = new Vector3(0, -3, 0);
        playerPaddle = paddle.GetComponent <Paddle>();
    }
Exemplo n.º 15
0
 void Update()
 {
     if (Input.GetMouseButton(0))
     {
         PoolObject bullet = PoolManager.Get(1);
         bullet.transform.position = transform.position;
         bullet.GetComponent <Bullet>().Shoot();
     }
 }
Exemplo n.º 16
0
    public void CastSkill(PoolObject projectile, SkillUser user)
    {
        PoolObject p = user.userPool.SpawnTargetObject(projectile, 1);

        if (user.userAim.focusPoint != null)
        {
            p.transform.position = user.userAim.focusPoint;
        }
        p.transform.position = new Vector3(p.transform.position.x, p.transform.position.y, 0);
        p.GetComponent <ProjectileObject>().InitializeProjectile(user);
    }
Exemplo n.º 17
0
 public void HumanDie(PoolObject human)
 {
     human.DestroedObject -= HumanDie;
     AllDead -= human.GetComponent <HumanBehavior>().Dead;
     if (!isGameOver)
     {
         isGameOver = true;
         AllDead(this);
         GameOver();
     }
 }
Exemplo n.º 18
0
    private void OnBulletCreated(PoolObject poolObj)
    {
        Bullet bullet = poolObj.GetComponent <Bullet>();

        initialization?.Invoke(bullet);

        poolObj.onEnable += () =>
        {
            initialization?.Invoke(bullet);
        };
    }
Exemplo n.º 19
0
    /// <summary>
    /// создаём объект на одной из 4-х сторон экрана, где 1-лево, 2-верх, 3-низ, 4-право
    /// затем сетим нужные данные в зависимости от того создали астероид или тарелку
    /// </summary>
    private void Spawn()
    {
        Vector3 startPos;
        Vector3 endPos;

        switch (Random.Range(1, 4))
        {
        case 1:
            startPos = new Vector3(-_stats.width, Random.Range(-_stats.height, _stats.height), 1);
            endPos   = new Vector3(_stats.width, Random.Range(-_stats.height, _stats.height), 1);
            break;

        case 2:
            startPos = new Vector3(Random.Range(-_stats.width, _stats.width), -_stats.height, 1);
            endPos   = new Vector3(Random.Range(-_stats.width, _stats.width), _stats.height, 1);
            break;

        case 3:
            startPos = new Vector3(_stats.width, Random.Range(-_stats.height, _stats.height), 1);
            endPos   = new Vector3(-_stats.width, Random.Range(-_stats.height, _stats.height), 1);
            break;

        default:
            startPos = new Vector3(Random.Range(-_stats.width, _stats.width), _stats.height, 1);
            endPos   = new Vector3(Random.Range(-_stats.width, _stats.width), -_stats.height, 1);
            break;
        }
        Vector2 direction = endPos - startPos;
        float   angle     = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;

        if (SpawnUfo())
        {
            _obj = PoolManager.Get(_Ufo);
            Ufo component = _obj.GetComponent <Ufo>();
            _obj.transform.position = startPos;
            _obj.transform.rotation = Quaternion.Euler(0, 0, -angle);
            component.target        = _targetForUfo;
            component.Shot();
        }
        else
        {
            _obj = PoolManager.Get(_Asteroid);
        }
        _obj.transform.position = startPos;
        _obj.transform.rotation = Quaternion.Euler(0, 0, -angle);
        Enemy enemy = _obj.GetComponent <Enemy>();

        enemy.gameController = _gameController;
        enemy.speed          = GetSpeed();
        enemy.Move();
        StartCoroutine(SpawnDelay());
    }
Exemplo n.º 20
0
    public override void InitializeProjectile(SkillUser user)
    {
        float currentAngle = 0;

        while (currentAngle < 360)
        {
            PoolObject p = pool.SpawnTargetObject(iceShardPrefab, 20);
            p.GetComponent <ProjectileObject>().InitializeProjectile(user);
            p.transform.position = transform.position;
            p.transform.rotation = Quaternion.Euler(0, 0, currentAngle);
            currentAngle        += angleBetweenShards;
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// Метод для уничтожения игрока
    /// </summary>
    public void DestroyPlayer()
    {
        PoolObject fx = PoolManager.Get(POOL_EXPLOSION_ID);

        fx.GetComponent <SpriteRenderer>().color = Color.yellow;
        fx.transform.position = transform.position;
        gameObject.SetActive(false);

        AudioManager.PlaySoundOnce(S_PLAYER_BULLET);

        //Конец игры
        LeanTween.delayedCall(END_GAME_PAUSE_TIME, () => UIController.instance.EndGame(false));
    }
Exemplo n.º 22
0
    internal void Initialize()
    {
        for (int i = 0; i < BoidNumber; i++)
        {
            PoolObject po   = GameObjectPoolManager.Instance.PoolDict[BoidType].AllocateGameObject <PoolObject>(Container);
            Boid       boid = po.GetComponent <Boid>();
            Boids.Add(boid);
            boid.transform.position = new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f), Random.Range(-50f, 50f));
            boid.Initialize(this);
        }

        RefreshCommonVars();
    }
Exemplo n.º 23
0
    IEnumerator Fire(float delay)
    {
        yield return(new WaitForSeconds(delay));

        if (_loadedBullet != null)
        {
            // unlink the bullet
            _loadedBullet.GetComponent <Rigidbody2D>().velocity = 300.0f * _loadedBullet.transform.right;
            _loadedBullet = null; // release bullet

            // fire it off
            _currentReloadDelay = ReloadDelay;
        }
    }
Exemplo n.º 24
0
 public void ApplyBuffs(SkillUser user)
 {
     user.userStats.ApplyState(buffToApply);
     if (stillGraph)
     {
         PoolObject p = user.userPool.SpawnTargetObject(stillGraph, 1, user.transform);
         p.GetComponent <StillGraph>().Initialize(null, user.userStats.GetStack(buffToApply).stateDuration, user.transform);
     }
     if (castEffect)
     {
         PoolObject p = user.userPool.SpawnTargetObject(castEffect, 1, user.transform);
         p.transform.localPosition = Vector3.zero;
     }
 }
Exemplo n.º 25
0
    private IEnumerator SpawnShip()
    {
        while (true)
        {
            yield return(new WaitForSeconds(BOSS_JET_SPAWN_TIME));

            PoolObject shipObject = PoolManager.Get(POOL_BOSS_SHIP_ID);
            shipObject.transform.position = transform.position;
            BaseShip ship = shipObject.GetComponent <BaseShip>();
            ship.Activate();
            ship.target      = WaypointController.instance.attakPoint;
            ship.attackState = true;
        }
    }
Exemplo n.º 26
0
    public void Open(bool instant = false, bool toggle = true)
    {
        if (toggle)
        {
            open = !open;        //disabling toggle allows me to call this method to update the size of the container when it's already open
        }
        float itemHeight = itemPrefab.GetComponent <QuestMenuItem>().rect.rect.height;

        if (open)
        {
            EnableItems();
            if (instant)
            {
                container.LeanSize(new Vector2(container.rect.width, originalHeight + (itemHeight + verticalOffset) * itemList.Count), 0.02f)
                .setEaseInOutCubic().setIgnoreTimeScale(true);
            }
            else
            {
                container.LeanSize(new Vector2(container.rect.width, originalHeight + (itemHeight + verticalOffset) * itemList.Count), 0.3f)
                .setEaseInOutCubic().setIgnoreTimeScale(true);
            }
        }
        else   //fechar
               //TO DO: Prevent selecting the items while the list is disappearing
        {
            if (instant)
            {
                container.LeanSize(new Vector2(container.rect.width, originalHeight), 0.02f)
                .setEaseInOutCubic().setOnComplete(DisableItems).setIgnoreTimeScale(true);
            }
            else
            {
                container.LeanSize(new Vector2(container.rect.width, originalHeight), 0.3f)
                .setEaseInOutCubic().setOnComplete(DisableItems).setIgnoreTimeScale(true);
            }
        }
    }
Exemplo n.º 27
0
    public void LoseLife(Vector3 collisionPos)
    {
        PoolObject po = _pool.ActivateObject("BlockHitParticles");

        if (po == null)
        {
            Debug.Log("No particles");
        }
        Vector3 pos = collisionPos;

        pos.z = -3;
        po.transform.position = pos;
        po.GetComponent <ParticleScript>().Fire();
        LoseLife();
    }
Exemplo n.º 28
0
    public void SpawnPrefabs()
    {
        int targetAmount = Mathf.RoundToInt(Random.Range(amountConstraints.x, amountConstraints.y));

        for (int i = 0; i < targetAmount; i++)
        {
            PoolObject po = pooler.SpawnTargetObject(targetPrefab, amountToPool, transform);
            po.transform.position = transform.position;
            float       targetForce = Random.Range(forceConstraints.x, forceConstraints.y);
            Rigidbody2D rb          = po.GetComponent <Rigidbody2D>();
            if (rb)
            {
                rb.AddForce(targetForce * Random.insideUnitCircle, ForceMode2D.Impulse);
            }
        }
    }
Exemplo n.º 29
0
        void Shot(Transform playerObj)
        {
            timer += Time.deltaTime;

            if (timer >= attackCooldown)
            {
                animator.SetTrigger("Attack");

                pool = PoolManager.GetInstance().GetPool("ProyectilePool");

                PoolObject po = pool.GetPooledObject();
                po.GetComponent <Bullet_Script>().SetEnemyTag(playerObj.tag);
                po.gameObject.transform.position = enemyObj.position;
                po.gameObject.transform.rotation = enemyObj.rotation;
                timer = 0;
            }
        }
Exemplo n.º 30
0
    public void Shot()
    {
        if (isDead)
        {
            return;
        }
        Vector3    targetPos = target.position;
        Vector2    direction = targetPos - transform.position;
        float      angle     = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        PoolObject bullet    = PoolManager.Get(6);

        bullet.transform.position = transform.position;
        bullet.transform.rotation = Quaternion.Euler(0, 0, -angle);
        Bullet comp = bullet.GetComponent <Bullet>();

        comp.Init(_stats.shotSpeed, _stats.bulletDestroyDelay);
        StartCoroutine(ShotDelay());
    }