Exemplo n.º 1
0
 private void FixedUpdate()
 {
     while (timerVolley.TimeUp(data.refs.ts.DeltaTime()))
     {
         VolleyData volley = data.volley;
         float[]    angles = UtilSpread.PopulateAngle(volley.spreadAngle,
                                                      data.volley.projectile.angle,
                                                      volley.projectileCount);
         foreach (float a in angles)
         {
             float angle = a;
             if (data.refs.player != null)
             {
                 if (volley.aimAtPlayer)
                 {
                     Vector3 playerPos = data.refs.player.transform.position;
                     angle += UtilHeading2D.SignedAngleToPoint(transform.position, playerPos);
                 }
             }
             Quaternion           rotation   = Quaternion.AngleAxis(angle, Vector3.forward);
             GameObject           projectile = Instantiate(prefabProjectile, transform.position, rotation);
             EnemyProjectile      proj       = projectile.GetComponent <EnemyProjectile>();
             EnemyProjectile.Data projData   = data.volley.projectile.DeepCopy();
             projData.angle = angle;
             proj.SetData(projData);
             Velocity2D      leftMovement = projectile.GetComponent <Velocity2D>();
             Velocity2D.Data v2d          = new Velocity2D.Data(
                 new Velocity2D.Data.Refs(data.refs.ts),
                 new Vector2(-data.projectileLeftSpeed, 0.0f));
             leftMovement.SetData(v2d);
         }
         data.volley.projectile.angle += data.volleyDirectionDeltaPerShot;
     }
 }
Exemplo n.º 2
0
 private void Start()
 {
     Velocity2D.Data dat = new Velocity2D.Data(
         new Velocity2D.Data.Refs(data.refs.ts),
         UtilHeading2D.HeadingVectorFromDegrees(data.angle) * data.speed);
     velocity.SetData(dat);
     //SetAngleSpeed(data.angle, data.speed);
     SetColor(data.color);
 }
Exemplo n.º 3
0
 public Data(float challenge,
             OscillatePosition2D.Data oscData, EnemyAttack.Data attackData,
             EnemySprite.Data spriteData, Velocity2D.Data leftMovementData,
             EnemyHealth.Data enemyHealthData)
 {
     this.challenge        = challenge;
     this.oscData          = oscData;
     this.attackData       = attackData;
     this.spriteData       = spriteData;
     this.leftMovementData = leftMovementData;
     this.enemyHealthData  = enemyHealthData;
 }
Exemplo n.º 4
0
    // Attempt to drop something.
    private void DropItem()
    {
        ItemType it = data.probItem.Roll();

        if (it == ItemType.None)
        {
            return;
        }
        if (it == ItemType.HealthKit)
        {
            GameObject    pup = Instantiate(prefabHealthKit, transform.position, Quaternion.identity);
            ItemHealthKit hk  = pup.GetComponent <ItemHealthKit>();
            hk.SetData(data.healthKit);

            Velocity2D.Data v2d = new Velocity2D.Data(
                new Velocity2D.Data.Refs(data.refs.ts),
                leftMovement.GetVelocity());
            Velocity2D lm = pup.GetComponent <Velocity2D>();
            lm.SetData(v2d);
        }
        else
        {
            // Only drop these powerups if none currently exist.
            if (!data.refs.playerPowerup.GetPowerupExists())
            {
                GameObject powerup = null;
                switch (it)
                {
                case ItemType.BattleAxe:
                    powerup = Instantiate(prefabBattleAxe, transform.position, Quaternion.identity);
                    break;

                case ItemType.MoreArms:
                    powerup = Instantiate(prefabMoreArms, transform.position, Quaternion.identity);
                    break;
                }
                ItemPowerup pup = powerup.GetComponent <ItemPowerup>();
                pup.SetPlayerPowerup(data.refs.playerPowerup);

                Velocity2D.Data v2d = new Velocity2D.Data(
                    new Velocity2D.Data.Refs(data.refs.ts),
                    leftMovement.GetVelocity());
                Velocity2D lm = powerup.GetComponent <Velocity2D>();
                lm.SetData(v2d);
            }
        }
    }
Exemplo n.º 5
0
    public void Kill()
    {
        data.refs.score.Add(data.pointsWhenKilled);
        data.refs.score.PunchedEnemy();
        DropItem();
        ac.PlaySFX(enemyDeathSounds.GetRandomElement());

        GameObject de = Instantiate(deathExplosion, transform.position, Quaternion.identity);

        Velocity2D.Data v2d = new Velocity2D.Data(
            new Velocity2D.Data.Refs(data.refs.ts),
            leftMovement.GetVelocity());
        Velocity2D lm = de.GetComponent <Velocity2D>();

        lm.SetData(v2d);

        Destroy(gameObject);
    }
Exemplo n.º 6
0
 public void InitializeVelocity()
 {
     velocity = new Velocity2D.Data(Vector2D.Zero, 5);
 }
Exemplo n.º 7
0
    // Read data from the files.
    private void Tune()
    {
        JSONNodeReader reader = new JSONNodeReader(enemySpawnersFile);

        challengeMax = reader.Get("initial challenge", 1.0f);
        challengeIncreasePerSpawnGroup = reader.Get("challenge increase per spawn group", 1.0f);
        spawnGroupsPerDeadTime         = reader.Get("spawn groups per dead time", 3);
        secondsBetweenSpawns           = reader.Get("seconds between spawns", 1.0f);
        secondsBetweenSpawnGroups      = reader.Get("seconds between spawn groups", 2.0f);
        secondsPerDeadTime             = reader.Get("seconds per dead time", 3.0f);
        enemyBaseLeftMovementSpeed     = reader.Get("enemy base left movement speed", 0.05f);

        timerSpawn      = new Timer(secondsBetweenSpawns);
        timerSpawnGroup = new Timer(secondsBetweenSpawnGroups);
        timerDeadTime   = new Timer(secondsPerDeadTime);
        ChooseRandomSpawnPosition();

        // How much health a single health kit should give.
        int healthPerHealthKit;
        int pointsPerEnemyKilled;
        int pointsPerProjectilePunched;
        int pointsPerFullHealthHealthKit;

        reader.SetFile(scoreFile);
        pointsPerEnemyKilled         = reader.Get("points per enemy killed", 100);
        pointsPerProjectilePunched   = reader.Get("points per projectile punched", 10);
        pointsPerFullHealthHealthKit = reader.Get("points per full health health kit", 100);

        // Drop rates for items.
        Probability <ItemType> probItem = new Probability <ItemType>(ItemType.None);
        float dropRateHealthKit;
        float dropRateBattleAxe;
        float dropRateMoreArms;

        reader.SetFile(itemsFile);
        dropRateHealthKit  = reader.Get("health kit drop rate", 0.07f);
        dropRateBattleAxe  = reader.Get("battle axe drop rate", 0.05f);
        dropRateMoreArms   = reader.Get("more arms drop rate", 0.05f);
        healthPerHealthKit = reader.Get("health per health kit", 50);

        probItem.SetChance(ItemType.HealthKit, dropRateHealthKit);
        probItem.SetChance(ItemType.BattleAxe, dropRateBattleAxe);
        probItem.SetChance(ItemType.MoreArms, dropRateMoreArms);

        reader.SetFile(enemiesFile);
        JSONArrayReader enemyArray = reader.Get <JSONArrayReader>("enemies");
        //for (int i = 0; i < enemyArray.GetCount(); ++i)
        JSONNodeReader enemyNode;

        while (enemyArray.GetNextNode(out enemyNode))
        {
            //JSONNodeReader enemyNode = enemyArray.GetNode(i);
            string enemyName = enemyNode.Get("name", "UNNAMED");

            // Read volley data.
            JSONNodeReader volleyNode = enemyNode.Get <JSONNodeReader>("volley");

            string colString = volleyNode.Get("color", "#ffffff");
            Color  projColor;
            if (!ColorUtility.TryParseHtmlString(colString, out projColor))
            {
                Debug.Log(enemyName + ": Could not parse HTML color for volley!");
            }
            EnemyProjectile.Data projectile = new EnemyProjectile.Data(
                new EnemyProjectile.Data.Refs(ts, score),
                volleyNode.Get("projectile punchable", true),
                volleyNode.Get("projectile damage", 20),
                pointsPerProjectilePunched,
                projColor,
                volleyNode.Get("direction", 180.0f),
                volleyNode.Get("speed", 4.0f));

            VolleyData volley = new VolleyData(projectile,
                                               volleyNode.Get("projectile count", 1),
                                               volleyNode.Get("spread angle", 0.0f),
                                               volleyNode.Get("aims at player", false));

            OscillatePosition2D.Data oscData = new OscillatePosition2D.Data(
                new OscillatePosition2D.Data.Refs(ts),
                0.0f, 0.0f,
                enemyNode.Get("y oscillation magnitude", 0.0f),
                enemyNode.Get("y oscillation speed", 0.0f));

            EnemyAttack.Data attack = new EnemyAttack.Data(
                new EnemyAttack.Data.Refs(ts, playerPowerup.gameObject),
                volley,
                enemyNode.Get("seconds between volleys", 1.0f),
                enemyNode.Get("volley direction delta per shot", 0.0f),
                enemyBaseLeftMovementSpeed);

            EnemySprite.Data enemySprite = new EnemySprite.Data(
                enemyNode.Get("sprite name", "basic"));

            Velocity2D.Data leftMovement = new Velocity2D.Data(
                new Velocity2D.Data.Refs(ts),
                new Vector2(
                    -enemyNode.Get("left movement speed increase", 0.0f)
                    - enemyBaseLeftMovementSpeed, 0.0f));

            ItemHealthKit.Data healthKitData = new ItemHealthKit.Data(
                new ItemHealthKit.Data.Refs(score),
                healthPerHealthKit,
                pointsPerFullHealthHealthKit);
            EnemyHealth.Data enemyHealthData = new EnemyHealth.Data(
                new EnemyHealth.Data.Refs(ts, score, playerPowerup),
                healthKitData,
                pointsPerEnemyKilled,
                probItem);

            Enemy.Data enemy = new Enemy.Data(enemyNode.Get("challenge", 1.0f),
                                              oscData,
                                              attack,
                                              enemySprite,
                                              leftMovement,
                                              enemyHealthData);

            // Add the enemy to the possible enemies pool.
            possibleEnemies.Add(enemy);
        }
    }
Exemplo n.º 8
0
		public void InitializeVelocity()
		{
			velocity = new Velocity2D.Data(Vector2D.Zero, 5);
		}