private void OnCollisionEnter(Collision collision) { float averageSpeed = CalcAverageSpeedFromCache(); if (shipAngle > maxAngleForLanding || shipAngle < -maxAngleForLanding) { CrashShip(); } //Debug.Log("MagVel: " + averageSpeed + " | Max: " + maxSpeedForLanding); if (averageSpeed > maxSpeedForLanding) { // The speed is to high, crash ship. CrashShip(); } else { LandingPlatform landingPlatform = collision.collider.GetComponentInParent <LandingPlatform>(); if (IsAbovePlatform && landingPlatform != null) // The ship is over a landing platform, check speed. { // The collision was with a valid platform, land on it. LandShip(landingPlatform); } else { // The collision was not with a valid platform, land ship on ground. LandShip(null); } } }
public IEnumerator LandedOnPlatform(GameObject landingPad, float distanceToCenter, float maxFuelRestore) { if (landingPad.Equals(lastLandingPad)) { Debug.Log("Feet on the Ground: " + amountOfFeet + " ... you get Points and Fuel! Dist: " + distanceToCenter.ToString()); bool perfectLanding = amountOfFeet == 4; int multiplier = amountOfFeet; /*if(perfectLanding){ * // TODO perfect landing * Debug.Log("Perfect Landing"); * SetMessageLabelText("Perfect Landing", 1f); * yield return new WaitForSeconds(1f); * }*/ LandingPlatform platformScript = landingPad.GetComponent <LandingPlatform>(); float points = platformScript.scorePoints - distanceToCenter - impact; int bonusMultiplier = platformScript.multiply; int score = ((int)(points + 0.5f)) * (multiplier + bonusMultiplier); string scoreText = (perfectLanding ? "Perfect Landing\n" : "") + (multiplier + bonusMultiplier).ToString() + " x " + ((int)(score / (multiplier + bonusMultiplier))).ToString(); SetMessageLabelText(scoreText, 24, 2f); yield return(new WaitForSeconds(2f)); currentLevelScore += score; // TODO Score textlabel aufblitzen lassen float bonusFuel = (maxFuelRestore * multiplier) - distanceToCenter; Lander.GetInstance().AddFuel(bonusFuel / 3); Debug.Log("Added Fuel"); if (GetRemainingLandingPads() == 0) { yield return(StartCoroutine(EndLevel())); } } }
protected override void Given() { const int areaDimensionX = 100; const int areaDimensionY = 100; const int platformDimensionX = 50; const int platformDimensionY = 50; _positionX = 20; _positionY = 40; var approachCheckResultMapper = new ApproachCheckResultMapper(); var strategy = new ZartisExerciseStrategy(); var platformDimension = new Dimension(platformDimensionX, platformDimensionY); var platform = new LandingPlatform(platformDimension, strategy); var areaDimension = new Dimension(areaDimensionX, areaDimensionY); var area = new LandingArea(areaDimension, platform, approachCheckResultMapper); var rocket = new Rocket(area); rocket.CheckApproach(_positionX, _positionY); _sut = new Rocket(area); _expectedResult = "ok for landing"; _farPositionX = _positionX + 2; }
public override void InitializeAgent() { landingPlatformS = landingPlatform.GetComponent <LandingPlatform>(); zPos = rocketObject.transform.position.z; rocketController = rocketObject.GetComponent <RocketController>(); rocketProps = rocketObject.GetComponent <RocketProps>(); rb = rocketObject.GetComponent <Rigidbody>(); }
protected override void Given() { _sut = new LandingPlatformBuilder() .WithStartPosition(StartPosition) .Build(); _expectedResult = IsAllowed; }
public void Given_A_Rocket_And_A_Landing_Platform_With_10x10_Size_And_Position_1_1_When_Asking_For_Next_To_Previous_Checked_Position_And_Out_Of_Platform( int x, int y, string expectedResult) { var rocket = new Rocket { Position = new Position { X = 11, Y = 11 } }; var rockets = new List <Rocket> { rocket }; var landingPlatform = new LandingPlatform { Position = new Position { X = 1, Y = 1 }, Size = new Size { Height = 10, Width = 10 }, Rockets = rockets }; var position = new Position { X = x, Y = y }; var result = _sut.IsValidPosition(position, landingPlatform); result.Should().Be(expectedResult); }
public void Given_A_Rocket_And_A_Landing_Platform_With_10x10_Size_And_Position_2_2_When_Asking_For_Next_To_Previous_Checked_Position( int x, int y) { var rocket = new Rocket { Position = new Position { X = 10, Y = 4 } }; var rockets = new List <Rocket> { rocket }; var landingPlatform = new LandingPlatform { Position = new Position { X = 2, Y = 2 }, Size = new Size { Height = 10, Width = 10 }, Rockets = rockets }; var position = new Position { X = x, Y = y }; var result = _sut.IsValidPosition(position, landingPlatform); result.Should().Be("clash"); }
public void LandShip(LandingPlatform landingPlatform) { onLand.Invoke(); if (landingPlatform != null) { CurrentLandingPlatform = landingPlatform; landingPlatform.Land(); } else { CurrentLandingPlatform = null; } IsLanded = true; Debug.Log("Landed Ship"); }
public IsValidPositionTests() { _landingPlatform = new LandingPlatform { Position = new Position { X = 5, Y = 5 }, Size = new Size { Height = 10, Width = 10 } }; _sut = new Rocket(); }
private IEnumerator DoRespawn() { isRespawning = true; yield return(new WaitForSeconds(respawnTime)); PlayerResourceManager.Instance.resourceCrystals -= respawnCost; if (PlayerResourceManager.Instance.resourceCrystals < 0) { PlayerResourceManager.Instance.resourceCrystals = 0; } float closestDistance = float.PositiveInfinity; LandingPlatform closestPlatform = null; foreach (LandingPlatform landingPlatform in FindObjectsOfType <LandingPlatform>()) { if (landingPlatform.PlatformType == PlatformType.BasePlatform) { float dist = Vector3.Distance(lastKnownPlayerPos, landingPlatform.transform.position); if (dist < closestDistance) { closestDistance = dist; closestPlatform = landingPlatform; } } } Vector2 spawnPosition = closestPlatform.transform.position + closestPlatform.transform.up * spawnHeight; PlayerMovement spawnedPlayer = Instantiate(playerPrefab, spawnPosition, Quaternion.identity); playerInput.ControlledActor = spawnedPlayer.gameObject; FindObjectOfType <MiniMap>().player = spawnedPlayer.transform; FindObjectOfType <CameraMovement>().target = spawnedPlayer.transform; isRespawning = false; }
protected override void When() { _sut = new LandingPlatform(_size, _startPosition); }
private void SetPositionTaken(Position position, LandingPlatform platform) { platform.TakenPositions.Add(new RocketPosition(position)); }
protected override void When() { _expectedException = Record.Exception( () => _sut = new LandingPlatform(_platformDimension, _strategy)); }
protected override void When() { _sut = new LandingPlatform(_platformDimension, _strategy); }
protected override void Given() { _platformDimension = Mock.Of <IDimension>(); _strategy = Mock.Of <ILandingStrategy>(); _sut = new LandingPlatform(_platformDimension, _strategy); }
public LandingPlatform Build() { var landingPlatform = new LandingPlatform(_size, _startPosition); return(landingPlatform); }