render in bridge code
This commit is contained in:
@@ -120,6 +120,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
public bool IsDead { get { return Health <= 0; } }
|
public bool IsDead { get { return Health <= 0; } }
|
||||||
public bool IsInWorld { get; set; }
|
public bool IsInWorld { get; set; }
|
||||||
|
public bool RemoveOnDeath = true;
|
||||||
|
|
||||||
public DamageState GetDamageState()
|
public DamageState GetDamageState()
|
||||||
{
|
{
|
||||||
@@ -145,6 +146,7 @@ namespace OpenRa
|
|||||||
if (attacker.Owner != null)
|
if (attacker.Owner != null)
|
||||||
attacker.Owner.Kills++;
|
attacker.Owner.Kills++;
|
||||||
|
|
||||||
|
if (RemoveOnDeath)
|
||||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,36 +4,37 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenRa.Graphics;
|
using OpenRa.Graphics;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
|
using IjwFramework.Collections;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRa.Traits
|
namespace OpenRa.Traits
|
||||||
{
|
{
|
||||||
class BridgeInfo : ITraitInfo
|
class BridgeInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public object Create(Actor self) { return new Bridge(); }
|
public object Create(Actor self) { return new Bridge(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Bridge : IRender, ITick, ICustomTerrain
|
class Bridge : IRender, ITick, ICustomTerrain
|
||||||
{
|
{
|
||||||
Animation anim;
|
|
||||||
Dictionary<int2, int> Tiles;
|
Dictionary<int2, int> Tiles;
|
||||||
TileTemplate Template;
|
TileTemplate Template;
|
||||||
|
Dictionary<int2, Sprite> TileSprites;
|
||||||
|
|
||||||
|
public Bridge(Actor self) { self.RemoveOnDeath = false; }
|
||||||
|
|
||||||
|
static Cache<TileReference, Sprite> Sprites =
|
||||||
|
new Cache<TileReference, Sprite>(
|
||||||
|
x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x),
|
||||||
|
new Size(Game.CellSize, Game.CellSize)));
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render(Actor self)
|
public IEnumerable<Renderable> Render(Actor self)
|
||||||
{
|
{
|
||||||
if (anim != null)
|
if (Template == null) yield break;
|
||||||
return new[] { Util.Centered(self, anim.Image, self.CenterLocation) };
|
foreach (var t in TileSprites)
|
||||||
else
|
yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold);
|
||||||
return new Renderable[] { };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self) {}
|
||||||
{
|
|
||||||
if (anim == null)
|
|
||||||
{
|
|
||||||
anim = new Animation("3tnk");
|
|
||||||
anim.PlayRepeating("idle");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetTiles(TileTemplate template, Dictionary<int2, int> replacedTiles)
|
public void SetTiles(TileTemplate template, Dictionary<int2, int> replacedTiles)
|
||||||
{
|
{
|
||||||
@@ -42,12 +43,15 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
foreach (var t in replacedTiles.Keys)
|
foreach (var t in replacedTiles.Keys)
|
||||||
Game.world.customTerrain[t.X, t.Y] = this;
|
Game.world.customTerrain[t.X, t.Y] = this;
|
||||||
|
|
||||||
|
TileSprites = replacedTiles.ToDictionary(
|
||||||
|
a => a.Key,
|
||||||
|
a => Sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetCost(int2 p, UnitMovementType umt)
|
public double GetCost(int2 p, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong.
|
var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong.
|
||||||
|
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user