private void Awake() { JSONNodeReader jsonReader = new JSONNodeReader(fileItems); JSONNamedEventReader itemReader = new JSONNamedEventReader("identifier"); itemReader.AddCallbackInt("health bonus", player.AddMaxHealth, "+{0} health"); itemReader.AddCallbackInt("tongue damage bonus", player.AddTongueDamage, "+{0} tongue damage"); itemReader.AddCallbackInt("headbutt damage bonus", player.AddHeadbuttDamage, "+{0} headbutt damage"); itemReader.AddCallbackInt("laser damage bonus", player.AddLaserDamage, "+{0} laser damage"); itemReader.AddCallbackInt("contact damage per second bonus", player.AddContactDamagePerSecond, "+{0} contact damage"); itemReader.AddCallbackInt("damaged explosion damage bonus", player.AddEggExplosionDamage, "+{0} egg damage...?"); itemReader.AddCallbackInt("headbutt explosion damage bonus", player.AddHeadbuttExplosionDamage, "+{0} headbutt explosion damage"); itemReader.AddCallbackFloat("jump velocity bonus", player.AddJumpVelocity, "+{0} jump height"); itemReader.AddCallbackFloat("horizontal acceleration bonus", player.AddHorizontalAcceleration, "+{0} acceleration"); itemReader.AddCallbackFloat("max horizontal speed bonus", player.AddMaxHorizontalSpeed, "+{0} max speed"); itemReader.AddCallbackBool("press down for shield", player.SetHasSoap, "Press down for shield"); JSONArrayReader itemsReader = jsonReader.Get <JSONArrayReader>("items"); JSONNodeReader itemNodeReader; while (itemsReader.GetNextNode(out itemNodeReader)) { bool blacklist = itemNodeReader.Get("BLACKLIST", false); if (!blacklist) { NamedEvent item = itemReader.Read(itemNodeReader); item.AddCallback(() => Claim(item)); pool.AddUnclaimed(item); } } }
private void Awake() { JSONNodeReader jsonReader = new JSONNodeReader(fileItems); JSONNamedEventReader itemReader = new JSONNamedEventReader("identifier"); itemReader.AddCallbackInt("health bonus", player.AddMaxHealth); itemReader.AddCallbackInt("tongue damage bonus", player.AddTongueDamage); itemReader.AddCallbackInt("headbutt damage bonus", player.AddHeadbuttDamage); JSONArrayReader itemsReader = jsonReader.Get <JSONArrayReader>("items"); JSONNodeReader itemNodeReader; while (itemsReader.GetNextNode(out itemNodeReader)) { NamedEvent item = itemReader.Read(itemNodeReader); item.AddCallback(() => Claim(item)); pool.AddUnclaimed(item); } }
private void Awake() { JSONNodeReader jsonReader = new JSONNodeReader(fileBosses); JSONArrayReader bossesReader = jsonReader.Get <JSONArrayReader>("bosses"); JSONNodeReader bossNodeReader; while (bossesReader.GetNextNode(out bossNodeReader)) { List <Boss.AttackGroup> attackGroups = new List <Boss.AttackGroup>(); JSONArrayReader attackGroupsReader = bossNodeReader.Get <JSONArrayReader>("attack groups"); JSONNodeReader attackGroupNodeReader; while (attackGroupsReader.GetNextNode(out attackGroupNodeReader)) { Boss.AttackGroup attackGroup = new Boss.AttackGroup( attackGroupNodeReader.Get("seconds of cooldown", 2.0f), attackGroupNodeReader.Get("seconds of cooldown variance", 0.5f)); float secondsOfCooldownBonusPerArena = attackGroupNodeReader.Get("seconds of cooldown bonus per arena", 0.0f); float secondsOfCooldownMin = attackGroupNodeReader.Get("seconds of cooldown min", 0.1f); DifficultyIncreased += () => attackGroup.SetSecondsOfCooldown( UtilApproach.Float(attackGroup.GetSecondsOfCooldown(), secondsOfCooldownMin, -secondsOfCooldownBonusPerArena) ); JSONArrayReader attacksReader = attackGroupNodeReader.Get <JSONArrayReader>("attacks"); JSONNodeReader attackNodeReader; while (attacksReader.GetNextNode(out attackNodeReader)) { string identifier = attackNodeReader.Get("identifier", "ERROR"); string appearance = attackNodeReader.Get("appearance", "ERROR"); if (identifier == "FloorSpikes") { float count = attackNodeReader.Get("count", 3); RuntimeAnimatorController rac; spikeAnimators.TryGetValue(appearance, out rac); FloorSpike.Data d = ReadFloorSpike(attackNodeReader, appearance); attackGroup.AddAttack(x => Boss.FloorSpikes(x, attackGroup, d, rac, count)); float countBonusPerArena = attackNodeReader.Get("count bonus per arena", 0.0f); float countMax = attackNodeReader.Get("count max", 6); DifficultyIncreased += () => count = UtilApproach.Float(count, countMax, countBonusPerArena); } else if (identifier == "FloorSpikeTargetPlayer") { RuntimeAnimatorController rac; spikeAnimators.TryGetValue(appearance, out rac); FloorSpike.Data d = ReadFloorSpike(attackNodeReader, appearance); attackGroup.AddAttack(x => Boss.FloorSpikeTargetPlayer(x, attackGroup, d, rac)); } else if (identifier == "Orb") { RuntimeAnimatorController rac; orbAnimators.TryGetValue(appearance, out rac); BossOrb.Data d = new BossOrb.Data( attackNodeReader.Get("damage", 20), attackNodeReader.Get("seconds to idle", 3.0f), attackNodeReader.Get("seconds to idle variance", 2.0f), attackNodeReader.Get("seconds to move to center", 0.2f), attackNodeReader.Get("seconds to move to bottom", 0.8f), attackNodeReader.Get("horizontal speed", 8.0f)); string positionName = attackNodeReader.Get("position", "ERROR"); attackGroup.AddAttack(x => Boss.SpawnOrb(x, attackGroup, d, positionName, rac)); int damageBonusPerArena = attackNodeReader.Get("damage bonus per arena", 0); int damageMax = attackNodeReader.Get("damage max", 10000); DifficultyIncreased += () => d.damage = UtilApproach.Int(d.damage, damageMax, damageBonusPerArena); } /* * else if (identifier == "HorizontalProjectile") * { * int damage = attackNodeReader.Get("damage", 20); * float speed = attackNodeReader.Get("speed", 8.0f); * float spawnHeight = attackNodeReader.Get("spawn height", 1.0f); * float seconds = attackNodeReader.Get("seconds to wait after attack", * 1.0f); * Velocity2D.Data d = new Velocity2D.Data(new Vector2(-speed, 0.0f)); * attacks.Add(x => Boss.FireProjectile(x, d, damage, spawnHeight, * seconds)); * } */ } attackGroups.Add(attackGroup); } Boss.Data boss = new Boss.Data( bossNodeReader.Get("identifier", "ERROR"), bossNodeReader.Get("base health", 1), attackGroups); int healthBonusPerArena = bossNodeReader.Get("health bonus per arena", 0); DifficultyIncreased += () => boss.baseHealth += healthBonusPerArena; pool.Add(boss); } }
// 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); } }