Exemplo n.º 1
0
        protected override IEnumerable <GameObject> CreateObjs()
        {
            var player = new OrthographicMovingObjectFactory()
                         .CreateMovingObject(Tsx.Create(Path.Combine("Characters", "Gareth.tsx")), _player.Transform.Location, new ZIndex(3))
                         .Add(new TopDownMovement {
                Speed = 0.2f
            });

            PlayerLocation.Current = new PlayerLocation {
                MapName = GetType().Name, Transform = player.World
            };

            yield return(player);

            var cameraPosition = Transform2.CameraZero;

            cameraPosition.Center = player.World.Center - new Vector2(800, 450);
            yield return(Entity
                         .Create("Player Camera", cameraPosition)
                         .Add(new Camera())
                         .AttachTo(player));

            foreach (var tile in new OrthographicTileMapFactory().CreateMap(Tmx.Create(Path.Combine("Maps", "Large.tmx"))))
            {
                yield return(tile);
            }
            foreach (var mapEvent in MapEventsFactory.Create(Path.Combine("Content", "Maps", "Large.events")).InstantiateEvents())
            {
                yield return(mapEvent);
            }
        }
Exemplo n.º 2
0
 private void AddTileset(Tsx tsx)
 {
     for (int i = 0; i < tsx.Tiles.Count; i++)
     {
         _tiles[tsx.FirstId + i] = new TileDetail(tsx.TileSource, GetTileRectangle(i, tsx));
     }
 }
Exemplo n.º 3
0
        private Rectangle GetTileRectangle(int tile, Tsx tsx)
        {
            var column = tile % tsx.Columns;
            var row    = (int)Math.Floor((double)tile / tsx.Columns);
            var x      = column * tsx.TileWidth + (column + 1) * tsx.Spacing;
            var y      = row * tsx.TileHeight + (row + 1) * tsx.Spacing;

            return(new Rectangle(x, y, tsx.TileWidth, tsx.TileHeight));
        }
 private MotionBoxColliderStates CreateBoxColliderStates(Tsx tsx)
 {
     return(new MotionBoxColliderStates(
                CreateBoxCollider(tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Up)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Right)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Down)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Left)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Up)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Right)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Down)).ToList()),
                CreateBoxCollider(tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Left)).ToList())));
 }
 private MotionAnimationStates CreateMotionAnimationStates(Tsx tsx, Texture2D texture)
 {
     return(new MotionAnimationStates(
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Up)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Right)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Down)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.IsStanding && x.Rotation.Equals(Rotation2.Left)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Up)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Right)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Down)).Select(x => x.Id).ToList(), texture),
                CreateAnimation(tsx, tsx.Sprites.Where(x => x.Rotation.Equals(Rotation2.Left)).Select(x => x.Id).ToList(), texture)));
 }
 public GameObject CreateMovingObject(Tsx tsx, Vector2 location, ZIndex zIndex)
 {
     return(Entity.Create("TsxMovingObject", new Transform2(location, new Size2(tsx.TileWidth, tsx.TileHeight), zIndex))
            .Add((o, r) => new Texture(r.LoadTexture(tsx.ImageSource, o)))
            .Add(o => new Animation(0, o.Get <Texture>()))
            .Add(o => CreateMotionAnimationStates(tsx, o.Get <Texture>().Value))
            .Add(new Motion2(new Velocity2()))
            .Add(new Collision())
            .Add(new BoxCollider(Transform2.Zero))
            .Add(new MotionState())
            .Add(CreateBoxColliderStates(tsx)));
 }
Exemplo n.º 7
0
        protected override IEnumerable <GameObject> CreateObjs()
        {
            var player = new OrthographicMovingObjectFactory()
                         .CreateMovingObject(Tsx.Create(Path.Combine("Characters", "Gareth.tsx")), _player.Transform.Location, new ZIndex(3))
                         .Add(new TopDownMovement {
                Speed = 0.2f
            });

            PlayerLocation.Current = new PlayerLocation {
                MapName = GetType().Name, Transform = player.World
            };

            yield return(player);

            var cameraPosition = Transform2.CameraZero;

            cameraPosition.Center = player.World.Center - new Vector2(800, 450);
            yield return(Entity
                         .Create("Player Camera", cameraPosition)
                         .Add(new Camera())
                         .AttachTo(player));

            foreach (var tile in new OrthographicTileMapFactory().CreateMap(Tmx.Create(Path.Combine("Maps", "FireCave.tmx"))))
            {
                yield return(tile);
            }

            yield return(Entity.Create("Start Battle", new Transform2(new TilePosition(3, 5, 48), new Size2(48 * 3, 10)))
                         .Add(new Collision {
                IsBlocking = false
            })
                         .Add(x => new BoxCollider(x.World))
                         .Add(new StepTrigger())
                         .Add(new OnCollision {
                Action = x => x.IfEquals(player, () => Navigate.To(BattleFactory.Create()))
            }));

            foreach (var mapEvent in MapEventsFactory.Create(Path.Combine("Content", "Maps", "FireCave.events")).InstantiateEvents())
            {
                yield return(mapEvent);
            }
        }
 private Texture CreateTexture(Tsx tsx, int id, Texture2D texture)
 {
     return(new Texture(texture, new SpriteSheetRectangle(id, tsx.Columns, tsx.TileWidth, tsx.TileHeight, tsx.Spacing).Get()));
 }
 private Animation CreateAnimation(Tsx tsx, List <int> spriteIds, Texture2D texture)
 {
     return(new Animation(tsx.MsPerFrame, spriteIds.Select(x => CreateTexture(tsx, x, texture)).ToArray()));
 }
Exemplo n.º 10
0
        private Tsx LoadTsx(string path, int firstgid)
        {
            Console.WriteLine ("MapLoader: Loading tileset " + path);
            var d = XElement.Load(path);

            Tsx tsx = new Tsx()
            {
                SpawnsOnly = path.Trim().Length > 0 && !path.Contains("spawns"),
                FirstGid = firstgid,
                LastGid = int.MaxValue,
                TilemapName = Path.GetFileNameWithoutExtension((string)d.Element("image").Attribute("source")),

                BlockTypes = (	from t in d.Elements("tile")
                                from p in t.Element("properties").Elements("property")
                                where (string)p.Attribute("name") == "blocktype"
                                select new
                                {
                                    Id = (int)t.Attribute("id") + 1,
                                    Type = (BlockType)Enum.Parse(typeof(BlockType), (string)p.Attribute("value"), true)
                                })
                                .ToDictionary(bt => bt.Id, bt => bt.Type),

                SpawnTypes = (	from t in d.Elements("tile")
                                from p in t.Element("properties").Elements("property")
                                where (string)p.Attribute("name") == "spawn"
                                select new
                                {
                                    Id = (int)t.Attribute("id") + 1,
                                    Type = (SpawnType)Enum.Parse(typeof(SpawnType), (string)p.Attribute("value"), true)
                                })
                                .Where(st => st.Type != SpawnType.Nothing)
                                .ToDictionary(st => st.Id, st => st.Type)
            };

            return tsx;
        }