// Distance of two planets public double Distance(SilverlightControlPlanet planet) { double x1 = (double)this.GetValue(Canvas.LeftProperty); double y1 = (double)this.GetValue(Canvas.TopProperty); double x2 = (double)planet.GetValue(Canvas.LeftProperty); double y2 = (double)planet.GetValue(Canvas.TopProperty); return(PlanetMath.Distance(x1, y1, x2, y2)); }
public void Update() { xk += px; yk += py; this.SetValue(Canvas.LeftProperty, xk); this.SetValue(Canvas.TopProperty, yk); if (PlanetMath.Distance(xk, yk, destx, desty) < 5.0) { IsActive = false; Visibility = Visibility.Collapsed; Landing(); } }
public void SetPlanets(SilverlightControlPlanet startplanet, SilverlightControlPlanet destplanet) { start = startplanet; destination = destplanet; double startx = (double)start.GetValue(Canvas.LeftProperty) + start.Width / 2.0 - this.Width / 2.0; double starty = (double)start.GetValue(Canvas.TopProperty) + start.Height / 2.0 - this.Height / 2.0; destx = (double)destination.GetValue(Canvas.LeftProperty) + destination.Width / 2.0 - this.Width / 2.0; desty = (double)destination.GetValue(Canvas.TopProperty) + destination.Height / 2.0 - this.Width / 2.0; xk = startx; yk = starty; double dx = destx - startx; double dy = desty - starty; double d = PlanetMath.Length(dx, dy); px = Speed * (dx / d); py = Speed * (dy / d); owner = start.Owner; if (owner == PlanetOwner.Player) { ImageFleet.Source = ship_player; } else { ImageFleet.Source = ship_enemy; } FleetRotate.Angle = PlanetMath.RotationAngle(startx, starty, destx, desty); IsActive = true; }