// Start is called before the first frame update
 void Awake()
 {
     ProjectileProcessor.Init();
     isCreated      = false;
     isPrefabLoaded = false;
     attackTime     = 0;
 }
Пример #2
0
    //load game
    public void Load()
    {
        PlayerData playerData = saveLoadPlayer.LoadData();

        if (playerData != null)
        {
            MapName savedMap = (MapName)playerData.map;

            //don't load if the data is for a different map
            if (savedMap == 0 || savedMap.Equals(mapName))
            {
                score = playerData.score;
                PlayerPrefs.SetInt("CurrentScore", score);

                float[] c = playerData.coords;
                coords = new Vector3(c[0], c[1], c[2]);
                player.transform.position = coords;

                var playerMove = player.GetComponent <PlayerMovement>();
                AbilityProcessor.Fetch((PlayerAbilities)playerData.abilityType, playerMove);

                ProjectileProcessor.SetProjectileName((PlayerProjectiles)playerData.projectileType);

                /*
                 * Sample Hierarchy of GameObject Tile
                 * to change the checkpoint image
                 *  Tile
                 *      -> Obstacles
                 *      -> Checkpoint1
                 *          -> CheckpointScript
                 *
                 * Process:
                 *  - Find the child gameobject using the name
                 *  - Call the ChangeState() of the child script
                 */

                //name of the loaded checkpoint
                checkpointTag = playerData.checkpointTag;

                //gets the list its children
                Transform[] childrenObj = tileObject.GetComponentsInChildren <Transform>();

                foreach (Transform obj in childrenObj)
                {
                    //if name matches with checkpointTag, change the state
                    if (obj.name == checkpointTag)
                    {
                        CheckpointScript objScript = obj.GetComponent <CheckpointScript>();
                        objScript.ForceWave();
                        break;
                    }
                }
            }
            else
            {
                Debug.Log("Data is for the different map. Data is not loaded");
            }
        }
    }
    public void Attack(bool isMoving, bool attack)
    {
        //creates a projectile clone
        if (attack && (attackTime <= Time.time && !isCreated))
        {
            if (!isPrefabLoaded)
            {
                projectilePrefab = ProjectileProcessor.GetPrefab(chosenProjectile);
                projectileName   = ProjectileProcessor.GetProjectileName();
                isPrefabLoaded   = true;
            }

            //set the shotgun location to attackhandsource
            if (projectileName == "Shotgun")
            {
                projectile = Instantiate(projectilePrefab, attackHandSource.position,
                                         attackHandSource.rotation);
            }
            else
            {
                projectile = Instantiate(projectilePrefab, attackSource.position,
                                         attackSource.rotation);
            }

            //creates the projectile
            projectileScript = projectile.GetComponent <ProjectileManager>();

            //updates and fetches projectile's data
            projectileScript.SetPlayerMoving(isMoving);
            fireRate    = fireRates[projectileScript.GetName()];
            explodeType = projectileScript.GetExplosionType();

            //updates the attack time
            attackTime = fireRate + Time.time;

            //start waiting if it's a detonation projectile
            if (explodeType == ExplosionType.Detonate)
            {
                coro      = projectileScript.coro;
                isCreated = true;
            }
        }

        //detonate the projectile using the button
        else if (attack && projectileScript != null && isCreated)
        {
            StopCoroutine(coro);
            projectileScript.DetonateProjectile();
            isCreated = false;
        }

        //if the projectile exploded on its own
        else if (projectileScript == null && isCreated)
        {
            isCreated = false;
        }
    }
Пример #4
0
    void Awake()
    {
        //adds component
        s_Projectile = ProjectileProcessor.ConfigureComponent(gameObject);
        //activates delayed detonation for some projectiles
        ExplosionType explodeType = GetExplosionType();

        if (explodeType == ExplosionType.Delay ||
            explodeType == ExplosionType.Detonate)
        {
            coro = StartCoroutine(WaitUntilDetonate());
        }

        //instantly explode this one because why not
        else if (explodeType == ExplosionType.Instant)
        {
            ExplodeProjectile();
        }
    }
    void Awake()
    {
        //adds component
        s_Projectile = ProjectileProcessor.ConfigureComponent(gameObject);
        //activates delayed detonation for some projectiles
        ExplosionType explodeType = GetExplosionType();

        /*
         *  CASE 1:
         *      - if it's animated projectile
         *      - AND the sprite list size isn't 0
         *      - AND the script inherits IAnimatedProjectile interface
         *
         *  CASE 2:
         *      - if projectile is either a delay or detonate-type
         *
         *  CASE 3:
         *      - if projectile is an instant-type
         */

        if (explodeType == ExplosionType.Delay ||
            explodeType == ExplosionType.Detonate)
        {
            coro = StartCoroutine(WaitUntilDetonate());
        }

        //instantly explode this one because why not
        else if (explodeType == ExplosionType.Instant)
        {
            ExplodeProjectile(scriptObject.explosionPrefab, scriptObject.explosionAmount);
        }

        else
        {
            coro = StartCoroutine(SetDespawnTime());
        }
    }
Пример #6
0
    /// <summary>
    /// Makes the player attack.
    /// </summary>
    /// <param name="isMoving">Player's movement state</param>
    /// <param name="attack">Player's attacking state</param>
    public void Attack(bool isMoving, bool attack)
    {
        //if the following conditions apply:
        //didnt attack,
        //currently on firerate cooldown,
        //projectile has spawned already (detonation-type only)
        //do nothing

        if (attack && (attackTime <= Time.time && !isCreated))
        {
            //use the attack animation
            switch (chosenProjectile)
            {
            case PlayerProjectiles.Fizztol:
                PlayerAnimation.current.ChangeAnimState("FIRE_FIZZTOL");
                break;

            case PlayerProjectiles.Shotgun:
                PlayerAnimation.current.ChangeAnimState("FIRE_SHOTGUN");
                break;

            default:
                PlayerAnimation.current.ChangeAnimState("THROW");
                break;
            }

            //load the projectile
            if (!isPrefabLoaded)
            {
                projectilePrefab = ProjectileProcessor.GetPrefab(chosenProjectile);
                projectileName   = ProjectileProcessor.GetProjectileName();
                isPrefabLoaded   = true;
            }

            //set the shotgun location to attackhandsource and spawn one
            if (projectileName == "Shotgun" || projectileName == "Fizztol")
            {
                projectile = Instantiate(projectilePrefab, attackHandSource.position,
                                         attackHandSource.rotation);
            }
            else
            {
                projectile = Instantiate(projectilePrefab, attackSource.position,
                                         attackSource.rotation);
            }

            //creates the projectile
            projectileScript = projectile.GetComponent <ProjectileManager>();

            //updates and fetches projectile data
            projectileScript.SetPlayerMoving(isMoving);
            fireRate    = fireRates[projectileScript.GetName()] / rateMultiplier;
            explodeType = projectileScript.GetExplosionType();

            //updates the attack time
            attackTime = fireRate + Time.time;

            //start waiting if it's a detonation projectile
            if (explodeType == ExplosionType.Detonate)
            {
                coro      = projectileScript.coro;
                isCreated = true;
            }
        }

        //detonate the projectile using the button
        else if (attack && projectileScript != null && isCreated)
        {
            StopCoroutine(coro);
            projectileScript.DetonateProjectile();
            isCreated = false;
        }

        //if the projectile exploded on its own
        else if (projectileScript == null && isCreated)
        {
            isCreated = false;
        }
    }
Пример #7
0
 public void ChangeProjectile(PlayerProjectiles newProjectile)
 {
     chosenProjectile = newProjectile;
     projectilePrefab = ProjectileProcessor.GetPrefab(chosenProjectile);
     projectileName   = ProjectileProcessor.GetProjectileName();
 }