本文整理汇总了C#中System.Entity.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.GetComponent方法的具体用法?C# Entity.GetComponent怎么用?C# Entity.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessEntity
protected override void ProcessEntity(Engine engine, Entity entity)
{
// 2 per 1000 milliseconds
var amountPerSecond = 2;
var people = entity.GetComponent<PeopleComponent>().Amount;
entity.GetComponent<GoldComponent>().Amount += (engine.DeltaMs*amountPerSecond/1000.0) * people;
}
示例2: Attach
private void Attach(int uid)
{
_master = Owner.EntityManager.GetEntity(uid);
// TODO handle this using event queue so that these sorts of interactions are deferred until we can be sure the target entity exists
_master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
Translate(_master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
}
示例3: Process
/// <summary>
/// Renders all entities with a sprite and a transform to the screen.
/// </summary>
/// <param name="e"></param>
public override void Process(Entity e)
{
try
{
//Get sprite data and transform
ITransform transform = e.GetComponent<ITransform>();
Sprite sprite = e.GetComponent<Sprite>();
if (sprite.Source != null)
//Draw to sprite batch
spriteBatch.Draw(
sprite.SpriteSheet.Texture,
ConvertUnits.ToDisplayUnits(transform.Position),
sprite.CurrentRectangle,
sprite.Color,
transform.Rotation,
sprite.Origin,
sprite.Scale,
SpriteEffects.None, sprite.Layer);
}
catch
{
e.Delete();
Console.WriteLine("Exception try-caught in RenderSystem");
}
}
示例4: Process
/// <summary>
/// Updates all the positions by applying velocity.
/// </summary>
/// <param name="entity"></param>
protected override void Process(Entity entity)
{
var pos = entity.GetComponent<PositionComponent>();
var vel = entity.GetComponent<VelocityComponent>();
var dif = vel.Value * (float)AlmiranteEngine.Time.Frame;
pos.Set(dif.X + pos.X, dif.Y + pos.Y);
}
示例5: attack
public static void attack(Entity attacker, Entity target)
{
// calc dmg
Weapon weapon = ((Equipment)attacker.GetComponent("Equipment")).MainHand;
int predamage = RollManager.roll(weapon.Dice_Num, weapon.Dice_Sides, weapon.Roll_Mod);
// subtract dmg reduction
Armor armor = ((Equipment)target.GetComponent("Equipment")).Chest;
int damage = predamage - armor.DmgReduction;
// reduce hp and shoot messages
Information targetInfo = target.GetComponent("Information") as Information;
Information attackerInfo = attacker.GetComponent("Information") as Information;
if (damage > 0)
{
target.DoAction("TakeDamage", new TakeDamageArgs(damage));
string message = String.Format("{0} swings at {1} for {2} damage.", attackerInfo.Username, targetInfo.Username, damage);
MessageManager.Instance.addMessage(message);
if (!((Hitpoints)target.GetComponent("Hitpoints")).Alive)
MessageManager.Instance.addMessage(String.Format("{0} dies!", (target.GetComponent("Information") as Information).Username));
}
else
{
string message = String.Format("{0} attacks {1}, but it glances off.", attackerInfo.Username, targetInfo.Username, damage);
MessageManager.Instance.addMessage(message);
}
}
示例6: Process
public override void Process(Entity e)
{
Body b = e.GetComponent<Body>();
Origin o = e.GetComponent<Origin>();
if (o != null)
{
Entity parent = o.Parent;
Vector2 origin = parent.GetComponent<Body>().Position;
float lastTime = elapsedSeconds;
elapsedSeconds += 16 / 1000f;
if (elapsedSeconds > orbitTime)
{
elapsedSeconds = 0f;
}
Vector2 oldPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * lastTime))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * lastTime))));
Vector2 newPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds))));
//b.LinearVelocity = parent.GetComponent<Body>().LinearVelocity + (newPosition - oldPosition);
b.Position = newPosition;
}
}
示例7: Process
public override void Process(Entity e)
{
Health h = healthMapper.Get(e);
if (h == null)
return;
if (e.HasComponent<Origin>())
{
Origin o = e.GetComponent<Origin>();
Entity parent = o.Parent;
if (!parent.HasComponent<Body>() || !parent.GetComponent<Health>().IsAlive)
{
if (e.HasComponent<Health>())
e.GetComponent<Health>().SetHealth(e, 0);
else
e.Delete();
}
}
if (!h.IsAlive)
{
h.SetHealth(e, 0);
e.Delete();
}
}
示例8: Process
public override void Process(Entity e)
{
Damage d = e.GetComponent<Damage>();
Health h = e.GetComponent<Health>();
if (d.Seconds <= 0)
{
e.RemoveComponent<Damage>(d);
e.Refresh();
return;
}
d.Seconds -= (float)world.Delta / 1000;
h.SetHealth(e, h.CurrentHealth - d.DamagePerSecond * (world.Delta / 1000));
Sprite s = e.GetComponent<Sprite>();
Vector2 offset;
if (!e.Tag.Contains("Boss"))
{
double mes = Math.Sqrt(s.CurrentRectangle.Width * s.CurrentRectangle.Height / 4);
offset = new Vector2((float)((r.NextDouble() * 2 - 1) * mes), (float)((r.NextDouble() * 2 - 1) * mes));
}
else
{
offset = new Vector2((float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Width / 2), (float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Height / 2));
}
world.CreateEntity("GREENFAIRY", e, ConvertUnits.ToSimUnits(offset)).Refresh();
}
示例9: Process
// Updates the entities position based on it's velocity.
protected override void Process(Entity entity)
{
var vel = entity.GetComponent<VelocityComponent>();
var transform = entity.GetComponent<TransformComponent>();
transform.Position += vel.Velocity * entityWorld.DeltaTime.Milliseconds;
}
示例10: PlaceItem
private void PlaceItem(Entity actor, Entity item)
{
var rnd = new Random();
actor.SendMessage(this, ComponentMessageType.DropItemInCurrentHand);
item.GetComponent<SpriteComponent>(ComponentFamily.Renderable).drawDepth = DrawDepth.ItemsOnTables;
//TODO Unsafe, fix.
item.GetComponent<TransformComponent>(ComponentFamily.Transform).TranslateByOffset(
new Vector2f(rnd.Next(-28, 28), rnd.Next(-28, 15)));
}
示例11: Process
public override void Process(Entity e)
{
if (!e.HasComponent<Animation>())
return;
Sprite sprite = e.GetComponent<Sprite>();
Animation anim = e.GetComponent<Animation>();
if (anim.Type != AnimationType.None)
{
anim._Tick += world.Delta;
if (anim._Tick >= anim.FrameRate)
{
anim._Tick -= anim.FrameRate;
switch (anim.Type)
{
case AnimationType.Loop:
sprite.FrameIndex++; //Console.WriteLine("Animation happened");
break;
case AnimationType.ReverseLoop:
sprite.FrameIndex--;
break;
case AnimationType.Increment:
sprite.FrameIndex++;
anim.Type = AnimationType.None;
break;
case AnimationType.Decrement:
sprite.FrameIndex--;
anim.Type = AnimationType.None;
break;
case AnimationType.Bounce:
sprite.FrameIndex += anim.FrameInc;
if (sprite.FrameIndex == sprite.Source.Count() - 1)
anim.FrameInc = -1;
if (sprite.FrameIndex == 0)
anim.FrameInc = 1;
break;
case AnimationType.Once:
if (sprite.FrameIndex < sprite.Source.Count() - 1)
sprite.FrameIndex++;
else
anim.Type = AnimationType.None;
break;
}
e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
e.AddComponent<Sprite>(sprite);
}
}
}
示例12: OnCollision
protected override bool OnCollision(Entity Entity, EntityClassification Classification)
{
var sc = Entity.GetComponent<ScoreComponent>();
sc.Coins += Value;
var ftc = Entity.GetComponent<FloatingTextComponent>();
if (ftc != null)
ftc.Add("+" + Value.ToString(), Color.Gold);
AudioManager.PlaySoundEffect("CoinPickup");
Parent.Dispose();
return true;
}
示例13: SpecialSquareTo
private bool SpecialSquareTo(Entity mEntity, int mNextX, int mNextY, bool mNextSuccess, out bool mAbort)
{
mAbort = false;
if (mEntity.GetComponent<TDCWielder>() == null) return true;
if (!mNextSuccess) return true;
if (!TrySheateEntity(mEntity)) return true;
mEntity.GetComponent<TDCDirection>().Direction = TDCDirection.GetDirection(new TDVector2(mNextX, mNextY));
return true;
}
示例14: BuildEntity
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <param name="args">args[0] = Entity smasher, args[1] = Smasher loc</param>
/// <returns></returns>
public Entity BuildEntity(Entity e, params object[] args)
{
string spriteKey = "smasherball";
#region Body
Body bitch = e.AddComponent<Body>(new Body(_World, e));
FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch);
Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f);
e.AddComponent<Sprite>(s);
bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
bitch.OnCollision += LambdaComplex.BossCollision();
++bitch.Mass;
Entity smasher = (args[0] as Entity);
float dist = ConvertUnits.ToSimUnits(20f);
Vector2 pos = smasher.GetComponent<Body>().Position + new Vector2(0, dist);
bitch.Position = pos;
#endregion Body
#region Animation
if (s.Source.Count() > 1)
e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));
#endregion Animation
#region Health
e.AddComponent<Health>(new Health(1000000)).OnDeath +=
ent =>
{
Vector2 poss = e.GetComponent<ITransform>().Position;
_World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, e, e.GetComponent<IVelocity>().LinearVelocity);
int splodeSound = rbitch.Next(1, 5);
SoundManager.Play("Explosion" + splodeSound.ToString());
};
#endregion Health
e.AddComponent<Origin>(new Origin(smasher));
e.Group = "Enemies";
e.Tag = "SmasherBall";
return e;
}
示例15: BuildEntity
public Entity BuildEntity(Entity e, params object[] args)
{
e.Tag = "Player";
Rectangle source = (Rectangle)args[1];
FixtureFactory.AttachCircle(ConvertUnits.ToSimUnits(source.Height/2),1f,e.AddComponent<Body>(new Body(_World, e)));
e.GetComponent<Body>().BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
e.GetComponent<Body>().FixedRotation = true;
e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, source, new Vector2(30,16),1f,Color.White,0.1f)); //Sprite
return e;
}