Inheritance: MonoBehaviour
        public override void Process(Entity entity)
        {
            FSMComponent             fsm             = entity.GetComponent <FSMComponent>();
            InputIntentComponent     inputIntent     = entity.GetComponent <InputIntentComponent>();
            BinaryDirectionComponent binaryDirection = entity.GetComponent <BinaryDirectionComponent>();

            if (inputIntent.Up)
            {
                LinkOnGroundStateComponent onGround = entity.GetComponent <LinkOnGroundStateComponent>();
                SpeedComponent             speed    = entity.GetComponent <SpeedComponent>();
                speed.SpeedY = -onGround.JumpForce;
                fsm.SetState(entity, "onAir");
                return;
            }
            if (inputIntent.Left ^ inputIntent.Right)
            {
                if (inputIntent.Left)
                {
                    binaryDirection.Direction = BinaryDirection.Left;
                }
                if (inputIntent.Right)
                {
                    binaryDirection.Direction = BinaryDirection.Right;
                }

                if (inputIntent.Run)
                {
                    fsm.SetState(entity, "run");
                    return;
                }
                fsm.SetState(entity, "walk");
                return;
            }
            fsm.SetState(entity, "idle");
        }
Ejemplo n.º 2
0
        public static Entity CreatePrincepsEntity(int currentTick, int formationNumber, Unit unit, FactionName faction,
                                                  int numPilas = 1, int startingMorale = 65)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Princeps");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            // Princeps AI is essentially the same as Hastatus AI
            e.AddComponent(new HastatusAIComponent(numPilas));
            e.AddComponent(AIRotationComponent.Create(.60, false));
            e.AddComponent(AIMoraleComponent.Create(100, startingMorale));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 6, meleeAttack: 55, rangedAttack: 30));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 2, maxHp: 65, maxFooting: 100, meleeDefense: 15, rangedDefense: 30));
            e.AddComponent(DisplayComponent.Create(_texPrincepsPath, "An experienced swordsman with good equipment.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 3
0
 public MoveAbleEntity() : base()
 {
     speed = new SpeedComponent()
     {
         entity = this
     };
 }
Ejemplo n.º 4
0
        public static Entity CreateTriariusEntity(int currentTick, int formationNumber, Unit unit, FactionName faction,
                                                  int startingMorale = 85)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Triarius");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            // TODO: different AI
            e.AddComponent(new HastatusAIComponent(0));
            e.AddComponent(AIRotationComponent.Create(.60, false));
            e.AddComponent(AIMoraleComponent.Create(100, startingMorale));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 8, meleeAttack: 70, rangedAttack: 30));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 3, maxHp: 85, maxFooting: 120, meleeDefense: 30, rangedDefense: 45));
            e.AddComponent(DisplayComponent.Create(_texTriariusPath, "An elite spearman of the legion.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 5
0
        // Create all the components that should be used by this game
        private void CreateComponents()
        {
            _menuComponent = new MenuComponent(this);
            Components.Add(_menuComponent);

            _backgroundComponent = new BackgroundComponent(this);
            Components.Add(_backgroundComponent);

            _actorComponent = new ActorComponent(this);
            Components.Add(_actorComponent);

            _collisionComponent = new CollisionComponent(this);
            Components.Add(_collisionComponent);

            _scoreComponent = new ScoreComponent(this);
            Components.Add(_scoreComponent);

            _timeComponent = new TimeComponent(this);
            Components.Add(_timeComponent);

            _speedComponent = new SpeedComponent(this);
            Components.Add(_speedComponent);

            _statusComponent = new StatusComponent(this);
            Components.Add(_statusComponent);
        }
Ejemplo n.º 6
0
    void Update()
    {
        //
        // get all the objects that have Player and Input component
        //
        List <GameObject> goComps = ObjectTracker.Find <OpponentsComponent>();

        foreach (GameObject goInput in goComps)
        {
            if (gameOver)
            {
                return;
            }

            SpeedComponent speed = goInput.GetComponent <SpeedComponent>();
            if (speed == null)
            {
                continue;
            }

            //input.xAxis = player.speed * Input.GetAxis(input.HorizontalInput);
            //input.shoot = Input.GetButton(input.ShootInput);
            //
            // move the player vertically
            //
            Vector3 now = goInput.transform.position;
            goInput.transform.position = new Vector3(now.x, now.y + speed.speed, now.z);
            //
            // find out if player has crossed the finish line
            //
            EventManager.TriggerEvent("FinishLineEvent", goInput.name);
        }
    }
Ejemplo n.º 7
0
        public static Entity CreatePlayerEntity(int currentTick)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "You");

            // TODO: modify PlayerAIComponent to it doesn't, you know...need these.
            e.AddComponent(new PlayerAIComponent());
            e.AddComponent(AIRotationComponent.Create(.60, true));
            e.AddComponent(AIMoraleComponent.Create(100, 100));

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, power: 8, meleeAttack: 55, rangedAttack: 10)); // TODO: make player not Ares
            e.AddComponent(CollisionComponent.Create(blocksMovement: true, blocksVision: false));
            e.AddComponent(DefenderComponent.Create(baseDefense: 0, maxHp: 70, maxFooting: 95, meleeDefense: 30, rangedDefense: 60, isInvincible: false));
            e.AddComponent(DisplayComponent.Create(_texPlayerPath, "It's you!", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(FactionName.PLAYER));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.PLAYER_DEFEAT
            }));
            e.AddComponent(PlayerComponent.Create(isInFormation: true));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(XPTrackerComponent.Create(levelUpBase: 200, levelUpFactor: 150));

            return(e);
        }
Ejemplo n.º 8
0
        public static Entity CreatePunicHeavyInfantry(int currentTick, int formationNumber, Unit unit, FactionName faction)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Punic Heavy Infantry");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            // TODO: one day I'll have different AIs
            e.AddComponent(new IberianLightInfantryAIComponent());
            e.AddComponent(AIRotationComponent.Create(.4, false));
            e.AddComponent(AIMoraleComponent.Create(100, 90));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 11, meleeAttack: 55, rangedAttack: 10));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 4, maxHp: 80, maxFooting: 140, meleeDefense: 40, rangedDefense: 45));
            e.AddComponent(DisplayComponent.Create(_texPunicHeavyInfantryPath, "Carthage's very best heavy infantry.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 9
0
 void Awake()
 {
     _rigidbody2D    = GetComponent <Rigidbody2D>();
     _speedComponent = GetComponent <SpeedComponent>();
     //_animator = GetComponent<Animator>();
     _y = transform.position.y - _fallDistance;
 }
Ejemplo n.º 10
0
        public void IncludesEntityGroup()
        {
            var         component    = SpeedComponent.Create(0);
            JsonElement deserialized = JsonSerializer.Deserialize <JsonElement>(component.Save());

            Assert.Equal(SpeedComponent.ENTITY_GROUP, deserialized.GetProperty("EntityGroup").GetString());
        }
Ejemplo n.º 11
0
        public static Entity CreateHastatusEntity(int currentTick, int formationNumber, Unit unit, FactionName faction,
                                                  int numPilas = 1, int startingMorale = 45)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Hastatus");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            e.AddComponent(new HastatusAIComponent(numPilas));
            e.AddComponent(AIRotationComponent.Create(.60, false));
            e.AddComponent(AIMoraleComponent.Create(100, startingMorale));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 5, meleeAttack: 50, rangedAttack: 30));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 2, maxHp: 45, maxFooting: 80, meleeDefense: 10, rangedDefense: 25));
            e.AddComponent(DisplayComponent.Create(_texHastatusPath, "A young and eager soldier.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 12
0
 public CircleState(ColorComponent color, PositionComponent pos, SizeComponent size, SpeedComponent speed)
 {
     colorComponent    = color;
     positionComponent = pos;
     sizeComponent     = size;
     speedComponent    = speed;
 }
Ejemplo n.º 13
0
        public static Entity CreateGallicVeteranInfantry(int currentTick, int formationNumber, Unit unit, FactionName faction)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Gallic Veteran Infantry");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            // TODO: one day I'll have different AIs
            e.AddComponent(new IberianLightInfantryAIComponent());
            e.AddComponent(AIRotationComponent.Create(.4, false));
            e.AddComponent(AIMoraleComponent.Create(100, 90));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 9, meleeAttack: 50, rangedAttack: 10));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 2, maxHp: 55, maxFooting: 110, meleeDefense: 30, rangedDefense: 45));
            e.AddComponent(DisplayComponent.Create(_texGallicVeteranInfantryPath, "An armored Gallic veteran. Fights defensively, but hits hard.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 14
0
        public static Entity CreateIberianLightInfantry(int currentTick, int formationNumber, Unit unit, FactionName faction)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Iberian Light Infantry");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            e.AddComponent(new IberianLightInfantryAIComponent());
            e.AddComponent(AIRotationComponent.Create(.7, false));
            e.AddComponent(AIMoraleComponent.Create(100, 90));

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(AttackerComponent.Create(e.EntityId, 5, meleeAttack: 55, rangedAttack: 10));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(baseDefense: 1, maxHp: 40, maxFooting: 75, meleeDefense: 15, rangedDefense: 5));
            e.AddComponent(DisplayComponent.Create(_texIberianLightInfantryPath, "A fast, deatly, and barely armored Iberian swordsman.", false, ENTITY_Z_INDEX));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(OnDeathComponent.Create(new List <string>()
            {
                OnDeathEffectType.REMOVE_FROM_UNIT
            }));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 80));
            e.AddComponent(statusEffectTrackerComponent);
            e.AddComponent(UnitComponent.Create(unit.UnitId, formationNumber));
            e.AddComponent(XPValueComponent.Create(xpValue: 30));

            return(e);
        }
Ejemplo n.º 15
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            var data = new SpeedComponent {
                Value = MoveSpeed
            };

            dstManager.AddComponentData(entity, data);
        }
Ejemplo n.º 16
0
 void OnTriggerExit2D(Collider2D collider)
 {
     if (collider.gameObject.TryGetComponent(typeof(SpeedComponent), out var component))
     {
         SpeedComponent speedComponent = (SpeedComponent)component;
         speedComponent.TimeScale += TimeScaleDecrease;
     }
 }
Ejemplo n.º 17
0
 protected override void Excute(SimpleEntity entity)
 {
     SpeedComponent sp = entity.GetComponent<SpeedComponent>();
     RotaComponet rc = entity.GetComponent<RotaComponet>();
     rc.go.transform.Rotate(UnityEngine.Vector3.forward,sp.speed);
     sp.speed += 0.01f;
     entity.ReFreshComponent(sp);
 }
Ejemplo n.º 18
0
        public override void Process(Entity entity)
        {
            float             dt       = (float)EntitySystem.BlackBoard.GetEntry <double>("dt");
            PositionComponent position = entity.GetComponent <PositionComponent>();
            SpeedComponent    speed    = entity.GetComponent <SpeedComponent>();

            speed.PreviousPosition = position.Position;
            position.Position     += speed.Speed * dt;
        }
Ejemplo n.º 19
0
        public void SerializesAndDeserializesCorrectly()
        {
            var    component = SpeedComponent.Create(64);
            string saved     = component.Save();

            var newComponent = SpeedComponent.Create(saved);

            Assert.Equal(component.BaseSpeed, newComponent.BaseSpeed);
        }
Ejemplo n.º 20
0
        public override void Process(Entity entity)
        {
            float dt = (float)EntitySystem.BlackBoard.GetEntry <double>("dt");
            GoalSpeedComponent goalSpeed = entity.GetComponent <GoalSpeedComponent>();
            SpeedComponent     speed     = entity.GetComponent <SpeedComponent>();

            speed.SpeedX = Approach(speed.SpeedX, Math.Abs(goalSpeed.AccelX * dt), goalSpeed.GoalSpeedX);
            speed.SpeedY = Approach(speed.SpeedY, Math.Abs(goalSpeed.AccelY * dt), goalSpeed.GoalSpeedY);
        }
        public override void OnAdded(Entity entity)
        {
            base.OnAdded(entity);
            SpeedComponent       speed       = entity.GetComponent <SpeedComponent>();
            EventSenderComponent eventSender = entity.GetComponent <EventSenderComponent>();

            speed.SpeedY              = 0;
            eventSender.GenericEvent += Event;
        }
Ejemplo n.º 22
0
 public EnemyCreature(GameObject _go, Vector2 _position, EnemyProperties _properties) : base(_go, _position)
 {
     properties = _properties;
     Health     = new HealthComponent(this, properties.enemyTroopHealth * UnityEngine.Random.Range(0.9f, 1.1f),
                                      // (1f - properties.enemyTroopHealthVariation, 1f + properties.enemyTroopHealthVariation,)
                                      GameObject.GetComponentInChildren <BloodParticles>());
     Attack = new AttackComponent(properties.enemyDamage * UnityEngine.Random.Range(0.9f, 1.1f),
                                  // (1f - properties.enemyDamageVariation, 1f + properties.enemyDamageeVariation,)
                                  properties.enemyRange, properties.enemyCooldown, animation);
     Speed = new SpeedComponent(properties.enemySpeed * UnityEngine.Random.Range(0.9f, 1.1f), navAgent);
 }
Ejemplo n.º 23
0
        public override void OnAdded(Entity entity)
        {
            base.OnAdded(entity);
            LinkOnAirStateComponent onAir       = entity.GetComponent <LinkOnAirStateComponent>();
            SpeedComponent          speed       = entity.GetComponent <SpeedComponent>();
            GoalSpeedComponent      goalSpeed   = entity.GetComponent <GoalSpeedComponent>();
            EventSenderComponent    eventSender = entity.GetComponent <EventSenderComponent>();

            goalSpeed.GoalSpeedY = onAir.MaxVerticalSpeed;
            goalSpeed.AccelY     = onAir.Gravity;
            goalSpeed.GoalSpeedX = speed.Speed.X;

            eventSender.GenericEvent += Event;
        }
Ejemplo n.º 24
0
    private float lastSpacePressTime = 0f;//on ne peut pas appuyer sur espace pendant les deux premières secondes

    public void UpdateSystem()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (Time.time - lastSpacePressTime < 2f)
            {
                string timeRemaining = (2f - (Time.time - lastSpacePressTime)).ToString();
                Debug.Log("Wait until the cooldown is over; time remaining in seconds : " + timeRemaining);
            }

            else
            {
                lastSpacePressTime = Time.time;
                Debug.Log("Space button pressed; activating 2 seconds cooldown");

                for (int i = 0; i < world.PastPositionsComponents.Count; i++)
                {
                    PositionComponent posC   = new PositionComponent();
                    ColorComponent    colorC = new ColorComponent();
                    SizeComponent     sizeC  = new SizeComponent();
                    SpeedComponent    speedC = new SpeedComponent();

                    posC.id   = world.PositionComponents[i].id;
                    colorC.id = world.ColorComponents[i].id;
                    sizeC.id  = world.SizeComponents[i].id;
                    speedC.id = world.SpeedComponents[i].id;

                    posC.pos = world.PastPositionsComponents[i].pos.Dequeue();
                    world.PositionComponents[i] = posC;
                    world.PastPositionsComponents[i].timestamps.Dequeue();
                    manager.UpdateShapePosition(world.PositionComponents[i].id, world.PositionComponents[i].pos);

                    colorC.color             = world.PastColorsComponents[i].colors.Dequeue();
                    world.ColorComponents[i] = colorC;
                    world.PastColorsComponents[i].timestamps.Dequeue();
                    manager.UpdateShapeColor(world.ColorComponents[i].id, world.ColorComponents[i].color);

                    sizeC.size = world.PastSizesComponents[i].sizes.Dequeue();
                    world.SizeComponents[i] = sizeC;
                    world.PastSizesComponents[i].timestamps.Dequeue();
                    manager.UpdateShapeSize(world.SizeComponents[i].id, world.SizeComponents[i].size);

                    speedC.speed             = world.PastSpeedsComponents[i].speeds.Dequeue();
                    world.SpeedComponents[i] = speedC;
                    world.PastSpeedsComponents[i].timestamps.Dequeue();
                }
            }
        }
    }
Ejemplo n.º 25
0
        public static Entity CreateProjectileEntity(Entity source, ProjectileType type, int power, EncounterPath path, int speed, int currentTick)
        {
            var displayData = projectileTypeToProjectileDisplay[type];

            var e = CreateEntity(Guid.NewGuid().ToString(), displayData.Name);

            e.AddComponent(PathAIComponent.Create(path));

            e.AddComponent(ActionTimeComponent.Create(currentTick)); // Should it go instantly or should it wait for its turn...?
            e.AddComponent(AttackerComponent.Create(source.EntityId, power));
            e.AddComponent(CollisionComponent.Create(false, false, true, true));
            e.AddComponent(DisplayComponent.Create(displayData.TexturePath, "A projectile.", false, PROJECTILE_Z_INDEX));
            e.AddComponent(SpeedComponent.Create(speed));

            return(e);
        }
Ejemplo n.º 26
0
 public PlayerTroop(GameObject _go, int _index, Vector2 _position, PlayerProperties properties) : base(_go, _position)
 {
     Index      = _index;
     IsInfected = false;
     IsDead     = false;
     Health     = new HealthComponent(this, properties.playerTroopHealth * UnityEngine.Random.Range(0.9f, 1.1f),
                                      // (1f - properties.playerTroopVariation, 1f + properties.playerTroopVariation,)
                                      GameObject.GetComponentInChildren <BloodParticles>(),
                                      GameObject.GetComponentInChildren <HealthBar>());
     Attack = new AttackComponent(properties.playerDamage * UnityEngine.Random.Range(0.9f, 1.1f),
                                  // (1f - properties.playerDamageVariation, 1f + properties.playerDamageVariation,)
                                  properties.playerRange, properties.playerCooldown, animation);
     Speed = new SpeedComponent(properties.playerSpeed * UnityEngine.Random.Range(0.9f, 1.1f), navAgent);
     animation.Init(this);
     animation.SetMoveTarget(Position);
 }
Ejemplo n.º 27
0
        public override void Update(GameTime gameTime)
        {
            List <Entity> movables = world.GetEntities(new[] { typeof(SpeedComponent), typeof(PositionComponent) });

            foreach (Entity moveable in movables)
            {
                PositionComponent pc = (PositionComponent)moveable.components[typeof(PositionComponent)];
                SpeedComponent    rc = (SpeedComponent)moveable.components[typeof(SpeedComponent)];
                pc.position = pc.position + rc.motion;

                if (moveable.HasComponent(typeof(PlayerComponent)))
                {
                    RenderComponent renderComp = (RenderComponent)moveable.components[typeof(RenderComponent)];
                    if (pc.position.X < 0)
                    {
                        pc.position.X = 0;
                    }
                    if (pc.position.Y < 0)
                    {
                        pc.position.Y = 0;
                    }
                    if (pc.position.X > world.screenRect.Width - renderComp.CurrentTexture.Width)
                    {
                        pc.position.X = world.screenRect.Width - renderComp.CurrentTexture.Width;
                    }
                    if (pc.position.Y > world.screenRect.Height - renderComp.CurrentTexture.Height)
                    {
                        pc.position.Y = world.screenRect.Height - renderComp.CurrentTexture.Height;
                    }
                }

                if (moveable.HasComponent(typeof(LaserComponent)))
                {
                    //Despawn lasers shortly after they leave the screen
                    if (pc.position.Y < 0 || pc.position.Y > world.screenRect.Height || pc.position.X < 0 || pc.position.X > world.screenRect.Width)
                    {
                        world.RemoveEntity(moveable);
                    }
                }

                //Despawn anything going off the bottom of the screen
                if (pc.position.Y > world.screenRect.Height)
                {
                    world.RemoveEntity(moveable);
                }
            }
        }
Ejemplo n.º 28
0
    private static void SpawnEntity(uint entityId, Vector2 speed, Config.ShapeConfig entityConfig, bool isStatic)
    {
        ECSManager.Instance.CreateShape(entityId, entityConfig);
        ComponentsManager.Instance.SetComponent <ColliderComponent>(entityId, new ColliderComponent());
        ComponentsManager.Instance.SetComponent <PositionComponent>(entityId, new PositionComponent(entityConfig.initialPos));
        ComponentsManager.Instance.SetComponent <SizeComponent>(entityId, new SizeComponent(entityConfig.size));
        ComponentsManager.Instance.SetComponent <EntityComponent>(entityId, new EntityComponent(entityId));

        if (!isStatic)
        {
            SpeedComponent speedData = new SpeedComponent
            {
                speed = speed
            };
            ComponentsManager.Instance.SetComponent <SpeedComponent>(entityId, speedData);
        }
    }
 private void Event(Entity entity, Type eventType, EventArgs pe)
 {
     if (eventType == typeof(MapCollisionEventType))
     {
         MapCollisionEventType e = (MapCollisionEventType)pe;
         if (!e.Type.HasFlag(MapCollisionType.Down))
         {
             FSMComponent fsm = entity.GetComponent <FSMComponent>();
             fsm.SetState(entity, "onAir");
         }
         else
         {
             SpeedComponent speed = entity.GetComponent <SpeedComponent>();
             speed.SpeedY = 0;
         }
     }
 }
Ejemplo n.º 30
0
        public static Entity CreateCommanderEntity(int currentTick, FactionName faction)
        {
            var e = CreateEntity(Guid.NewGuid().ToString(), "Hidden Commander Unit");

            var statusEffectTrackerComponent = StatusEffectTrackerComponent.Create();

            e.AddComponent(new CommanderAIComponent());

            e.AddComponent(ActionTimeComponent.Create(currentTick));
            e.AddComponent(CollisionComponent.CreateDefaultActor());
            e.AddComponent(DefenderComponent.Create(9999, 9999, 9999, 9999, 9999, isInvincible: true));
            e.AddComponent(DisplayComponent.Create(_texTriariusPath, "Hidden Commander Unit", false, ENTITY_Z_INDEX, visible: false));
            e.AddComponent(FactionComponent.Create(faction));
            e.AddComponent(SpeedComponent.Create(baseSpeed: 100));
            e.AddComponent(XPValueComponent.Create(xpValue: 9999));

            return(e);
        }