public override void Draw(float baseRotation = 0f, bool isFocused = false) { if (CurrentPlanet is null) { return; } Application.Push(); Application.Fill(Color.DarkSlateGray); var halfHeight = _body.Height * 0.5f; Vector2 translation; if (!isFocused) { translation = CurrentPlanet.EdgePointToPosition(EdgePoint, radiusOffset: halfHeight); } else { translation = CurrentPlanet.Position + (-Vector2.UnitY * (CurrentPlanet.Radius + halfHeight)); } Application.Translate(translation); var rotation = CurrentPlanet.EdgePointToRotationAngle(EdgePoint); Application.Rotate(baseRotation + rotation); Application.SetRectangleMode(RectangleMode.Center); Application.DrawRectangle(_body); Application.Pop(); }
private void ChangePlanet() { float NearestDistance = 1000; foreach (GameObject planet in Planets) { //if (planet != CurrentPlanet) //the player will be attached only with higher planets if (planet != CurrentPlanet && transform.position.y <= planet.transform.position.y) { //calculate the distance between the player and each planet exept the planet the player is attached to var distance = Mathf.Abs(Vector2.Distance(gameObject.transform.position, planet.transform.position)); // if (distance <= NearestDistance && distance < 25) { NearestDistance = distance; NearestPlanet = planet; } } } // //return the nearest planet CurrentPlanet = NearestPlanet; DirectionHandler(CurrentPlanet); //atmpsphere set Atmosphere = CurrentPlanet.GetComponent <Renderer>().bounds.size.x / 1.25f; //rotate the player transform.rotation = Quaternion.LookRotation(Vector3.forward, CurrentPlanet.transform.position - transform.position); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition = new Vector3(mousePosition.x, mousePosition.y, CurrentPlanet.transform.position.z); Vector3 direction = mousePosition - CurrentPlanet.transform.position; Vector3 pos = CurrentPlanet.transform.position + direction.normalized * CurrentPlanet.Collider.radius; if (Vector2.Distance(mousePosition, pos) <= 0.5f) { CurrentPlanet.PlaceSeedBox(new DefaultPlantationBox(CurrentPlanet, Resources.Load <GameObject>("PlantationBox"), 0.2f), pos); // Auto plant CurrentPlanet.GetPlantationBoxAtPosition(mousePosition).PlantSeed(new PlantationData(2, Resources.LoadAll <GameObject>("PlantLol"))); } } if (Input.GetMouseButtonDown(1)) { Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition = new Vector3(mousePosition.x, mousePosition.y, CurrentPlanet.transform.position.z); CurrentPlanet.GetPlantationBoxAtPosition(mousePosition).Water(); } }
public void Update() { KSPPlanet CurrentPlanet; planets.TryGetValue(FlightGlobals.currentMainBody ?? FlightGlobals.Bodies.FirstOrDefault(x => x.name == "Kerbin"), out CurrentPlanet); if (CurrentPlanet != LastPlanet) { Utils.Log("Planet changed: {0} => {1}", LastPlanet == null ? "(null)" : LastPlanet.Body.name, CurrentPlanet == null ? "(null)" : CurrentPlanet.Body.name); LastPlanet = CurrentPlanet; } if (CurrentPlanet != null) { if (FlightGlobals.ActiveVessel == null) { CurrentPlanet.UpdatePosition(Coordinates.KSC); } else { CurrentPlanet.UpdatePosition(new Coordinates(FlightGlobals.ActiveVessel.latitude * Math.PI / 180, FlightGlobals.ActiveVessel.longitude * Math.PI / 180)); } } ThreadDispatcher.DequeueFromWorker(20); }
public void Serialize(BinaryWriter writer) { writer.Write(UniverseTime.Ticks); // Serialize the current planet writer.Write(CurrentPlanet != null); if (CurrentPlanet != null) { CurrentPlanet.Serialize(writer); } // Determine saving procedure for current instance byte a = (byte)(CurrentInstance != null ? (CurrentInstance != CurrentPlanet ? 1 : 2) : 0); writer.Write(a); if (a == 1) { CurrentInstance.Serialize(writer); } }
/// <summary> /// Update the star's position and do any other work here /// </summary> /// <param name="deltaSeconds">Time to advance star position</param> public void UpdatePosition(int deltaSeconds) { double x, y; Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y); Position.X = x; Position.Y = y; if (Parent != null) { // Position is absolute system coordinates, while // coordinates returned from GetPosition are relative to it's parent. Position.X += Parent.Position.X; Position.Y += Parent.Position.Y; } foreach (SystemBody CurrentPlanet in Planets) { CurrentPlanet.UpdatePosition(deltaSeconds); } }
/// <summary> /// Updates this StarSystem for the new time. /// </summary> /// <param name="deltaSeconds">Change in seconds since last update.</param> public void Update(int deltaSeconds) { // Update the position of all planets. This should probably be in something like the construction tick in Aurora. foreach (Star CurrentStar in Stars) { // The system primary will cause a divide by zero error currently as it has no orbit. if (CurrentStar != Stars[0]) { CurrentStar.UpdatePosition(deltaSeconds); // Since the star moved, update the JumpPoint position. foreach (JumpPoint CurrentJumpPoint in JumpPoints) { CurrentJumpPoint.UpdatePosition(); } } foreach (Planet CurrentPlanet in CurrentStar.Planets) { CurrentPlanet.UpdatePosition(deltaSeconds); } } }
public void Init(GameObject planet) { currentPlanet = planet.GetComponent <CurrentPlanet> (); currentPlanet.UpdatePlanetPosition(); }