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:
@@ -10,7 +10,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
abstract class Actor
|
abstract class Actor
|
||||||
{
|
{
|
||||||
public float2 location;
|
public float2 renderLocation;
|
||||||
public int palette;
|
public int palette;
|
||||||
public abstract Sprite[] CurrentImages { get; }
|
public abstract Sprite[] CurrentImages { get; }
|
||||||
public abstract void Tick( double t );
|
public abstract void Tick( double t );
|
||||||
|
|||||||
12
OpenRa.Game/ISelectable.cs
Normal file
12
OpenRa.Game/ISelectable.cs
Normal 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace OpenRa.Game
|
|||||||
Sidebar sidebar;
|
Sidebar sidebar;
|
||||||
Viewport viewport;
|
Viewport viewport;
|
||||||
|
|
||||||
Mcv myUnit;
|
ISelectable myUnit;
|
||||||
|
|
||||||
static Size GetResolution(Settings settings)
|
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(5, 5), 3));
|
||||||
world.Add(new Mcv(24 * new float2(7, 5), 2));
|
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));
|
world.Add(new Refinery(24 * new float2(5, 7), 1));
|
||||||
|
|
||||||
@@ -87,8 +89,11 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
if (e.Button == MouseButtons.Left)
|
if (e.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
MoveOrder order = new MoveOrder(lastPos + viewport.Location);
|
//MoveOrder order = new MoveOrder(lastPos + viewport.Location);
|
||||||
myUnit.Accept(order);
|
//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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,17 @@ using BluntDirectX.Direct3D;
|
|||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
class Mcv : Actor
|
class Mcv : Actor, ISelectable
|
||||||
{
|
{
|
||||||
static Range<int>? mcvRange = null;
|
static Range<int>? mcvRange = null;
|
||||||
MoveOrder currentOrder = null;
|
MoveOrder currentOrder = null;
|
||||||
int facing = 0;
|
int facing = 0;
|
||||||
|
float2 location;
|
||||||
|
|
||||||
public Mcv( float2 location, int palette )
|
public Mcv( float2 location, int palette )
|
||||||
{
|
{
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
this.renderLocation = this.location - new float2( 12, 12 ); // HACK: display the mcv centered in it's cell
|
||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
|
|
||||||
if (mcvRange == null)
|
if (mcvRange == null)
|
||||||
@@ -75,8 +77,11 @@ namespace OpenRa.Game
|
|||||||
if( currentOrder == null )
|
if( currentOrder == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( float2.WithinEpsilon( location, currentOrder.Destination, 1.0f ) )
|
if( float2.WithinEpsilon( renderLocation, currentOrder.Destination, 1.0f ) )
|
||||||
|
{
|
||||||
|
currentOrder = null;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Range<float2> r = new Range<float2>(
|
Range<float2> r = new Range<float2>(
|
||||||
new float2( -Speed * (float)t, -Speed * (float)t ),
|
new float2( -Speed * (float)t, -Speed * (float)t ),
|
||||||
@@ -92,6 +97,13 @@ namespace OpenRa.Game
|
|||||||
facing = ( facing + 31 ) % 32;
|
facing = ( facing + 31 ) % 32;
|
||||||
else
|
else
|
||||||
facing = ( facing + 1 ) % 32;
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,23 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
class MoveOrder
|
class MoveOrder
|
||||||
{
|
{
|
||||||
|
public readonly Mcv Unit;
|
||||||
public readonly float2 Destination;
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Clock.cs" />
|
<Compile Include="Clock.cs" />
|
||||||
<Compile Include="float2.cs" />
|
<Compile Include="float2.cs" />
|
||||||
|
<Compile Include="ISelectable.cs" />
|
||||||
<Compile Include="MoveOrder.cs" />
|
<Compile Include="MoveOrder.cs" />
|
||||||
<Compile Include="Region.cs" />
|
<Compile Include="Region.cs" />
|
||||||
<Compile Include="SheetBuilder.cs" />
|
<Compile Include="SheetBuilder.cs" />
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace OpenRa.Game
|
|||||||
if (refineryRange == null)
|
if (refineryRange == null)
|
||||||
refineryRange = UnitSheetBuilder.AddUnit("proc");
|
refineryRange = UnitSheetBuilder.AddUnit("proc");
|
||||||
|
|
||||||
this.location = location;
|
this.renderLocation = location;
|
||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
public Tree(TreeReference r, TreeCache renderer, Map map)
|
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) };
|
currentImages = new Sprite[] { renderer.GetImage(r.Image) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
Sprite[] images = a.CurrentImages;
|
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;
|
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;
|
continue;
|
||||||
|
|
||||||
foreach( Sprite image in images )
|
foreach( Sprite image in images )
|
||||||
spriteRenderer.DrawSprite(image, a.location, a.palette);
|
spriteRenderer.DrawSprite(image, a.renderLocation, a.palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|||||||
Reference in New Issue
Block a user