Пример #1
0
        public void ResetPlayer(EntityCommandBuffer cb, Entity player, WorldCoord worldCoord, Translation translation)
        {
            CreatureDescription descr = CreatureDescriptions[(int)ECreatureId.Player];

            Creature c = new Creature {
                id = (int)ECreatureId.Player
            };
            HealthPoints hp = new HealthPoints {
                max = descr.health, now = descr.health
            };
            AttackStat att = new AttackStat {
                range = descr.attackRange
            };
            Level lvl = new Level {
                level = 1
            };
            ExperiencePoints exp = new ExperiencePoints {
                now = 0, next = LevelSystem.GetXPRequiredForLevel(1)
            };
            GoldCount gp = new GoldCount {
                count = 0
            };
            Mobile mobile = new Mobile {
                Destination = new float3(0, 0, 0), Initial = new float3(0, 0, 0), MoveTime = 0, Moving = false
            };
            Animated animated = new Animated {
                Id = descr.spriteId, Direction = Direction.Right, Action = Action.None, AnimationTime = 0, AnimationTrigger = false
            };
            Sight sight = new Sight {
                SightRadius = 4
            };
            TurnPriorityComponent tp = new TurnPriorityComponent {
                Value = -1
            };

            // Only tint sprites if ascii
            Sprite2DRenderer s = new Sprite2DRenderer();
            LayerSorting     l = new LayerSorting {
                order = 2
            };

            s.color  = GlobalGraphicsSettings.ascii ? descr.asciiColor : Color.Default;
            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(descr.ascii)];
            l.layer  = 2;

            cb.SetComponent(player, s);
            cb.SetComponent(player, c);
            cb.SetComponent(player, l);
            cb.SetComponent(player, hp);
            cb.SetComponent(player, att);
            cb.SetComponent(player, lvl);
            cb.SetComponent(player, exp);
            cb.SetComponent(player, gp);
            cb.SetComponent(player, mobile);
            cb.SetComponent(player, animated);
            cb.SetComponent(player, sight);
            cb.SetComponent(player, worldCoord);
            cb.SetComponent(player, translation);
            cb.SetComponent(player, tp);
        }
Пример #2
0
        public Entity CreateGold(EntityCommandBuffer ecb, int2 xy, float3 pos)
        {
            Entity entity = ecb.CreateEntity(Gold);

            Sprite2DRenderer s = new Sprite2DRenderer();
            Translation      t = new Translation();
            WorldCoord       c = new WorldCoord();
            LayerSorting     l = new LayerSorting();

            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = GlobalGraphicsSettings.ascii
                ? new Unity.Tiny.Core2D.Color(0.964f, 0.749f, 0.192f)
                : Color.Default;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics((char)236)];
            l.layer  = 1;

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);

            return(entity);
        }
Пример #3
0
        public Entity CreateSpearTrap(EntityCommandBuffer ecb, int2 xy, float3 pos)
        {
            Entity entity = ecb.CreateEntity(SpearTrap);

            Sprite2DRenderer s = new Sprite2DRenderer();
            Translation      t = new Translation();
            WorldCoord       c = new WorldCoord();
            LayerSorting     l = new LayerSorting();

            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = TinyRogueConstants.DefaultColor;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }
            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('^')];
            l.order  = 1;

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);

            return(entity);
        }
Пример #4
0
        public Entity CreateTile(EntityManager entityManager, int2 xy, float3 pos, Entity parent)
        {
            Entity           entity = entityManager.CreateEntity(Tile);
            Sprite2DRenderer s      = new Sprite2DRenderer();
            Translation      t      = new Translation();
            Parent           p      = new Parent();
            WorldCoord       c      = new WorldCoord(); // ViewCoord?

            p.Value = parent;
            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = TinyRogueConstants.DefaultColor;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(' ')];

            entityManager.SetComponentData(entity, s);
            entityManager.SetComponentData(entity, t);
            entityManager.SetComponentData(entity, p);
            entityManager.SetComponentData(entity, c);

            return(entity);
        }
Пример #5
0
        public Entity SpawnCreature(EntityCommandBuffer cb, ECreatureId cId, int priority)
        {
            Entity entity             = cb.CreateEntity(_creatureArchetype);
            CreatureDescription descr = CreatureDescriptions[(int)cId];

            Sprite2DRenderer s = new Sprite2DRenderer();
            LayerSorting     l = new LayerSorting();
            Creature         c = new Creature {
                id = (int)cId
            };
            HealthPoints hp = new HealthPoints {
                max = descr.health, now = descr.health
            };
            AttackStat att = new AttackStat {
                range = descr.attackRange
            };
            Sight sight = new Sight {
                SightRadius = descr.sightRadius
            };
            PatrollingState     patrol   = new PatrollingState();
            MeleeAttackMovement movement = new MeleeAttackMovement();
            Speed speed = new Speed {
                SpeedRate = descr.speed
            };
            Mobile mobile = new Mobile {
                Destination = new float3(0, 0, 0), Initial = new float3(0, 0, 0), MoveTime = 0, Moving = false
            };
            Animated animated = new Animated {
                Id = descr.spriteId, Direction = Direction.Right, Action = Action.None, AnimationTime = 0, AnimationTrigger = false
            };
            ArmorClass ac = new ArmorClass {
                AC = descr.ac
            };
            TurnPriorityComponent tp = new TurnPriorityComponent {
                Value = priority
            };

            // Only tint sprites if ascii
            s.color   = GlobalGraphicsSettings.ascii ? descr.asciiColor : Color.Default;
            s.color.a = 0.0f; // Start invisible
            s.sprite  = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(descr.ascii)];
            l.layer   = 2;

            cb.SetComponent(entity, s);
            cb.SetComponent(entity, c);
            cb.SetComponent(entity, l);
            cb.SetComponent(entity, hp);
            cb.SetComponent(entity, att);
            cb.SetComponent(entity, sight);
            cb.SetComponent(entity, movement);
            cb.SetComponent(entity, patrol);
            cb.SetComponent(entity, speed);
            cb.SetComponent(entity, mobile);
            cb.SetComponent(entity, animated);
            cb.SetComponent(entity, ac);

            return(entity);
        }
Пример #6
0
 void ClearView(EntityCommandBuffer ecb)
 {
     Entities.WithAll <Tile>().ForEach((Entity e, ref Sprite2DRenderer renderer) =>
     {
         ecb.SetComponent(e, new Sprite2DRenderer
         {
             sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(' ')]
         });
     });
 }
Пример #7
0
        public void Blit(EntityCommandBuffer ecb, int2 xy, int c, Color color)
        {
            if (!GlobalGraphicsSettings.ascii)
            {
                return;
            }
            Entity e = ViewTiles[XYToIndex(xy, Width)];

            ecb.SetComponent(e, new Sprite2DRenderer
            {
                sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics((char)c)],
                color  = color
            });
        }
Пример #8
0
        public void CreateCollectible(EntityCommandBuffer ecb, int2 xy, float3 pos)
        {
            Entity entity = ecb.CreateEntity(Collectible);

            Sprite2DRenderer s  = new Sprite2DRenderer();
            Translation      t  = new Translation();
            WorldCoord       c  = new WorldCoord();
            LayerSorting     l  = new LayerSorting();
            CanBePickedUp    p  = new CanBePickedUp();
            HealthBonus      hb = new HealthBonus();

            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = GlobalGraphicsSettings.ascii
                ? new Unity.Tiny.Core2D.Color(1, 1, 1)
                : Color.Default;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            l.layer = 1;

            p.appearance.color  = s.color;
            p.appearance.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('S')];   //defaults

            p.name        = new NativeString64("unknown pickup");
            p.description = new NativeString64("Check collectible gen");

            var collectibleGenSystem = World.Active.GetOrCreateSystem <CollectibleGenSystem>();

            collectibleGenSystem.GetRandomCollectible(ecb, entity, p, hb);
            s.sprite = p.appearance.sprite;

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);
            ecb.SetComponent(entity, p);
        }
Пример #9
0
        public Entity CreateHealingItem(EntityCommandBuffer ecb, int2 xy, float3 pos, int healAmount)
        {
            Entity entity = ecb.CreateEntity(HealingPotion);

            HealItem         heal = new HealItem();
            Sprite2DRenderer s    = new Sprite2DRenderer();
            Translation      t    = new Translation();
            WorldCoord       c    = new WorldCoord();
            LayerSorting     l    = new LayerSorting();

            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = GlobalGraphicsSettings.ascii
                ? new Unity.Tiny.Core2D.Color(1.0f, 0.26f, 0.23f)
                : Color.Default;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics((char)235)];
            l.layer  = 1;

            heal.HealAmount = healAmount;

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);
            ecb.SetComponent(entity, heal);

            return(entity);
        }
Пример #10
0
        public Entity CreateDoorway(EntityCommandBuffer ecb, int2 xy, float3 pos, bool horizontal)
        {
            Entity entity = ecb.CreateEntity(Doorway);

            Sprite2DRenderer s = new Sprite2DRenderer();
            Translation      t = new Translation();
            WorldCoord       c = new WorldCoord();
            LayerSorting     l = new LayerSorting();
            Door             d = new Door();

            d.Horizontal = horizontal;
            t.Value      = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = GlobalGraphicsSettings.ascii
                ? new Unity.Tiny.Core2D.Color(18 / 255.0f, 222 / 255.0f, 23.0f / 255.0f)
                : Color.Default;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(horizontal ? '\\' : '/')];
            // Have to draw above character in graphical
            l.layer = (short)(GlobalGraphicsSettings.ascii ? 1 : 3);

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);
            ecb.SetComponent(entity, d);

            return(entity);
        }
Пример #11
0
        public Entity SpawnPlayer(EntityManager entityManager)
        {
            Entity entity             = entityManager.CreateEntity(_playerArchetype);
            CreatureDescription descr = CreatureDescriptions[(int)ECreatureId.Player];

            Creature c = new Creature {
                id = (int)ECreatureId.Player
            };
            HealthPoints hp = new HealthPoints {
                max = descr.health, now = descr.health
            };
            AttackStat att = new AttackStat {
                range = descr.attackRange
            };
            Level lvl = new Level {
                level = 1
            };
            ExperiencePoints exp = new ExperiencePoints {
                now = 0, next = LevelSystem.GetXPRequiredForLevel(1)
            };
            GoldCount gp = new GoldCount {
                count = 0
            };
            Mobile mobile = new Mobile {
                Destination = new float3(0, 0, 0), Initial = new float3(0, 0, 0), MoveTime = 0, Moving = false
            };
            Animated animated = new Animated {
                Id = descr.spriteId, Direction = Direction.Right, Action = Action.None, AnimationTime = 0, AnimationTrigger = false
            };
            Sight sight = new Sight {
                SightRadius = 4
            };
            ArmorClass ac = new ArmorClass {
                AC = descr.ac
            };
            TurnPriorityComponent tp = new TurnPriorityComponent {
                Value = -1
            };

            // Only tint sprites if ascii
            Sprite2DRenderer s = new Sprite2DRenderer();
            LayerSorting     l = new LayerSorting {
                order = 2
            };

            s.color  = GlobalGraphicsSettings.ascii ? descr.asciiColor : Color.Default;
            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics(descr.ascii)];
            l.layer  = 2;

            entityManager.SetComponentData(entity, s);
            entityManager.SetComponentData(entity, c);
            entityManager.SetComponentData(entity, l);
            entityManager.SetComponentData(entity, hp);
            entityManager.SetComponentData(entity, att);
            entityManager.SetComponentData(entity, lvl);
            entityManager.SetComponentData(entity, exp);
            entityManager.SetComponentData(entity, gp);
            entityManager.SetComponentData(entity, mobile);
            entityManager.SetComponentData(entity, animated);
            entityManager.SetComponentData(entity, sight);
            entityManager.SetComponentData(entity, ac);
            entityManager.SetComponentData(entity, tp);

            return(entity);
        }
Пример #12
0
        protected override void OnUpdate()
        {
            var tileSprite = Sprite2DRenderer.Default;

            tileSprite.color = TinyRogueConstants.DefaultColor;

            // Set all floor tiles
            Entities.WithAll <Sprite2DRenderer, Floor>().ForEach((Entity e, ref Tile tile, ref Floor floor) =>
            {
                tileSprite.sprite  = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('.', floor.TileOffset)];
                tileSprite.color.a = GetAlphaForStaticTile(tile);
                PostUpdateCommands.SetComponent(e, tileSprite);
            });

            // Default all block tiles to a wall

            Entities.WithAll <Sprite2DRenderer, Wall>().ForEach((Entity e, ref Tile tile, ref Wall wall) =>
            {
                tileSprite.sprite  = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('#', wall.TileOffset)];
                tileSprite.color.a = GetAlphaForStaticTile(tile);
                PostUpdateCommands.SetComponent(e, tileSprite);
            });

            // Set all door tiles// horizontal // vertical
            // Set all closed door tiles // closed horizontal // closed vertical
            var doorSprite = Sprite2DRenderer.Default;

            doorSprite.color = TinyRogueConstants.DefaultColor;
            Entities.WithAll <Sprite2DRenderer, Door>().ForEach((Entity e, ref Door door, ref WorldCoord coord) =>
            {
                if (door.Opened)
                {
                    doorSprite.sprite = door.Horizontal ? SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('\\')] : SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('/')];
                }
                else
                {
                    doorSprite.sprite = door.Horizontal ? SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('_')]: SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics('|')];
                }

                // Check the tile, regardless of what entity we're looking at; this will tell objects if their tile is visible or not
                var tileIndex  = View.XYToIndex(new int2(coord.x, coord.y), GameStateSystem.GameView.Width);
                var tileEntity = GameStateSystem.GameView.ViewTiles[tileIndex];
                var tile       = EntityManager.GetComponentData <Tile>(tileEntity);
                // Setting alpha on a door onto of a tile only works for ascii. For graphics, dim the colours instead.
                if (GlobalGraphicsSettings.ascii)
                {
                    doorSprite.color.a = GetAlphaForStaticTile(tile);
                }
                else
                {
                    doorSprite.color = GetColorForDoor(tile);
                }

                PostUpdateCommands.SetComponent(e, doorSprite);
            });

            // All remaining static entities can be updated but need to keep their colour
            // This reads from *before* the above changes, so shouldn't be used on the same entities
            Entities.WithNone <Mobile, Tile, Door>().ForEach(
                (Entity e, ref Sprite2DRenderer renderer, ref WorldCoord coord) =>
            {
                var spriteRenderer = renderer;

                // Check the tile, regardless of what entity we're looking at; this will tell objects if their tile is visible or not
                var tileIndex          = View.XYToIndex(new int2(coord.x, coord.y), GameStateSystem.GameView.Width);
                var tileEntity         = GameStateSystem.GameView.ViewTiles[tileIndex];
                var tile               = EntityManager.GetComponentData <Tile>(tileEntity);
                spriteRenderer.color.a = GetAlphaForStaticTile(tile);

                PostUpdateCommands.SetComponent(e, spriteRenderer);
            });

            // All mobile entities should be either visible or not
            Entities.WithAll <Mobile>().ForEach(
                (Entity e, ref Sprite2DRenderer renderer, ref WorldCoord coord) =>
            {
                var spriteRenderer = renderer;

                // Check the tile, regardless of what entity we're looking at; this will tell objects if their tile is visible or not
                var tileIndex          = View.XYToIndex(new int2(coord.x, coord.y), GameStateSystem.GameView.Width);
                var tileEntity         = GameStateSystem.GameView.ViewTiles[tileIndex];
                var tile               = EntityManager.GetComponentData <Tile>(tileEntity);
                spriteRenderer.color.a = GetColorForMobileEntity(tile);

                PostUpdateCommands.SetComponent(e, spriteRenderer);
            });
        }