示例#1
0
 public static void SetColorPaletteCustom(Entity entity, int red, int green, int blue, int alpha)
 {
     if (entity.HasComponent<Sprite>())
     {
         entity.GetComponent<Sprite>().SetColorOverride(red, green, blue, alpha);
     }
 }
示例#2
0
        public override void Process(Entity entity)
        {
            Entity player = (Entity)BlackBoard.GetEntry("Player");
            CollisionBox playerBox = player.GetComponent<CollisionBox>();
            Position playerPosition = player.GetComponent<Position>();
            Rectangle playerRectangle = new Rectangle(
                (int)playerPosition.X + playerBox.OffsetX,
                (int)playerPosition.Y + playerBox.OffsetY,
                playerBox.Width,
                playerBox.Height);

            CollisionBox enemyBox = entity.GetComponent<CollisionBox>();
            Position enemyPosition = entity.GetComponent<Position>();
            Rectangle enemyRectangle = new Rectangle(
                (int)enemyPosition.X + enemyBox.OffsetX,
                (int)enemyPosition.Y + enemyBox.OffsetY,
                enemyBox.Width,
                enemyBox.Height);

            var type = playerRectangle.GetCollisionType(enemyRectangle);

            if (type == CollisionType.None || !entity.HasComponent<Script>()) return;
            Script script = entity.GetComponent<Script>();
            _scriptManager.QueueScript(script.FilePath, entity, "OnTouch");
        }
示例#3
0
 public static void ResetColorPalette(Entity entity)
 {
     if (entity.HasComponent<Sprite>())
     {
         entity.GetComponent<Sprite>().RemoveColorOverride();
     }
 }
示例#4
0
 /// <summary>
 /// Copy all fields from another instance to the current one. 
 /// (e.g. for re-use of object, avoiding new object creation)
 /// </summary>
 public void CopyFrom(BTAIContext other)
 {
     SimTime = other.SimTime;
     BTComp = other.BTComp;
     Dt = other.Dt;
     Entity = other.Entity;
 }
示例#5
0
        public override void Process(Entity entity)
        {
            Map map = entity.GetComponent<Map>();
            Vector2 origin = new Vector2(0, 0);

            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Height; y++)
                {
                    TileData tile = map.Tiles[x, y];
                    if (tile == null) continue;

                    Vector2 position = new Vector2(
                        x * TilesetConstants.TileWidth,
                        y * TilesetConstants.TileHeight);
                    Rectangle source = new Rectangle(
                        tile.X,
                        tile.Y,
                        tile.X * TilesetConstants.TileWidth + TilesetConstants.TileWidth,
                        tile.Y * TilesetConstants.TileHeight + TilesetConstants.TileHeight);
                    _spriteBatch.Draw(map.Spritesheet,   // Texture
                        position,                        // Position
                        source,                          // Source
                        Color.White,                     // Color
                        0.0f,                            // Rotation
                        origin,                          // Origin
                        1.0f,                            // Scale
                        SpriteEffects.None,              // SpriteEffects
                        0.0f);                           // Layer Depth
                }
            }
        }
示例#6
0
        public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
        {
            e.AddComponent(new Position());

            e.Refresh();

            return e;
        }
 public override void OnAdded(Entity e)
 {
     ColoredText ColoredText = e.GetComponent<ColoredText>();
     Transform spatial = e.GetComponent<Transform>();
     spatial.Width = (int)_font.MeasureString(ColoredText.Text).X;
     spatial.Height = (int)_font.MeasureString(ColoredText.Text).Y;
     spatial.Center = new Point((int)spatial.Position.X, (int)spatial.Position.Y);
 }
示例#8
0
        public override void Process(Entity entity)
        {
            Position position = entity.GetComponent<Position>();
            Velocity velocity = entity.GetComponent<Velocity>();

            velocity.Y += WorldConstants.Gravity;
            if (velocity.Y > WorldConstants.Gravity) velocity.Y = WorldConstants.Gravity;
        }
示例#9
0
 public static void SetColorPalette(Entity entity, ColorType color)
 {
     if (entity.HasComponent<Sprite>())
     {
         ColorTypeAttribute attr = color.GetAttributeOfType<ColorTypeAttribute>();
         entity.GetComponent<Sprite>().SetColorOverride(attr.Red, attr.Green, attr.Blue, attr.Alpha);
     }
 }
示例#10
0
        public override void Process(Entity entity)
        {
            Position position = entity.GetComponent<Position>();
            Velocity velocity = entity.GetComponent<Velocity>();

            position.X += velocity.X;
            position.Y += velocity.Y;
        }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entity world.</param>
        /// <param name="args">The args.</param>
        /// <returns>The built <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.AddComponent(new TestPowerComponent());
            entity.GetComponent<TestPowerComponent>().Power = 100;

            entity.Refresh();

            return entity;
        }
示例#12
0
 public override void OnRemoved(Entity e)
 {
     Effect effect = e.GetComponent<Effect>();
     BattleStats stats = effect.Owner.GetComponent<BattleStats>();
     if (stats != null)
     {
         stats.RemoveEffect(effect.Type, effect.Amount);
     }
 }
示例#13
0
 public override void Process(Entity e)
 {
     Expires expires = e.GetComponent<Expires>();
     expires.LifeTime -= EntityWorld.Delta / 10000000.0;
     if (expires.LifeTime <= 0)
     {
         e.Delete();
     }
 }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entityWorld.</param>
        /// <param name="args">The args.</param>
        /// <returns>The <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.Group = "EFFECTS";

            entity.AddComponentFromPool<TransformComponent>();
            entity.AddComponent(new SpatialFormComponent("BulletExplosion"));
            entity.AddComponent(new ExpiresComponent(1000));

            return entity;
        }
示例#15
0
 public void CreateCounterInfo(Entity target)
 {
     Entity entity = _world.CreateEntity();
     Point position = target.GetComponent<Transform>().Center;
     position.Y -= 20;
     entity.AddComponent(new Transform(position));
     entity.AddComponent(new Moving(new Vector2(0, -75)));
     entity.AddComponent(new ColoredText("Contré", Color.Yellow));
     entity.AddComponent(new Expires(1));
     entity.Refresh();
 }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entityWorld.</param>
        /// <param name="args">The args.</param>
        /// <returns>The <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.Group = "BULLETS";

            entity.AddComponentFromPool<TransformComponent>();
            entity.AddComponent(new SpatialFormComponent("Missile"));
            entity.AddComponent(new VelocityComponent());
            entity.AddComponent(new ExpiresComponent(2000));

            return entity;
        }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entity world.</param>
        /// <param name="args">The args.</param>
        /// <returns>The <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.Group = "SHIPS";

            entity.AddComponentFromPool<TransformComponent>();
            entity.AddComponent(new SpatialFormComponent("EnemyShip"));
            entity.AddComponent(new HealthComponent(10));
            entity.AddComponent(new WeaponComponent());
            entity.AddComponent(new EnemyComponent());
            entity.AddComponent(new VelocityComponent());

            return entity;
        }
        /// <summary>The process.</summary>
        /// <param name="entity">The entity.</param>
        public override void Process(Entity entity)
        {
            TestHealthComponent testHealth = entity.GetComponent<TestHealthComponent>();
            if (testHealth != null)
            {
                testHealth.AddDamage(10);
            }

            TestPowerComponent testPower = entity.GetComponent<TestPowerComponent>();
            if (testPower != null)
            {
                testPower.Power -= 10;
            }
        }
示例#19
0
        public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
        {
            e.AddComponent(new Direction());
            e.AddComponent(new IsControllable());
            e.AddComponent(new ControllableStates());
            e.AddComponent(new Position());
            e.AddComponent(new Health());
            e.AddComponent(new Velocity());
            e.AddComponent(new TransformC());

            e.Refresh();

            return e;
        }
        /// <summary>The process.</summary>
        /// <param name="entity">The entity.</param>
        public override void Process(Entity entity)
        {
            TestHealthComponent testHealth = this.testHealthMapper.Get(entity);
            if (testHealth != null)
            {
                testHealth.AddDamage(10);
            }

            TestPowerComponentPoolable testPower = this.testPowerMapper.Get(entity);
            if (testPower != null)
            {
                testPower.Power -= 10;
            }
        }
示例#21
0
文件: Enemy.cs 项目: zunath/MMXEngine
        public Entity BuildEntity(Entity entity, params object[] args)
        {
            string enemyResourceFile = args[0] as string;
            string dataFile = "/Creatures/Enemies/" + enemyResourceFile + ".json";
            CreatureData data = _dataManager.Load<CreatureData>(dataFile);

            Sprite sprite = _componentFactory.Create<Sprite>();
            sprite.Texture = _contentManager.Load<Texture2D>("./Graphics/Enemies/" + data.TextureFile);
            foreach (Animation animation in data.Animations)
            {
                sprite.Animations.Add(animation.Name, animation);
                if (animation.IsDefaultAnimation)
                {
                    sprite.SetCurrentAnimation(animation.Name);
                }
            }

            entity.AddComponent(sprite);
            entity.AddComponent(_componentFactory.Create<Health>());
            Position position = _componentFactory.Create<Position>();
            position.X = (int?) args[1] ?? 0;
            position.Y = (int?) args[2] ?? 0;
            entity.AddComponent(position);
            entity.AddComponent(_componentFactory.Create<Renderable>());
            entity.AddComponent(_componentFactory.Create<Velocity>());
            entity.AddComponent(_componentFactory.Create<Hostile>());
            entity.AddComponent(_componentFactory.Create<LocalData>());

            Nameable nameable = _componentFactory.Create<Nameable>();
            nameable.Name = data.Name;
            entity.AddComponent(nameable);

            Script script = _componentFactory.Create<Script>();
            script.FilePath = data.Script;
            entity.AddComponent(script);

            CollisionBox box = _componentFactory.Create<CollisionBox>();
            box.Width = data.CollisionWidth;
            box.Height = data.CollisionHeight;
            box.OffsetX = data.CollisionOffsetX;
            box.OffsetY = data.CollisionOffsetY;
            entity.AddComponent(box);

            Heartbeat hb = _componentFactory.Create<Heartbeat>();
            hb.Interval = data.HeartbeatInterval;
            entity.AddComponent(hb);

            return entity;
        }
示例#22
0
        public override void Process(Entity entity)
        {
            Renderable renderable = entity.GetComponent<Renderable>();
            Sprite sprite = entity.GetComponent<Sprite>();
            Position position = entity.GetComponent<Position>();
            Animation animation = sprite.Animations[sprite.CurrentAnimationName];
            Frame frame = animation.Frames[animation.CurrentFrameID];

            // Determine next frame to use.
            sprite.FrameActiveTime += _world.DeltaSeconds();

            if (sprite.FrameActiveTime > frame.Length)
            {
                if (animation.CurrentFrameID == animation.Frames.Count - 1 &&
                    !string.IsNullOrEmpty(animation.NextAnimation))
                {
                    sprite.SetCurrentAnimation(animation.NextAnimation);
                    animation = sprite.Animations[sprite.CurrentAnimationName];
                    frame = animation.Frames[animation.CurrentFrameID];
                }
                else
                {
                    frame.HasRunOnce = true;
                    animation.CurrentFrameID++;
                    sprite.FrameActiveTime = 0;
                    frame = animation.Frames[animation.CurrentFrameID];
                }
            }

            while (frame.OnlyRunOnce && frame.HasRunOnce)
            {
                animation.CurrentFrameID++;
                frame = animation.Frames[animation.CurrentFrameID];
            }

            int offsetX = frame.OffsetX;
            int offsetY = frame.OffsetY;
            if (position.Facing == Direction.Left)
            {
                offsetX = -offsetX;
            }

            // Update renderable
            renderable.Source = new Rectangle(frame.X, frame.Y, frame.Width, frame.Height);
            renderable.Texture = sprite.Texture;
            renderable.Position = new Vector2(position.X + offsetX, position.Y + offsetY);
            renderable.Facing = position.Facing;
            renderable.ColorOverride = sprite.ColorOverride;
        }
        public override void Process(Entity entity)
        {
            CollisionBox box = entity.GetComponent<CollisionBox>();
            Position position = entity.GetComponent<Position>();

            if (box.IsVisible)
            {
                Rectangle bounds = new Rectangle(
                    (int)position.X + box.OffsetX,
                    (int)position.Y + box.OffsetY,
                    box.Width,
                    box.Height
                    );
                _spriteBatch.DrawRectangle(bounds, box.Color);
            }
        }
示例#24
0
        public override void Process(Entity entity)
        {
            if (!entity.HasComponent<Heartbeat>()) return;
            Heartbeat hb = entity.GetComponent<Heartbeat>();
            if (hb.Interval <= 0.0f) return;
            hb.CurrentTimer += _world.DeltaSeconds();
            if (!(hb.CurrentTimer >= hb.Interval)) return;

            if (entity.HasComponent<Script>())
            {
                Script script = entity.GetComponent<Script>();
                _scriptManager.QueueScript(script.FilePath, entity, "OnHeartbeat");
            }

            hb.CurrentTimer = 0.0f;
        }
示例#25
0
 public override void Process(Entity e)
 {
     Effect effect = e.GetComponent<Effect>();
     BattleStats stats = effect.Owner.GetComponent<BattleStats>();
     Acting acting = effect.Owner.GetComponent<Acting>();
     if (stats != null && acting != null)
     {
         if (acting.State == ActingState.Cooldown)
         {
             effect.RemainingDuration -= stats.Speed * EntityWorld.Delta / 10000000;
         }
         if (stats.IsDead || effect.RemainingDuration < 0)
         {
             e.Delete();
         }
     }
 }
示例#26
0
文件: Midgard.cs 项目: enBask/Asgard
        public Physics2dComponent CreateComponent(Entity entity, BodyDefinition definition, bool remoteSync = true)
        {
            var body = CreateBody(definition);

            var component = new Physics2dComponent();
            component.Body = body;
            body.UserData = entity;
            entity.AddComponent(component);

            if (remoteSync)
            {
                ObjectMapper.Create(
                    (uint)entity.UniqueId, typeof(NetPhysicsObject));
            }

            return component;
        }
示例#27
0
文件: Level.cs 项目: zunath/MMXEngine
        public Entity BuildEntity(Entity entity, params object[] args)
        {
            string dataFile = "./Levels/" + args[0] + ".json";
            LevelData levelData = _dataManager.Load<LevelData>(dataFile);

            Nameable nameable = _componentFactory.Create<Nameable>();
            nameable.Name = levelData.Name;

            Map map = _componentFactory.Create<Map>();
            map.Width = levelData.Width;
            map.Height = levelData.Height;
            map.Spritesheet = _contentManager.Load<Texture2D>("./Graphics/Tilesets/" + levelData.Spritesheet);
            map.Tiles = levelData.Tiles;

            entity.AddComponent(nameable);
            entity.AddComponent(map);
            return entity;
        }
示例#28
0
        public override void Process(Entity e)
        {
            bool isHero = e.GetComponent<Group>().IsHero;
            Transform spatial = e.GetComponent<Transform>();
            Animation animation = e.GetComponent<Animation>();
            Acting acting = e.GetComponent<Acting>();

            animation.Timer += EntityWorld.Delta / 10000000.0;
            if (animation.Timer >= animation.MovementTime && !animation.IsActing && animation.IsAdvancing)
            {
                foreach (Entity target in acting.Targets)
                {
                    _entityCreator.GenerateParticle(target, acting.SkillSelected.Name);
                }
                animation.IsActing = true;
            }
            else if (animation.Timer >= animation.MovementTime + animation.ActionTime && animation.IsActing)
            {
                BattleEngine.UseSkill(e, acting.SkillSelected, acting.Targets);
                animation.IsActing = false;
                animation.IsAdvancing = false;
            }
            else if (animation.Timer >= 2 * animation.MovementTime + animation.ActionTime && !animation.IsActing)
            {
                spatial.X = animation.InitialPosition.X;
                acting.ResetSelection();
                return;
            }
            if (animation.IsActing)
            {
                return;
            }
            double movement = animation.SpriteSpeed * EntityWorld.Delta / 10000000;
            if (!animation.IsAdvancing)
            {
                movement = -movement;
            }
            if (!isHero)
            {
                movement = -movement;
            }
            spatial.X += (float)movement;
        }
示例#29
0
        public Entity BuildEntity(Entity entity, params object[] args)
        {
            _characterType = args.Length > 0 ? (CharacterType) args[0] : CharacterType.X;
            LoadPlayerDataFile();

            entity.AddComponent(BuildSprite());
            PlayerAction action = _componentFactory.Create<PlayerAction>();
            action.MaxDashLength = _playerData.MaxDashLength;
            entity.AddComponent(action);
            entity.AddComponent(_componentFactory.Create<Health>());

            Position position = _componentFactory.Create<Position>();
            position.Facing = Direction.Right;
            position.X = (int?) args[1] ?? 0;
            position.Y = (int?) args[2] ?? 0;
            entity.AddComponent(position);

            entity.AddComponent(_componentFactory.Create<LocalData>());
            entity.AddComponent(_componentFactory.Create<Velocity>());
            entity.AddComponent(_componentFactory.Create<Renderable>());
            entity.AddComponent(BuildCollisionBox());
            PlayerCharacter playerCharacter = _componentFactory.Create<PlayerCharacter>();
            playerCharacter.CharacterType = _characterType;
            entity.AddComponent(playerCharacter);

            Nameable nameable = _componentFactory.Create<Nameable>();
            nameable.Name = _playerData.Name;
            entity.AddComponent(nameable);

            Heartbeat heartbeat = _componentFactory.Create<Heartbeat>();
            heartbeat.Interval = _playerData.HeartbeatInterval;
            entity.AddComponent(heartbeat);

            Script script = _componentFactory.Create<Script>();
            script.FilePath = _playerData.Script;
            entity.AddComponent(script);

            EntitySystem.BlackBoard.SetEntry("Player", entity);

            return entity;
        }
示例#30
0
        public override void Process(Entity entity)
        {
            Renderable renderable = entity.GetComponent<Renderable>();
            SpriteEffects flip = SpriteEffects.None;
            Vector2 origin = new Vector2((int)(renderable.Source.Width / 2), (int)(renderable.Source.Height / 2));

            if (renderable.Facing == Direction.Left)
            {
                flip = SpriteEffects.FlipHorizontally;
            }

            _spriteBatch.Draw(renderable.Texture,                   // Texture
                renderable.Position,                                // Position
                renderable.Source,                                  // Source
                renderable.ColorOverride ?? Color.White,            // Color
                0.0f,                                               // Rotation
                origin,                                             // Origin
                1.0f,                                               // Scale
                flip,                                               // SpriteEffects
                0.0f);                                              // Layer Depth
        }
示例#31
0
 /// <summary>
 /// Processes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public override void Process(Artemis.Entity entity)
 {
     entity.GetComponent <TestHealthComponent>().AddDamage(10);
     TestTimeWaster.Delay(1000);
 }