コード例 #1
0
ファイル: EnemyAttack.cs プロジェクト: ByteNybbler/NotTheFace
    private void TimerVolleyFinished(float secondsOverflow)
    {
        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 += Angle.FromPoint(transform.position, playerPos).GetDegrees();
                    //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>();
            leftMovement.SetVelocity(new Vector2(-data.projectileLeftSpeed, 0.0f));
            projectile.GetComponent <TimeScale>().SetData(timeScale);
        }
        data.volley.projectile.angle += data.volleyDirectionDeltaPerShot;
    }
コード例 #2
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;
     }
 }
コード例 #3
0
ファイル: EnemyAttack.cs プロジェクト: ByteNybbler/NotTheFace
 public Data(Refs refs,
             VolleyData volley,
             float secondsBetweenVolleys,
             float volleyDirectionDeltaPerShot,
             float projectileLeftSpeed)
 {
     this.refs   = refs;
     this.volley = volley;
     this.secondsBetweenVolleys       = secondsBetweenVolleys;
     this.volleyDirectionDeltaPerShot = volleyDirectionDeltaPerShot;
     this.projectileLeftSpeed         = projectileLeftSpeed;
 }
コード例 #4
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);
        }
    }