git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1312 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
(no author)
2007-07-20 04:18:02 +00:00
parent df4e71e89e
commit db17062511
5 changed files with 28 additions and 22 deletions

View File

@@ -10,7 +10,7 @@ namespace OpenRa.Game
{
abstract class Actor
{
public float2 renderLocation;
public abstract float2 RenderLocation { get; }
public int palette;
public abstract Sprite[] CurrentImages { get; }
public virtual void Tick(World world, double t) { }

View File

@@ -7,10 +7,11 @@ namespace OpenRa.Game
class Building : Actor
{
protected Animation animation;
protected int2 location;
public Building( string name, int2 location, int palette )
{
this.renderLocation = 24.0f * location.ToFloat2();
this.location = location;
this.palette = palette;
animation = new Animation( name );
@@ -26,5 +27,10 @@ namespace OpenRa.Game
{
get { return animation.Images; }
}
public override float2 RenderLocation
{
get { return 24.0f * location.ToFloat2(); }
}
}
}

View File

@@ -8,14 +8,17 @@ namespace OpenRa.Game
{
class Tree : Actor
{
int2 location;
public Tree(TreeReference r, TreeCache renderer, Map map)
{
renderLocation = 24 * (new float2(r.Location) - new float2(map.XOffset, map.YOffset));
location = new int2( r.Location ) - new int2( map.XOffset, map.YOffset );
currentImages = new Sprite[] { renderer.GetImage(r.Image) };
}
Sprite[] currentImages;
public override Sprite[] CurrentImages { get { return currentImages; } }
public override float2 RenderLocation { get { return 24 * location.ToFloat2(); } }
}
}

View File

@@ -20,8 +20,6 @@ namespace OpenRa.Game
{
fromCell = toCell = cell;
this.renderOffset = renderOffset;
// HACK: display the mcv centered in it's cell;
renderLocation = ( cell * 24 ).ToFloat2() - renderOffset;
this.palette = palette;
}
@@ -101,17 +99,6 @@ namespace OpenRa.Game
}
}
}
float2 location;
if( moveFraction > 0 )
location = 24 * float2.Lerp( fromCell.ToFloat2(), toCell.ToFloat2(),
(float)moveFraction / moveFractionTotal );
else
location = 24 * fromCell.ToFloat2();
renderLocation = location - renderOffset;
renderLocation = renderLocation.Round();
};
}
@@ -130,5 +117,16 @@ namespace OpenRa.Game
{
get { return toCell; }
}
public override float2 RenderLocation
{
get
{
float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f;
float2 location = 24 * float2.Lerp( fromCell.ToFloat2(), toCell.ToFloat2(), fraction );
return ( location - renderOffset ).Round(); ;
}
}
}
}

View File

@@ -13,13 +13,11 @@ namespace OpenRa.Game
List<Actor> actors = new List<Actor>();
List<Action<World>> frameEndActions = new List<Action<World>>();
SpriteRenderer spriteRenderer;
Renderer renderer;
Viewport viewport;
public ISelectable myUnit;
public World(Renderer renderer, Viewport viewport)
{
this.renderer = renderer;
this.viewport = viewport;
viewport.AddRegion(Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw));
spriteRenderer = new SpriteRenderer(renderer, true);
@@ -44,15 +42,16 @@ namespace OpenRa.Game
a.Tick( this, dt );
Sprite[] images = a.CurrentImages;
float2 loc = a.RenderLocation;
if( a.renderLocation.X > range.End.X || a.renderLocation.X < range.Start.X - images[ 0 ].bounds.Width )
if( loc.X > range.End.X || loc.X < range.Start.X - images[ 0 ].bounds.Width )
continue;
if (a.renderLocation.Y > range.End.Y || a.renderLocation.Y < range.Start.Y - images[0].bounds.Height)
if( loc.Y > range.End.Y || loc.Y < range.Start.Y - images[ 0 ].bounds.Height )
continue;
foreach( Sprite image in images )
spriteRenderer.DrawSprite(image, a.renderLocation, a.palette);
spriteRenderer.DrawSprite(image, loc, a.palette);
}
foreach( Action<World> a in frameEndActions )