本文整理汇总了C#中System.Entity.Component方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.Component方法的具体用法?C# Entity.Component怎么用?C# Entity.Component使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.Component方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGlow
public void CreateGlow(Entity lightSource)
{
var center = lightSource.Component<Position>().Coords;
var source = lightSource.Component<LightSource>();
// Radius, light strength, fog strength; must start in the center
var lightPools = new[]
{
new[] {1, 30, 0},
new[] {2, 25, 5},
new[] {Convert.ToInt32(source.Radius*.6), 20, 10},
new[] {Convert.ToInt32(source.Radius*.75), 12, 25},
new[] {Convert.ToInt32(source.Radius*.9), 5, 40}
};
var glow = new Dictionary<GridPoint, Entity>();
foreach (var pool in lightPools)
{
var points = Utilities.CreateCircle(center, pool[0], true);
foreach (var point in points)
{
if (glow.ContainsKey(point) == false)
{
var lightStrength = source.Strength * pool[1] / 100.0;
var fogStrength = source.Strength * pool[2] / 100.0;
var light = new Light(source.Color, lightStrength, fogStrength);
glow[point] = new Entity("Light", new Component[] { new Position(point.X, point.Y), light } );
}
}
}
_sourcesAndLights.Add(lightSource, glow.Values.ToList());
}
示例2: Register
public override void Register(Entity entity)
{
if (entity.Component<Mob>() != null)
{
_mobs.Add(entity);
}
if (entity.Component<Obstacle>() != null)
{
_obstacles.Add(entity);
}
}
示例3: Deregister
public override void Deregister(Entity entity)
{
if (entity.Component<Tile>() != null)
{
var positions = entity.Component<IPosition>().Positions;
foreach (var pos in positions)
{
_map[pos.X, pos.Y] = null;
}
SetTiles(_region.Default, positions);
}
}
示例4: Register
public override void Register(Entity entity)
{
if (entity.Component<Harvestable>() != null)
{
_harvestables.Add(entity);
}
}
示例5: Register
public override void Register(Entity entity)
{
var item = entity.Component<InventoryItem>();
if (item != null && _inventory.ContainsKey(entity.Name) == false)
{
_inventory.Add(entity.Name, item);
}
}
示例6: DrawEntity
public void DrawEntity(Entity entity)
{
var position = entity.Component<IPosition>();
if (position == null) return;
var graphic = entity.Component<BeadGraphic>();
if (graphic != null)
{
foreach (var pos in position.Positions)
{
if (GameState.OnScreen(pos.X, pos.Y))
DrawBeadGraphic(pos.X, pos.Y, graphic);
}
}
var overlay = entity.Component<Overlay>();
if (overlay != null)
{
foreach (var pos in position.Positions)
{
DrawOverlay(pos.X, pos.Y, overlay);
}
}
}
示例7: MoveEntity
public void MoveEntity(Entity entity, GridPoint oldPos, GridPoint newPos, bool checkPassable = true)
{
var canMove = true;
if (checkPassable == true)
{
if (CanPassThroughSquare(entity, newPos) == false)
canMove = false;
}
if (canMove == true)
{
var pos = entity.Component<IPosition>();
pos.ChangePosition(oldPos, newPos);
GameState.DrawMap();
}
}
示例8: CanPass
private bool CanPass(Entity traveler, Entity blocker)
{
var mob = traveler.Component<Mob>();
var obstacle = blocker.Component<Obstacle>();
// If the obstacle blocks everything, return false
if (obstacle.MovementTypesBlocked.Contains("all"))
return false;
// Get all the flags the traveler has that the obstacle doesn't
var flags = from flag in mob.MovementTypes
where obstacle.MovementTypesBlocked.Contains(flag) == false
select flag;
// If the traveler has any flags (can pass) that the obstacle doesn't (can block),
// then the traveler can pass over the obstacle
return flags.Any();
}
示例9: Register
public override void Register(Entity entity)
{
var position = entity.Component<IPosition>();
if (position == null) return;
var beadGraphic = entity.Component<BeadGraphic>();
var overlay = entity.Component<Overlay>();
var light = entity.Component<Light>();
var darkness = entity.Component<Darkness>();
if (beadGraphic != null)
{
_graphics.Add(entity);
}
if (overlay != null)
{
_overlays.Add(entity);
}
if (light != null)
{
_lights.Add(entity);
}
if (darkness != null)
{
_darkness.Add(entity);
}
if (beadGraphic != null || overlay != null || light != null || darkness != null)
{
GameState.DrawMap();
}
}
示例10: Register
public override void Register(Entity entity)
{
var lightSource = entity.Component<LightSource>();
if (lightSource != null)
{
CreateGlow(entity);
}
}
示例11: BuildEntity
private void BuildEntity()
{
if (_name == null)
{
throw new Exception("Error: Call start before calling build!");
}
var tile = new Entity(_name, _requiredComponents.Union(_optionalComponents));
if (tile.Component<Buildable>() != null)
{
Action<bool> callback = isPressed => GameState.SwitchBuildable(_name, isPressed);
ButtonBuilder.Start(_name, ButtonType.Build, _graphic, _buttonColor, callback);
ButtonBuilder.AddBorder(_buttonBorderColor, _buttonBorderWidth);
if (_graphic.Glyph != ' ')
ButtonBuilder.AddGlyph(_buttonGlyphColor, _graphic.Glyph);
ButtonBuilder.Build();
}
Initialize();
}
示例12: PressButton
private void PressButton(Entity clicked)
{
var button = clicked.Component<MenuButton>();
button.Toggle();
var buttonGraphic = clicked.Component<ButtonGraphic>();
var beadGraphic = clicked.Component<BeadGraphic>();
if (button.IsPressed == true)
{
buttonGraphic.ChangeToPressedGraphic(beadGraphic);
}
else
{
buttonGraphic.ChangeToOriginalGraphic(beadGraphic);
}
button.Callback(button.IsPressed);
OpenMenu();
}
示例13: DrawButton
private void DrawButton(Entity buttonEntity)
{
var pos = buttonEntity.Component<Position>();
GameState.DrawEntity(buttonEntity);
var buildable = buttonEntity.Component<Buildable>();
if (buildable != null)
{
DrawCounter(pos.X + 1, pos.Y, buildable.Cost, 1, _buildCounterColor, _bgColor);
GameState.DrawString(pos.X + 3, pos.Y, buttonEntity.Name, _buildCounterColor);
}
}