/// <summary> /// Calulate the center and size /// </summary> /// <param name="obj">The specified object</param> /// <param name="additionalSize"></param> /// <returns>Center.X,Center.Y,Radius</returns> internal Vector3 GetCircleOfObject(GraphicObject obj, float additionalSize) { if (obj.mModel != null) { var posSpace = obj.GetPosition(); var borderSpace = posSpace; borderSpace.X += obj.mModel.Meshes[0].BoundingSphere.Radius * obj.mBoundingScale + additionalSize; var borders = SpaceToScreenPosition(borderSpace); var center = SpaceToScreenPosition(posSpace); // set thrid coordinate to the radius of the circle center.Z = Math.Abs((borders - center).X); return center; } return Vector3.Zero; }
/// <summary> /// Draws the amount of minions above an object /// </summary> /// <param name="obj">Object</param> /// <param name="poso">Position of OBject</param> /// <param name="color">Color</param> private void DrawMinionAmount(GraphicObject obj, Vector3? poso, Color color) { // get the number of minions, from planet/deathstar/minion string minions; if (obj.mGameObject is Planet) minions = ((Planet) obj.mGameObject).MinionCount.ToString(CultureInfo.InvariantCulture); else if (obj.mGameObject is DeathStar) minions = ((DeathStar) obj.mGameObject).MinionCount.ToString(CultureInfo.InvariantCulture); else if (obj.mGameObject is Minion) { var minionCount = ((Minion) obj.mGameObject).Count; minions = (minionCount.ToString(CultureInfo.InvariantCulture)); // dont show 0 or 1 minions on minion if (minionCount <= 1) return; } else return; color.A = 200; // calculate postition of object again if not given Vector3 pos; if (poso == null) pos = mRenderer.GetCamera().GetCircleOfObject(obj, 10); else pos = (Vector3) poso; // write the minionamount 30% highr than the object diameter (not on minions, they have pos.Z=0) pos.Z *= 1.3f; var size = sMinionLabelFont.MeasureString(minions); float scale; // Get different Size of the minions (constant=not scaleable/dynamic) if (obj.mGameObject is Minion) scale = 0.7f; else scale = 0.9f; mSpriteBatch.DrawString(sMinionLabelFont, minions, new Vector2( pos.X - (size.X * scale / 2), pos.Y - (size.Y * scale / 2) - pos.Z * (obj.mGameObject is Minion ? 0 : 1)), color, 0, Vector2.Zero, scale, SpriteEffects.None, 0); // Also Draw the shieldnumber, if the planet has one var planet = obj.mGameObject as Planet; if (planet == null) return; if (!planet.PlanetaryShieldUpgrade) return; minions = planet.Shield.ToString(CultureInfo.InvariantCulture); size = sMinionLabelFont.MeasureString(minions); mSpriteBatch.DrawString(sMinionLabelFont, minions, new Vector2( pos.X - (size.X * scale / 2), pos.Y - (size.Y * scale / 2) + pos.Z), Color.Gray, 0, Vector2.Zero, scale, SpriteEffects.None, 0); }
/// <summary> /// Draws a selection circle aruond an object /// </summary> /// <param name="graphicObj">Object</param> /// <param name="poso">Postion of the Object</param> /// <param name="texture">Texture of the Circle</param> /// <param name="color">Color of the Circle</param> private void DrawSelectionCircle(GraphicObject graphicObj, Vector3? poso, Texture2D texture, Color color) { // calculate postition of object again if not given Vector3 pos; if (poso == null) pos = mRenderer.GetCamera().GetCircleOfObject(graphicObj, 0); else pos = (Vector3) poso; // draw the circle mSpriteBatch.Draw(texture, new Rectangle( (int) (pos.X - pos.Z), (int) (pos.Y - pos.Z), (int) (pos.Z * 2), (int) (pos.Z * 2)), color); }
private bool CheckAndCompareSelection(GraphicObject obj) { if (obj.mGameObject is Minion || obj.mGameObject is Asteroid) return false; if (obj.mGameObject.Alive) { //only if the object isnt already in the list if (!mSelectedObjects.Contains(obj)) { var curType = GetTypeOfSelection(obj.mGameObject); if (mPlanetSelection && curType != SelectionType.Static) return false; //clear list if a higher priorized object comes in if (curType > mSelectionType) { ClearList(); mSelectionType = curType; } //only one enemy at once if (curType == SelectionType.Enemy && mSelectionType == SelectionType.Enemy) ClearList(); if (curType == mSelectionType) return true; } } return false; }
/// <summary> /// Draws the LifeBar of an spaceship /// </summary> /// <param name="obj">Spaceship-Object</param> /// <param name="poso">Position of the Object</param> private void DrawLiveBar(GraphicObject obj, Vector3? poso) { // return, if unit is no spaceship var unit = obj.mGameObject as Spaceship; if (unit == null) return; // get the actual health of the spaceship float health = unit.Health; float max; // get the maximum health of the spaceship if (unit is Interceptor) max = GlobalValues.GetInstance().InterceptorHealth; else if (unit is Predator) max = GlobalValues.GetInstance().PredatorHealth; else if (unit is Defender) max = GlobalValues.GetInstance().DefenderHealth; else return; // if the position of the object is null, calulate it again Vector3 pos; if (poso == null) pos = mRenderer.GetCamera().GetCircleOfObject(obj, 0); else pos = (Vector3) poso; // the size of the bar depends on the size of the spaceship var size = new Vector2(pos.Z * 1.8f, pos.Z * 0.2f); var rect = new Rectangle((int) (pos.X - size.X / 2), (int) (pos.Y - pos.Z + size.Y), (int) size.X, (int) size.Y); // Draw a box over the spaceship DrawDashedRectangle(mSpriteBatch, rect, 1, mDot, Color.Black); var percent = health / max; // get the actual color depending on percent number, from Green to Red var color = GradedValue(Color.Red, Color.Green, percent); color.A = 50; // change the width of the box, to its percent value rect.Width = (int) (rect.Width * percent); // and draw the lifeBar in the box, with the specified color mSpriteBatch.Draw(mDot, rect, color); }
public bool SelectionContains(GraphicObject target) { return mSelectedObjects.Contains(target); }
/// <summary> /// Get the Upgrade a planet has /// </summary> /// <param name="obj">The Planet Object</param> /// <returns>A List of Upgrades a Planet has</returns> private Upgrade[] GetActiveUpgrades(GraphicObject obj) { var planet = (Planet) obj.mGameObject; // initialized by just one Upgrade, to reduce redundancy var result = new Upgrade[1]; // Check which Upgrade the Planet has, and save it to the result if (planet.MinionBoostUpgrade) result[0] = GetUpgrade(planet, 1); else if (planet.SateliteStationUpgrade) result[0] = GetUpgrade(planet, 2); else if (planet.PlanetaryShieldUpgrade) result[0] = GetUpgrade(planet, 3); else if (planet.StarfleetAcademyUpgrade) { // on StarfleetAcademyUpgrade, there are three possible upgrades (ships) result = new Upgrade[3]; // Get the ShipUpgrades(5,6,7) and calulate the Circles of Upgrades for (var i = 0; i < 3; i++) { result[i] = GetUpgrade(planet, 5 + i); result[i].mCircle = GetUpgradeCircle(mRenderer.GetCamera().GetCircleOfObject(obj, 50 + (int) planet.PlanetSize * 18), i, 3); } return result; } else { // if the planet has no Upgrade, it has five possible upgrades result = new Upgrade[5]; // Get the Upgrades(0,1,2,3,4) and calulate the Circles of Upgrades for (var i = 0; i < 5; i++) { result[i] = GetUpgrade(planet, i); result[i].mCircle = GetUpgradeCircle(mRenderer.GetCamera().GetCircleOfObject(obj, 50 + (int) planet.PlanetSize * 18), i, 5); } return result; } // if no return yet, the planet has an upgrade (not StarFleet!) // the circle is now in the center of the upgrade return result; }
/// <summary> /// Draws the Prperties of a unit in the Propertiefield /// </summary> /// <param name="obj">Unit to describe</param> /// <param name="index">Index of the Propertiefield, 0 is the first</param> /// <param name="amount">Amount of Appearence of the Object</param> private void DrawPropertieText(GraphicObject obj, int index, int amount) { if (obj.mGameObject is Interceptor || obj.mGameObject is Predator || obj.mGameObject is Defender) { WritePropertie(obj.mGameObject.GetKind()[0] + "(" + amount + ")", index, 0); WritePropertie("Gesundheit: " + ((ISpaceship) obj.mGameObject).Health.ToString(CultureInfo.InvariantCulture), index, 1); WritePropertie("Schaden: " + ((IAttacker) obj.mGameObject).AttackDamage.ToString(CultureInfo.InvariantCulture), index, 2); WritePropertie("Tempo: " + ((IMovable) obj.mGameObject).MovementSpeed.ToString(CultureInfo.InvariantCulture), index, 3); WritePropertie("Sichtfeld: " + (obj.mGameObject).LineOfSight.ToString(CultureInfo.InvariantCulture), index, 4); } else if (obj.mGameObject is DeathStar) { WritePropertie(obj.mGameObject.GetKind()[0] + "(" + amount + ")", index, 0); WritePropertie("Ruestung: " + ((DeathStar) obj.mGameObject).Shield.ToString(CultureInfo.InvariantCulture), index, 1); WritePropertie("Schaden: " + ((DeathStar) obj.mGameObject).AttackDamage.ToString(CultureInfo.InvariantCulture), index, 2); WritePropertie("Tempo: " + ((IMovable) obj.mGameObject).MovementSpeed.ToString(CultureInfo.InvariantCulture), index, 3); WritePropertie("Sichtfeld: " + (obj.mGameObject).LineOfSight.ToString(CultureInfo.InvariantCulture), index, 4); } else if (obj.mGameObject is Planet) { WritePropertie(obj.mGameObject.GetKind()[0] + "(" + amount + ")", index, 0); WritePropertie("Typ: " + obj.mGameObject.GetKind()[1], index, 1); WritePropertie("Minions: " + ((Planet) obj.mGameObject).MinionCount.ToString(CultureInfo.InvariantCulture), index, 2); WritePropertie("Sichtfeld: " + (obj.mGameObject).LineOfSight.ToString(CultureInfo.InvariantCulture), index, 3); WritePropertie("MaxLimit: " + ((Planet) obj.mGameObject).MinionLimit.ToString(CultureInfo.InvariantCulture), index, 4); } }
/// <summary> /// Draws a pictogram on every planet that has an upgrade /// </summary> /// <param name="obj">the planet object</param> internal void DrawPlanetUpgradePictogram(GraphicObject obj) { var list = GetActiveUpgrades(obj); // only upgraded planets get a picto if (list.Length != 1 && list.Length != 3) return; var planet = (Planet) obj.mGameObject; var circle = mRenderer.GetCamera().GetCircleOfObject(obj, 50 + (int) planet.PlanetSize * 18); // get the first upgrade in the list (its the only upgrade or the interceptor upgrade) var upgrade = list[0]; // Draw this texture on the planet mSpriteBatch.Draw(upgrade.mTexture, new Rectangle((int) (circle.X - circle.Z / 2f), (int) (circle.Y - circle.Z / 2f), (int) circle.Z, (int) circle.Z), Color.White); }
/// <summary> /// Draws Upgradeoptions around the planet, /// if the planet allready have a upgrade it draws its identification /// </summary> /// <param name="obj">Graphic Object of the planet</param> /// <param name="state"> Position of the Mouse Cursor </param> /// <returns>The Upgrade where the Mouse is over</returns> internal Upgrade DrawPlanetUpgradeAroundPlanet(GraphicObject obj, MouseState state) { var hoverUpgrade = new Upgrade(); var available = new Color(255, 255, 255); var blocked = new Color(70, 70, 70); // Get the list of Upgrades the planet has var list = GetActiveUpgrades(obj); var mousePosition = new Vector2(state.X, state.Y); // if the planet has no upgrades, Five Upgrades are available // if the panet has the starfleet upgrade, Three upgrades availbale if (list.Length > 1) foreach (var upgrade in list) { var upgradePosition = new Vector2(upgrade.mCircle.X, upgrade.mCircle.Y); var color = upgrade.mAvailable ? available : blocked; // make the hover effect and set the return upgrade if (Vector2.Distance(mousePosition, upgradePosition) < (upgrade.mCircle.Z / 2f)) { if (upgrade.mAvailable) color = Color.PaleGreen; hoverUpgrade = upgrade; } // Draw the green circle behind upgrade picto mSpriteBatch.Draw(mUpgrade, new Rectangle((int) (upgrade.mCircle.X - upgrade.mCircle.Z / 2f), (int) (upgrade.mCircle.Y - upgrade.mCircle.Z / 2f), (int) upgrade.mCircle.Z, (int) upgrade.mCircle.Z), color); // draw upgrade picto mSpriteBatch.Draw(upgrade.mTexture, new Rectangle((int) (upgrade.mCircle.X - upgrade.mCircle.Z / 2f), (int) (upgrade.mCircle.Y - upgrade.mCircle.Z / 2f), (int) upgrade.mCircle.Z, (int) upgrade.mCircle.Z), color); } // return the object where the mouse is over at the moment return hoverUpgrade; }