public void Tick(float deltaTime) { Vector2 velocity = vius.GetVelocity(); // Decelerate if the Rigidbody is grounded and not accelerating. if (groundChecker.IsOnGround() && accumulatedHorizontalAcceleration == 0.0f) { velocity.x = UtilApproach.Float(velocity.x, 0.0f, groundDeceleration * deltaTime); } // Accelerate the Rigidbody based on applied forces. velocity.x += accumulatedHorizontalAcceleration * deltaTime; accumulatedHorizontalAcceleration = 0.0f; // Cap the Rigidbody's velocity. if (Mathf.Abs(velocity.x) > maxHorizontalSpeed) { velocity.x = Mathf.Sign(velocity.x) * maxHorizontalSpeed; } vius.SetVelocity(velocity); }
private void FixedUpdate() { timerHesitate.Tick(timeScale.DeltaTime()); if (timerFinished) { // Shrink the buffer. float stepSize = timeScale.DeltaTime() * shrinkSpeed; if (shrinkToLeft) { bufferUpper = UtilApproach.Float(bufferUpper, bufferLower, stepSize); } else { bufferLower = UtilApproach.Float(bufferLower, bufferUpper, stepSize); } UpdateBufferMeter(); if (bufferLower == bufferUpper) { timerFinished = false; } } }
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); } }
// Move one angle towards another without considering coterminality. public Angle ApproachRaw(Angle target, Angle stepSize) { degrees = UtilApproach.Float(degrees, target.degrees, stepSize.degrees); return(this); }