generalising selection, issuing of orders

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1283 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
bob
2007-07-16 01:01:45 +00:00
parent 74fb71b253
commit acba1dc8e4
9 changed files with 56 additions and 14 deletions

View File

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

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenRa.Game
{
interface ISelectable
{
//Sprite CurrentCursor( int x, int y );
MoveOrder Order( int x, int y );
}
}

View File

@@ -23,7 +23,7 @@ namespace OpenRa.Game
Sidebar sidebar;
Viewport viewport;
Mcv myUnit;
ISelectable myUnit;
static Size GetResolution(Settings settings)
{
@@ -62,7 +62,9 @@ namespace OpenRa.Game
world.Add(new Mcv(24 * new float2(5, 5), 3));
world.Add(new Mcv(24 * new float2(7, 5), 2));
world.Add(myUnit = new Mcv(24 * new float2(9, 5), 1));
Mcv mcv = new Mcv( 24 * new float2( 9, 5 ), 1 );
myUnit = mcv;
world.Add( mcv );
world.Add(new Refinery(24 * new float2(5, 7), 1));
@@ -87,8 +89,11 @@ namespace OpenRa.Game
if (e.Button == MouseButtons.Left)
{
MoveOrder order = new MoveOrder(lastPos + viewport.Location);
myUnit.Accept(order);
//MoveOrder order = new MoveOrder(lastPos + viewport.Location);
//myUnit.Accept(order);
int x = (int)( ( e.X + viewport.Location.X ) / 24 );
int y = (int)( ( e.Y + viewport.Location.Y ) / 24 );
myUnit.Order( x, y ).Apply();
}
}

View File

@@ -7,15 +7,17 @@ using BluntDirectX.Direct3D;
namespace OpenRa.Game
{
class Mcv : Actor
class Mcv : Actor, ISelectable
{
static Range<int>? mcvRange = null;
MoveOrder currentOrder = null;
int facing = 0;
float2 location;
public Mcv( float2 location, int palette )
{
this.location = location;
this.renderLocation = this.location - new float2( 12, 12 ); // HACK: display the mcv centered in it's cell
this.palette = palette;
if (mcvRange == null)
@@ -75,8 +77,11 @@ namespace OpenRa.Game
if( currentOrder == null )
return;
if( float2.WithinEpsilon( location, currentOrder.Destination, 1.0f ) )
if( float2.WithinEpsilon( renderLocation, currentOrder.Destination, 1.0f ) )
{
currentOrder = null;
return;
}
Range<float2> r = new Range<float2>(
new float2( -Speed * (float)t, -Speed * (float)t ),
@@ -92,6 +97,13 @@ namespace OpenRa.Game
facing = ( facing + 31 ) % 32;
else
facing = ( facing + 1 ) % 32;
renderLocation = location - new float2( 12, 12 ); // HACK: center mcv in it's cell
}
public MoveOrder Order( int x, int y )
{
return new MoveOrder( this, x, y );
}
}
}

View File

@@ -6,11 +6,23 @@ namespace OpenRa.Game
{
class MoveOrder
{
public readonly Mcv Unit;
public readonly float2 Destination;
public MoveOrder(float2 destination)
public MoveOrder( Mcv unit, int x, int y )
: this( unit, new float2( x * 24, y * 24 ) )
{
this.Destination = destination - new float2(24,24); //HACK account for MCV size
}
public MoveOrder(Mcv unit, float2 destination)
{
this.Unit = unit;
this.Destination = destination;
}
public void Apply()
{
Unit.Accept( this );
}
}
}

View File

@@ -43,6 +43,7 @@
<Compile Include="Actor.cs" />
<Compile Include="Clock.cs" />
<Compile Include="float2.cs" />
<Compile Include="ISelectable.cs" />
<Compile Include="MoveOrder.cs" />
<Compile Include="Region.cs" />
<Compile Include="SheetBuilder.cs" />

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game
if (refineryRange == null)
refineryRange = UnitSheetBuilder.AddUnit("proc");
this.location = location;
this.renderLocation = location;
this.palette = palette;
}

View File

@@ -10,7 +10,7 @@ namespace OpenRa.Game
{
public Tree(TreeReference r, TreeCache renderer, Map map)
{
location = 24 * (new float2(r.Location) - new float2(map.XOffset, map.YOffset));
renderLocation = 24 * (new float2(r.Location) - new float2(map.XOffset, map.YOffset));
currentImages = new Sprite[] { renderer.GetImage(r.Image) };
}

View File

@@ -41,14 +41,14 @@ namespace OpenRa.Game
Sprite[] images = a.CurrentImages;
if( a.location.X > range.End.X || a.location.X < range.Start.X - images[ 0 ].bounds.Width )
if( a.renderLocation.X > range.End.X || a.renderLocation.X < range.Start.X - images[ 0 ].bounds.Width )
continue;
if (a.location.Y > range.End.Y || a.location.Y < range.Start.Y - images[0].bounds.Height)
if (a.renderLocation.Y > range.End.Y || a.renderLocation.Y < range.Start.Y - images[0].bounds.Height)
continue;
foreach( Sprite image in images )
spriteRenderer.DrawSprite(image, a.location, a.palette);
spriteRenderer.DrawSprite(image, a.renderLocation, a.palette);
}
spriteRenderer.Flush();