diff --git a/OpenRa.Game/Harvester.cs b/OpenRa.Game/Harvester.cs new file mode 100644 index 0000000000..692055fad6 --- /dev/null +++ b/OpenRa.Game/Harvester.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenRa.Game +{ + class Harvester : Unit + { + static Sequence idle = SequenceProvider.GetSequence("harv", "idle"); + + public override Sprite[] CurrentImages + { + get { return new Sprite[] { idle.GetSprite(facing) }; } + } + + public Harvester(int2 cell, int palette) + : base(cell, palette, new float2(12,12)) + { + } + } +} diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 4a9e4df29e..79af72adaa 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -23,8 +23,6 @@ namespace OpenRa.Game Sidebar sidebar; Viewport viewport; - ISelectable myUnit; - static Size GetResolution(Settings settings) { Size desktopResolution = Screen.PrimaryScreen.Bounds.Size; @@ -41,7 +39,9 @@ namespace OpenRa.Game Location = Point.Empty; Visible = true; - renderer = new Renderer(this, GetResolution(settings), true); + bool windowed = !settings.GetValue("fullscreeen", false); + + renderer = new Renderer(this, GetResolution(settings), windowed); map = new Map(new IniFile(File.OpenRead("../../../" + settings.GetValue("map", "scm12ea.ini")))); @@ -65,7 +65,7 @@ namespace OpenRa.Game world.Add( new Mcv( new int2( 5, 5 ), 3 ) ); world.Add( new Mcv( new int2( 7, 5 ), 2 ) ); Mcv mcv = new Mcv( new int2( 9, 5 ), 1 ); - myUnit = mcv; + world.myUnit = mcv; world.Add( mcv ); world.Add( new Refinery( new int2( 7, 5 ), 2 ) ); @@ -94,7 +94,7 @@ namespace OpenRa.Game { int x = (int)( ( e.X + viewport.Location.X ) / 24 ); int y = (int)( ( e.Y + viewport.Location.Y ) / 24 ); - myUnit.Order( new int2( x, y ) ).Apply(); + world.myUnit.Order( new int2( x, y ) ).Apply(); } } diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index 3bf114d0d3..ab71df17f4 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -9,10 +9,10 @@ namespace OpenRa.Game { class Mcv : Unit { - static Range mcvRange = UnitSheetBuilder.GetUnit( "mcv" ); + static Sequence sequence = SequenceProvider.GetSequence("mcv", "idle"); public Mcv( int2 location, int palette ) - : base( location, palette ) + : base(location, palette, new float2(12, 12)) { } @@ -30,6 +30,9 @@ namespace OpenRa.Game world.Remove( this ); world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), palette ) ); world.Add( new Refinery( fromCell - new int2( 1, -2 ), palette ) ); + + world.myUnit = new Harvester(fromCell - new int2(0, -4), palette); + world.Add((Actor)world.myUnit); } ); currentOrder = null; } @@ -38,7 +41,7 @@ namespace OpenRa.Game public override Sprite[] CurrentImages { - get { return new Sprite[] { UnitSheetBuilder.sprites[ facing + mcvRange.Start ] }; } + get { return new Sprite[] { sequence.GetSprite(facing) }; } } public override IOrder Order( int2 xy ) diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index d134a9eb4f..e119666366 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -43,6 +43,7 @@ + @@ -72,6 +73,7 @@ + diff --git a/OpenRa.Game/Settings.cs b/OpenRa.Game/Settings.cs index 512f859ff0..a6730390fc 100644 --- a/OpenRa.Game/Settings.cs +++ b/OpenRa.Game/Settings.cs @@ -35,5 +35,15 @@ namespace OpenRa.Game return result; } + + public bool GetValue(string key, bool defaultValue) + { + bool result; + + if (!bool.TryParse(GetValue(key, defaultValue.ToString()), out result)) + result = defaultValue; + + return result; + } } } diff --git a/OpenRa.Game/Truck.cs b/OpenRa.Game/Truck.cs new file mode 100644 index 0000000000..cd2611d659 --- /dev/null +++ b/OpenRa.Game/Truck.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenRa.Game +{ + class Truck : Unit + { + static Sequence sequence = SequenceProvider.GetSequence("truk", "idle"); + + public Truck(int2 cell, int palette) + : base(cell, palette, float2.Zero) + { + } + + public override Sprite[] CurrentImages + { + get { return new Sprite[] { sequence.GetSprite(facing) }; } + } + } +} diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index eb83b67687..ec26993094 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -14,11 +14,14 @@ namespace OpenRa.Game protected TickFunc currentOrder = null; protected TickFunc nextOrder = null; - public Unit( int2 cell, int palette ) + protected readonly float2 renderOffset; + + public Unit( int2 cell, int palette, float2 renderOffset ) { fromCell = toCell = cell; + this.renderOffset = renderOffset; // HACK: display the mcv centered in it's cell; - renderLocation = ( cell * 24 ).ToFloat2() - new float2( 12, 12 ); + renderLocation = ( cell * 24 ).ToFloat2() - renderOffset; this.palette = palette; } @@ -106,7 +109,7 @@ namespace OpenRa.Game else location = 24 * fromCell.ToFloat2(); - renderLocation = location - new float2( 12, 12 ); // HACK: center mcv in it's cell + renderLocation = location - renderOffset; renderLocation = renderLocation.Round(); }; diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 1488885026..3031f9ad8a 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -15,6 +15,7 @@ namespace OpenRa.Game SpriteRenderer spriteRenderer; Renderer renderer; Viewport viewport; + public ISelectable myUnit; public World(Renderer renderer, Viewport viewport) { diff --git a/sequences.xml b/sequences.xml index b9cda217a8..b04153c7fb 100644 --- a/sequences.xml +++ b/sequences.xml @@ -48,4 +48,22 @@ + + + + + + + + + + + + + + + + + +