added TurretedUnit

3tnk works; jeep's turret is off-center (and possibly hard-coded?)
This commit is contained in:
Bob
2009-10-06 20:39:40 +13:00
parent e4c3c7e5af
commit f2eeb11d0f
10 changed files with 96 additions and 35 deletions

View File

@@ -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<Pair<Sprite,float2>> CurrentImages { get; }
public virtual void Tick(Game game, int t) { }
protected Actor(Game game)

View File

@@ -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);

View File

@@ -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 )

View File

@@ -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();

View File

@@ -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);

View File

@@ -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<Pair<Sprite, float2>> CurrentImages { get { yield return Pair.New( animation.Image, 24 * (float2)location ); } }
}
}

View File

@@ -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();

View File

@@ -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<Pair<Sprite, float2>> CurrentImages
{
get
{
foreach( var x in currentImages )
yield return Pair.New( x, 24 * (float2)location );
}
}
}
}

View File

@@ -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<Pair<Sprite, float2>> 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<Sprite, float2> 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<Pair<Sprite, float2>> CurrentImages
{
get
{
foreach( var x in base.CurrentImages )
yield return x;
yield return Centered( turretAnim.Image, CenterLocation );
}
}
}
}

View File

@@ -130,6 +130,20 @@
<sequence name="harvest7" start="88" length="8"/>
</unit>
<!-- heavy tank -->
<unit name="3tnk">
<sequence name="idle" start="0" length="32"/>
<sequence name="turret" start="32" length="32"/>
</unit>
<!-- jeep -->
<unit name="jeep">
<sequence name="idle" start="0" length="32"/>
<sequence name="turret" start="32" length="32"/>
</unit>
<!-- build clock - hacked in -->
<unit name="clock">