private Rectangle FromfbRectangle(fbRectangle rectangle) { return(new Rectangle( (int)Math.Round(rectangle.Position.X), (int)Math.Round(rectangle.Position.Y), (int)Math.Round(rectangle.Size.X), (int)Math.Round(rectangle.Size.Y) )); }
public DrawCall( Texture2D texture, fbRectangle destination, int depth = 0, Color coloring = default(Color), float rotation = 0f ) : this(texture, destination, null, depth, coloring) { Rotation = rotation; }
public fbRectangle WorldToScreen(fbRectangle rectangle) { rectangle.Position -= Camera.Position; Vector2 scaleFactor = engine.GetSize() / Camera.Size; rectangle.Position *= scaleFactor; rectangle.Size *= scaleFactor; return(rectangle); }
private void DrawTile(int x, int y) { Tile t = Game.World.Map.At(x, y); fbRectangle destination = Camera.WorldToScreen( new fbRectangle( new Vector2(x, y) * tileSize, tileSize, tileSize ) ); if (t.Station != null) { Player owner = Game.World.GetPlayer(t.Station.Owner); Engine.Draw( t.Unit == null ? Engine.GetTexture("station") : Engine.GetTexture("station-bg"), destination, owner == null ? Color.Gray : owner.Color ); } if (t.Planet != null) { Engine.Draw( t.Unit == null ? Engine.GetTexture("planet") : Engine.GetTexture("planet-bg"), destination ); } if (t.Unit != null) { DrawUnit(t.Unit); } if (Game.World.PlayerStarts.Any(v2 => v2.X == x && v2.Y == y)) { new DrawCall( Engine.GetTexture("cross"), destination ).Draw(Engine); } }
public fbCamera(fbEngine engine) { this.engine = engine; Camera = new fbRectangle( Vector2.Zero, engine.GetSize() ); new InputSubscriber(this) .Subscribe("+camera-up") .Subscribe("+camera-down") .Subscribe("+camera-left") .Subscribe("+camera-right") .Register(); }
public DrawCall( Texture2D texture, fbRectangle destination, fbRectangle source, int depth = 0, Color coloring = default(Color) ) { Texture = texture; Destination = destination; Source = source; Depth = depth; Coloring = coloring == default(Color) ? Color.White : coloring; }
public void DrawSelection() { if (Selection == null) { return; } Tile t = Game.World.Map.At(Selection.GetSelection()); if ( (SelectedUnit != null && t.Unit == SelectedUnit) || (SelectedTile == t && t.Station != null) ) { Vector2 position = t.Position.ToVector2(); if (Selection.GetSelectionType() == SelectionType.Unit) { //no i'm not going to check if it's null, it's not null. //i'll fight you. Debug.Assert(SelectedUnit != null, "SelectedUnit != null"); position = SelectedUnit .GetAnimateable() .ApplyAnimations() .Position; } fbRectangle destination = Camera.WorldToScreen( new fbRectangle( //t.Position * tileSize, position * tileSize, new Vector2(tileSize) ) ); Engine.Draw( Engine.GetTexture("ui-selection"), destination ); } }
public void Draw( Texture2D texture, fbRectangle destination, Color coloring = default(Color), int depth = 0 ) { if (destination.Size.X == -1) { destination.Size.X = texture.Width; } if (destination.Size.Y == -1) { destination.Size.Y = texture.Height; } drawCalls.Add( new DrawCall(texture, destination, depth, coloring) ); }
private void DrawUnit(Unit unit) { AnimationValues animationValues = unit .GetAnimateable() .ApplyAnimations(); fbRectangle destination = Camera.WorldToScreen( new fbRectangle( animationValues.Position * tileSize, new Vector2(tileSize) ) ); if (unit.Attacks > 0) { Engine.Draw( Engine.GetTexture("ui-attackborder"), destination, Color.White ); } Engine.Draw( Engine.GetTexture(unit.UnitType.Texture), destination, unit.Owner == -1 //dc:ed ? Color.Gray : Game.World.GetPlayer(unit.Owner).Color ); if (unit.WarpTarget != null) { fbRectangle beaconDestination = Camera.WorldToScreen( new fbRectangle( unit.WarpTarget * tileSize, tileSize ) ); Engine.Draw( Engine.GetTexture("ui-warp-beacon"), beaconDestination, Color.White ); DrawLine( destination.Position, beaconDestination.Position, 1f, new Color(0, 215, 255) ); } for (int i = 0; i < unit.Moves; i++) { Vector2 dingySize = Engine.GetTextureSize("ui-move-dingy"); Vector2 distancing = new Vector2(Camera.Scale(dingySize.X), 0); Engine.Draw( Engine.GetTexture("ui-move-dingy"), new fbRectangle( destination.Position + distancing * i, Camera.Scale(dingySize) ) ); } for (int i = 0; i < unit.Strength; i++) { Vector2 dingySize = Engine.GetTextureSize("ui-strength-dingy"); Vector2 distancing = new Vector2(0, Camera.Scale(dingySize.Y)); Engine.Draw( Engine.GetTexture("ui-strength-dingy"), new fbRectangle( destination.Position + new Vector2(0, Camera.Scale(tileSize)) - distancing * (i + 1), Camera.Scale(dingySize) ) ); } }
private void DrawRange() { if (SelectedUnit == null) { return; } int minRange; int maxRange; Color color; switch (Mode) { case InterfaceMode.Normal: if (SelectedUnit.WarpTarget != null) { return; } minRange = 1; maxRange = SelectedUnit.Moves; color = Color.LimeGreen; break; case InterfaceMode.TargettingWarp: minRange = SelectedUnit.UnitType.Moves * 5; maxRange = SelectedUnit.UnitType.Moves * 10; color = Color.CornflowerBlue; break; case InterfaceMode.TargettingBombard: minRange = SelectedUnit.UnitType.BombardMinRange; maxRange = SelectedUnit.UnitType.BombardMaxRange; color = Color.Red; break; default: throw new ArgumentException(); } for (int x = -maxRange; x <= maxRange; x++) { for (int y = -maxRange; y <= maxRange; y++) { if (!SelectedUnit.PositionInRange( SelectedUnit.Position + new Vector2i(x, y), minRange, maxRange ) ) { continue; } fbRectangle destination = Camera.WorldToScreen( new fbRectangle( new Vector2( SelectedUnit.x + x, SelectedUnit.y + y ) * tileSize, tileSize ) ); new DrawCall( Engine.GetTexture("blank"), destination, 10, color * 0.6f ).Draw(Engine); } } }