protected void Awake() { animator = GetComponent<Animator>(); entity = GetComponentInParent<Entity>(); agent = entity.GetComponent<NavMeshAgent>(); movement = entity.GetComponent<EntityMovement>(); }
private void UpdateThrusters(Entity ship) { var shipComponent = ship.GetComponent<ShipComponent>(); var thrusters = shipComponent.Thrusters.Select(e => e.GetComponent<ThrusterComponent>()); var xform = ship.GetComponent<Transform>(); bool isShipTurning = Math.Abs(shipComponent.AngularTorque) > 0; var isShipThrusting = shipComponent.LinearThrustVector.LengthSquared() > 0; foreach (var thruster in thrusters) { if (thruster == null) continue; bool isThrusting = false; if (isShipThrusting) { var offset = Math.Abs(GetLesserAngleDifference(shipComponent.LinearThrustVector.GetAngleRadians() - MathHelper.Pi / 2f, thruster.Part.Transform.Rotation)); isThrusting = offset < 1; } if (isShipTurning) { var rotateDir = (AngularDirection)Math.Sign(shipComponent.AngularTorque); //isThrusting = rotateDir == thruster.RotateDir; isThrusting |= thruster.GetAngularThrustMult(rotateDir, Vector2.Zero) > 0; } thruster.IsThrusting = isThrusting; if (isThrusting) thruster.ThrustPercentage = MathHelper.Clamp(thruster.ThrustPercentage + 0.05f, 0, 1); else thruster.ThrustPercentage = MathHelper.Clamp(thruster.ThrustPercentage - 0.05f, 0, 1); } }
public Body ClosestTarget(Entity e) { AI a = e.GetComponent<AI>(); PhysicsBody pb = world.GetClosestBody(e.GetComponent<ITransform>().Position, a.HostileGroup); Body b = new Body(world, pb.UserData as Entity); return b; }
public void Attach(Entity newMaster) { master = newMaster; master.OnShutdown += master_OnShutdown; master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMasterMove; Translate(master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position); }
protected override void ProcessEntity(Engine engine, Entity entity) { // 2 per 1000 milliseconds var amountPerSecond = 2; var people = entity.GetComponent<PeopleComponent>().Value; entity.GetComponent<GoldComponent>().Value += (engine.DeltaMs * amountPerSecond / 1000.0) * people; }
public void Attach(int uid) { master = Owner.EntityManager.GetEntity(uid); master.OnShutdown += master_OnShutdown; master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMasterMove; Translate(master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position); }
public override void Process(Entity entity, float dt) { var physics = entity.GetComponent<PhysicsComponent>(); var render = entity.GetComponent<RenderComponent>(); render.RenderPosition = physics.Position; }
public override void Process(Entity e) { Moving moving = e.GetComponent<Moving>(); Transform spatial = e.GetComponent<Transform>(); spatial.Position += moving.Velocity * EntityWorld.Delta / 10000000; moving.Velocity += moving.Acceleration * EntityWorld.Delta / 10000000; }
public override void Process(Entity e) { Acting acting = e.GetComponent<Acting>(); if (acting.State != ActingState.SkillSelection) return; InputControlled inputControlled = e.GetComponent<InputControlled>(); if (String.IsNullOrEmpty(acting.SkillSelected.Name)) { inputControlled.SkillMenu.Draw(); } else { int count = acting.PossibleTargets.Count; if (count > 0) { if (inputControlled.IsTargetingGroup) { foreach (Entity entity in acting.PossibleTargets) { if (entity.GetComponent<Transform>() != null) { Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10); _spriteBatch.Draw(arrowTargeted, position, Color.White); } } } else { Entity TargetedEntity = acting.PossibleTargets[inputControlled.TargetIndex]; foreach (Entity entity in acting.PossibleTargets) { if (entity.GetComponent<Transform>() != null) { Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10); if (entity == TargetedEntity) { _spriteBatch.Draw(arrowTargeted, position, Color.White); } else { _spriteBatch.Draw(arrowCanBeTargeted, position, Color.White); } } } } } else { foreach (Entity entity in acting.Targets) { if (entity.GetComponent<Transform>() != null) { Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10); _spriteBatch.Draw(arrowTargeted, position, Color.White); } } } } }
public override void Process(Entity e) { if(e.GetComponent<Health>()!=null) e.GetComponent<Health>().AddDamage(10); if (e.GetComponent<Power2>() != null) e.GetComponent<Power2>().POWER -=10; }
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 Vector2(rnd.Next(-28, 28), rnd.Next(-28, 15))); }
public static void DamageTarget(Entity user, Entity target, int damage, double hitSuccess = 1) { EntityCreator.CreateDamageInfo(target, damage, hitSuccess); BattleStats stats = target.GetComponent<BattleStats>(); stats.Health.Decrease(damage); if (stats.IsDead && !target.GetComponent<Group>().IsHero) { target.Delete(); } }
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args) { e.Group = "EFFECTS"; e.AddComponentFromPool<Transform>(); e.AddComponent(new SpatialForm()); e.AddComponent(new Expires()); e.GetComponent<SpatialForm>().SpatialFormFile = "ShipExplosion"; e.GetComponent<Expires>().LifeTime = 1000; return e; }
public Entity BuildEntity(Entity e) { e.Group = "EFFECTS"; e.AddComponent(new Transform()); e.AddComponent(new SpatialForm()); e.AddComponent(new Expires()); e.GetComponent<SpatialForm>().SpatialFormFile = "BulletExplosion"; e.GetComponent<Expires>().LifeTime = 1000; return e; }
public override void Process (Entity entity) { var transform = entity.GetComponent<Transform>(); var renderer = entity.GetComponent<Texture2DRenderer>(); var spriteBatch = BlackBoard.GetEntry<SpriteBatch>("SpriteBatch"); var texture = BlackBoard.GetEntry<ContentManager>("ContentManager").Load<Texture2D>(renderer.TextureName); spriteBatch.Draw(texture, transform.renderPosition, null, null, transform.globalOrigin, transform.renderRotation, transform.renderScale); }
public Entity BuildEntity(Entity e) { e.Group = "BULLETS"; e.AddComponent(new Transform()); e.AddComponent(new SpatialForm()); e.AddComponent(new Velocity()); e.AddComponent(new Expires()); e.GetComponent<SpatialForm>().SpatialFormFile = "Missile"; e.GetComponent<Expires>().LifeTime = 2000; return e; }
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args) { e.Group = "BULLETS"; e.AddComponentFromPool<Transform>(); e.AddComponent(new SpatialForm()); e.AddComponent(new Velocity()); e.AddComponent(new Expires()); e.GetComponent<SpatialForm>().SpatialFormFile = "Missile"; e.GetComponent<Expires>().LifeTime = 2000; return e; }
public override void Process(Entity e) { Sprite sprite = e.GetComponent<Sprite>(); Animation anim = e.GetComponent<Animation>(); if (anim.Type != AnimationType.None) { anim._Tick++; anim._Tick %= anim.FrameRate; if (anim._Tick == 0) //If time to animate. { switch (anim.Type) { case AnimationType.Loop: sprite.FrameIndex++; 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); } } }
public Entity BuildEntity(Entity e) { e.Group = "SHIPS"; e.AddComponent(new Transform()); e.AddComponent(new SpatialForm()); e.AddComponent(new Health()); e.AddComponent(new Weapon()); e.AddComponent(new Enemy()); e.AddComponent(new Velocity()); e.GetComponent<SpatialForm>().SpatialFormFile = "EnemyShip"; e.GetComponent<Health>().HP = 10; return e; }
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args) { e.Group = "SHIPS"; e.AddComponentFromPool<Transform>(); e.AddComponent(new SpatialForm()); e.AddComponent(new Health()); e.AddComponent(new Weapon()); e.AddComponent(new Enemy()); e.AddComponent(new Velocity()); e.GetComponent<SpatialForm>().SpatialFormFile = "EnemyShip"; e.GetComponent<Health>().HP = 10; return e; }
public virtual Entity Install(EntityWorld world, Entity shipEntity, Entity hardpointEntity) { var slot = hardpointEntity.GetComponent<HardpointComponent>(); if (!hardpointEntity.IsChildOf(shipEntity)) throw new InvalidOperationException("Cannot install, ship entity does not own hardpoint entity."); if (slot == null) throw new InvalidOperationException("Cannot install on non-hardpoint entity."); var shipComponent = shipEntity.GetComponent<ShipComponent>(); var moduleEntity = world.CreateEntity(); var hardpointTransform = hardpointEntity.GetComponent<Transform>(); var moduleTransform = moduleEntity.AddComponentFromPool<Transform>(); moduleTransform.Position = Vector2.Zero; moduleTransform.Rotation = 0; moduleTransform.Scale = Vector2.One; moduleTransform.Origin = -hardpointTransform.Origin; var scale = hardpointTransform.Scale; var origin = -hardpointTransform.Origin; if (scale.X < 0) { scale.X = Math.Abs(scale.X); origin.X *= -1; } if (scale.Y < 0) { scale.Y *= Math.Abs(scale.Y); origin.Y *= -1; } moduleTransform.Scale = scale; moduleTransform.Origin = origin; hardpointEntity.AddChild(moduleEntity); var previousInstalled = slot.InstalledEntity; if (previousInstalled != null) { previousInstalled.GetComponent<ModuleComponent>().Module.Uninstall(shipEntity, previousInstalled); } if (!string.IsNullOrWhiteSpace(PartGroupId)) { ShipEntityFactory.GetShipModel(PartGroupId).CreateChildEntities(world, moduleEntity); } var moduleComponent = new ModuleComponent { HardpointEntity = hardpointEntity, Module = this }; slot.InstalledEntity = moduleEntity; moduleEntity.AddComponent(moduleComponent); return moduleEntity; }
private void GasEffect(Entity entity, float frameTime) { var transform = entity.GetComponent<TransformComponent>(ComponentFamily.Transform); var physics = entity.GetComponent<PhysicsComponent>(ComponentFamily.Physics); ITile t = IoCManager.Resolve<IMapManager>().GetFloorAt(transform.Position); if (t == null) return; var gasVel = t.GasCell.GasVelocity; if (gasVel.Abs() > physics.Mass) // Stop tiny wobbles { transform.Position = new Vector2(transform.X + (gasVel.X * frameTime), transform.Y + (gasVel.Y * frameTime)); } }
public override void Process(Entity entity, float dt) { var render = entity.GetComponent<RenderComponent>(); var animation = entity.GetComponent<AnimationComponent>(); var input = entity.GetComponent<InputComponent>(); string animationId = _animationMapper.GetAnimationId(input); SetRunningAnimation(animation, animationId); if (!string.IsNullOrEmpty(animation.CurrentAnimationId)){ UpdateAnimation(dt, animation); render.SourceRectangle = animation.Animations[animation.CurrentAnimationId].SourceRectangle; } }
public override void DestroyEntity(Entity entity) { var debugComponent = (DebugComponent)entity.GetComponent(_debugIndex); debugComponent.debugBehaviour.DestroyBehaviour(); base.DestroyEntity(entity); updateName(); }
public override void Execute(Entity context) { CharacterController controller = context.GetComponent<CharacterController>(); transform = controller.transform; //transform = context.transform; direction = context.GetMedrashPosition() - transform.position; direction.y = 0.0f; tangent.x = clockwise*direction.z; tangent.z = -clockwise*direction.x; tangent.y = 0.0f; if (context.DistanceToMainCharacter() > context.GetCloseRadius()) direction = tangent + 0.01f*(direction.magnitude - context.GetFarRadius()) * direction; else direction = tangent + 0.1f*(direction.magnitude - context.GetFarRadius()) * direction; RaycastHit hitInfo; if (Physics.Raycast(transform.position + controller.center, direction, out hitInfo, 3.0f)) { clockwise *= -1; direction *= -1; } context.SetDirection(direction); context.SetRunAnimation(); }
public static void DeleteLocalString(Entity entity, string key) { if (!entity.HasComponent<LocalData>()) return; LocalData data = entity.GetComponent<LocalData>(); if (data.LocalStrings.ContainsKey(key)) data.LocalStrings.Remove(key); }
public override void Process(Entity e) { if (!e.HasComponent<FadingText>()) return; e.GetComponent<FadingText>().Draw(spriteBatch, spriteFont); }
public Entity BuildEntity(Entity et1, EntityWorld world , params object[] args) { et1.AddComponent(new Power()); et1.GetComponent<Power>().POWER = 100; et1.Refresh(); return et1; }
private GameObject CreateGameObject(Entity entity) { if (entity.GetComponent<CardType>() != null) { return Factory.Cards.MakeCard("", entity.GetComponent<Position>().position); } else if (entity.GetComponent<SystemType>() != null) { return Factory.Systems.MakeSystem (entity.GetComponent<SystemType>().info.tile.X, entity.GetComponent<SystemType>().info.tile.Y); } else { return null; } }
public override void Process(Entity e) { Health health = healthMapper.Get(e); Body body = bodyMapper.Get(e); int X = (int)ScreenHelper.Center.X; int Y = (int)ScreenHelper.Center.Y; if (e.Tag.Contains("Boss") || e.Group == "Base") { Sprite s = e.GetComponent<Sprite>(); float Width = s.CurrentRectangle.Width; float Height = s.CurrentRectangle.Height + 7; int posX = X + (int)ConvertUnits.ToDisplayUnits(body.Position.X) - (int)s.CurrentRectangle.Width / 2; int posY = Y + (int)ConvertUnits.ToDisplayUnits(body.Position).Y - (int)Height / 2; //Draw backing _SpriteBatch.Draw(_BarTexture, new Rectangle( posX, posY, (int)Width, 2), Color.DarkRed); _SpriteBatch.Draw(_BarTexture, new Rectangle( posX, posY, (int)((health.CurrentHealth / health.MaxHealth) * Width), 2), Color.Red); } }