/*---------------------------------------------------------------------*/ /// <summary> /// スコアとボーナス燃料の計算 /// </summary> /// <param name="status">ランダーのステータス</param> /// <param name="point">着陸地点</param> /// <param name="score">スコア受け取り用変数</param> /// <param name="bonusfuel">ボーナス燃料受け取り用変数</param> private void ScoreCalc(LanderStatus status, LandingPoint point, out float score, out float bonusfuel) { // ステータス情報の取得 LanderStatus.STATUS _status = status.GetStatus(); // 水平速度と垂直速度をベクトルとし、ベクトルの長さの半分をスピード値として取得する。 int speed = (int)(new Vector2(_status.horizontal_speed, _status.vertical_speed).magnitude / 2); // 計算ベース値からスピード値を引いた値に着陸地点のボーナス倍率をかけた値をスコアとする。 score = (Const.MainGameData.SCORE_CALC_BASE - speed) * point.GetBonusRate(); // スコアにボーナス燃料倍率をかけた値をボーナス燃料とする。 bonusfuel = score * Const.MainGameData.BONUS_FUEL_RATE; }
/// <summary> /// Call this function every time unit to update the lander's position based /// on the current enviroment, and burn and thrust settings. /// </summary> /// <returns>The new lander status. </returns> public LanderStatus Update() { this.CurrentTime++; this.VelocityY -= this.Enviroment.Gravity; // Adjust velocity for burn //this.VelocityY += (this.Fuel - this.Burn >= 0 ? this.Burn : this.Burn - this.Fuel); if (this.Burn > this.Fuel) { this.VelocityY += this.Fuel; } else { this.VelocityY += this.Burn; } this.Fuel = Math.Max(this.Fuel - this.Burn, 0); // Adjust velocity for thrust //this.VelocityX += (this.Fuel - this.Thrust >= 0 ? this.Thrust : this.Thrust - this.Fuel); if (Math.Abs(this.Thrust) > this.Fuel) { this.VelocityX += (Math.Abs(this.Thrust) - this.Fuel) * (this.Thrust / Math.Abs(this.Thrust)); } else { this.VelocityX += this.Thrust; } this.Fuel = Math.Max(this.Fuel - Math.Abs(this.Thrust), 0); // New position based on velocity this.PositionX += this.VelocityX + this.Enviroment.WindSpeed; this.PositionY += this.VelocityY; // Check if crashed if (this.PositionY > this.Enviroment.GetElevation(this.PositionX)) { // We are still in the air, so flying. this.Status = LanderStatus.Flying; } else if (this.VelocityY < this.MaxLandingVelocity || this.PositionX < this.MinSafeX || this.PositionX > this.MaxSafeX) { // Now we are are on the ground and have broken one of the constraints this.status = LanderStatus.Crashed; } else { // All contraints passed, lander has landed. this.status = LanderStatus.Landed; this.VelocityX = 0; this.VelocityY = 0; this.PositionY = this.Enviroment.GetElevation(this.PositionX); } return this.Status; }
/*---------------------------------------------------------------------*/ void Awake() { _Status = this.GetComponent <LanderStatus> (); _Rigidbody = this.GetComponent <Rigidbody2D> (); }