From f2eeb11d0f7bea2fcb7b8495b030afd1d5584a9d Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 6 Oct 2009 20:39:40 +1300 Subject: [PATCH] added TurretedUnit 3tnk works; jeep's turret is off-center (and possibly hard-coded?) --- OpenRa.Game/Actor.cs | 4 +-- OpenRa.Game/Game.cs | 5 +-- OpenRa.Game/Graphics/Animation.cs | 2 +- OpenRa.Game/Graphics/WorldRenderer.cs | 18 +++++----- OpenRa.Game/MainWindow.cs | 17 ++++++---- OpenRa.Game/PlayerOwned.cs | 10 +++--- OpenRa.Game/Sidebar.cs | 2 +- OpenRa.Game/Tree.cs | 12 +++++-- OpenRa.Game/Unit.cs | 47 ++++++++++++++++++++++++--- sequences.xml | 14 ++++++++ 10 files changed, 96 insertions(+), 35 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index c1479e0dd0..1c1a673329 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -6,6 +6,7 @@ using OpenRa.FileFormats; using System.Windows.Forms; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -13,9 +14,8 @@ namespace OpenRa.Game { public readonly Game game; - public abstract float2 RenderLocation { get; } public Player owner; - public abstract Sprite[] CurrentImages { get; } + public abstract IEnumerable> CurrentImages { get; } public virtual void Tick(Game game, int t) { } protected Actor(Game game) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 043be2a03f..fb91c4947c 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -52,10 +52,7 @@ namespace OpenRa.Game string[] buildings = { "fact", "powr", "apwr", "weap", "barr", "atek", "stek", "dome" }; foreach (string s in buildings) - { - var t = s; - buildingCreation.Add(t, (location, owner) => new Building(t, location, owner, this)); - } + buildingCreation.Add(s, (location, owner) => new Building(s, location, owner, this)); controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL worldRenderer = new WorldRenderer(renderer, world); diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index d1debfef51..b3be057d05 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -15,7 +15,7 @@ namespace OpenRa.Game.Graphics Play( "idle" ); } - public Sprite[] Images { get { return new Sprite[] { currentSequence.GetSprite( frame ) }; } } + public Sprite Image { get { return currentSequence.GetSprite( frame ); } } public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } } public void Play( string sequenceName ) diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index d060b4bbae..92dc5f3248 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -29,17 +29,19 @@ namespace OpenRa.Game.Graphics foreach (Actor a in world.Actors) { - Sprite[] images = a.CurrentImages; - float2 loc = a.RenderLocation; + var images = a.CurrentImages; - if (loc.X > rect.Right || loc.X < rect.Left - images[0].bounds.Width) - continue; + foreach( var image in images ) + { + var loc = image.Second; - if (loc.Y > rect.Bottom || loc.Y < rect.Top - images[0].bounds.Height) - continue; + if( loc.X > rect.Right || loc.X < rect.Left - image.First.bounds.Width ) + continue; + if( loc.Y > rect.Bottom || loc.Y < rect.Top - image.First.bounds.Height ) + continue; - foreach (Sprite image in images) - spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0); + spriteRenderer.DrawSprite( image.First, loc, ( a.owner != null ) ? a.owner.Palette : 0 ); + } } spriteRenderer.Flush(); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 8b3c163eb0..c35226a0f2 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -36,19 +36,24 @@ namespace OpenRa.Game Location = Point.Empty; Visible = true; - bool windowed = !settings.GetValue("fullscreen", false); - renderer = new Renderer(this, GetResolution(settings), windowed); + //bool windowed = !settings.GetValue("fullscreen", false); + //renderer = new Renderer(this, GetResolution(settings), windowed); + renderer = new Renderer( this, new Size( 800, 600 ), true ); SheetBuilder.Initialize( renderer ); - game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) ); + game = new Game( settings.GetValue( "map", "scg11eb.ini" ), renderer, new int2( ClientSize ) ); SequenceProvider.ForcePrecache(); + Unit controlled; + game.world.Add( new Unit( "mcv", new int2( 5, 5 ), game.players[ 3 ], game ) ); game.world.Add( new Unit( "mcv", new int2( 7, 5 ), game.players[ 2 ], game ) ); - Unit mcv = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game ); - game.controller.orderGenerator = mcv; - game.world.Add( mcv ); + game.world.Add( controlled = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game ) ); + + game.world.Add( controlled = new TurretedUnit( "jeep", new int2( 9, 7 ), game.players[ 1 ], game ) ); + + game.controller.orderGenerator = controlled; sidebar = new Sidebar(Race.Soviet, renderer, game); diff --git a/OpenRa.Game/PlayerOwned.cs b/OpenRa.Game/PlayerOwned.cs index 06e969abaf..8c65b3866f 100644 --- a/OpenRa.Game/PlayerOwned.cs +++ b/OpenRa.Game/PlayerOwned.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -17,11 +19,7 @@ namespace OpenRa.Game this.location = location; } - public override float2 RenderLocation - { - get { return 24.0f * (float2)location; } - } - - public override Sprite[] CurrentImages { get { return animation.Images; } } + public override IEnumerable> CurrentImages { get { yield return Pair.New( animation.Image, 24 * (float2)location ); } } } } + \ No newline at end of file diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 465776a8e2..8c8768e958 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -108,7 +108,7 @@ namespace OpenRa.Game spriteRenderer.Flush(); - clockRenderer.DrawSprite( clockAnimation.Images[0], region.Location, 0 ); + clockRenderer.DrawSprite( clockAnimation.Image, region.Location, 0 ); clockAnimation.Tick(1); clockRenderer.Flush(); diff --git a/OpenRa.Game/Tree.cs b/OpenRa.Game/Tree.cs index 14b82f361d..e295eea0e5 100644 --- a/OpenRa.Game/Tree.cs +++ b/OpenRa.Game/Tree.cs @@ -4,6 +4,7 @@ using System.Text; using OpenRa.FileFormats; using System.Drawing; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -19,8 +20,13 @@ namespace OpenRa.Game } Sprite[] currentImages; - public override Sprite[] CurrentImages { get { return currentImages; } } - - public override float2 RenderLocation { get { return 24 * location; } } + public override IEnumerable> CurrentImages + { + get + { + foreach( var x in currentImages ) + yield return Pair.New( x, 24 * (float2)location ); + } + } } } diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index 4b9bd67528..994429d0ec 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -1,5 +1,9 @@ using System; +using System.Collections.Generic; +using System.Linq; + using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -67,14 +71,20 @@ namespace OpenRa.Game currentOrder( t ); } - public override float2 RenderLocation + public override IEnumerable> CurrentImages + { + get + { + yield return Centered( animation.Image, CenterLocation ); + } + } + + public float2 CenterLocation { get { float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f; - - float2 location = 24 * float2.Lerp( fromCell, toCell, fraction ); - return ( location - renderOffset ).Round(); + return new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction ); } } @@ -97,5 +107,34 @@ namespace OpenRa.Game } public void PrepareOverlay(Game game, int2 xy) { } + + protected static Pair Centered( Sprite s, float2 location ) + { + var loc = location - 0.5f * s.size; + return Pair.New( s, loc.Round() ); + } + } + + class TurretedUnit : Unit + { + Animation turretAnim; + int turretFacing { get { return facing; } } + + public TurretedUnit( string name, int2 cell, Player owner, Game game ) + : base( name, cell, owner, game ) + { + turretAnim = new Animation( name ); + turretAnim.PlayFetchIndex( "turret", () => turretFacing ); + } + + public override IEnumerable> CurrentImages + { + get + { + foreach( var x in base.CurrentImages ) + yield return x; + yield return Centered( turretAnim.Image, CenterLocation ); + } + } } } diff --git a/sequences.xml b/sequences.xml index 3856828cae..7fd1819920 100644 --- a/sequences.xml +++ b/sequences.xml @@ -130,6 +130,20 @@ + + + + + + + + + + + + + +