Esempio n. 1
0
        public Tilemap(TextureAtlas atlas, int width, int height, float tileTextureDimension, float tileWorldDimension, Tile[,] tiles)
        {
            _atlas = atlas;
            _width = width;
            _height = height;
            _tileSize = tileTextureDimension;
            _cellSize = tileWorldDimension;
            Tiles = tiles;
            _vertexArray = new VertexArray(PrimitiveType.Quads, (uint)(width * height * 4));

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    AddTileVertices(tiles[x, y], new Vector2f(x, y));
                }
            }
        }
Esempio n. 2
0
        public static Level Generate(GameWorld world, int width, int height, TextureAtlas atlas, int cellSize)
        {
            DungeonGenerator.Instance.GenerateHauberkDungeon(width, height, 195000, 5, 5, 50, false, true);

            var tileData = DungeonGenerator._dungeon;
            var map = new Map(width, height);
            var tiles = new Tile[width, height];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    Color color = Color.White;

                    switch (tileData[x, y])
                    {
                        case TileType.Floor:
                            map.SetCellProperties(x, y, true, true);
                            color = new Color(194, 194, 194);
                            break;
                        case TileType.RoomFloor:
                            map.SetCellProperties(x, y, true, true);
                            color = new Color(35, 255, 255);
                            break;
                        case TileType.Wall:
                            map.SetCellProperties(x, y, false, false);
                            color = new Color(163, 163, 163);
                            break;
                        case TileType.Door:
                            map.SetCellProperties(x, y, false, true);
                            color = new Color(132, 81, 0);
                            break;
                    }

                    tiles[x, y] = new Tile(tileData[x, y], color);
                    tiles[x, y].Cell = map.GetCell(x, y);
                }
            }

            var tilemap = new Tilemap(atlas, width, height, atlas.SpriteSize, cellSize, tiles);

            return new Level(world, map, tilemap);
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            _font = new Font("Super Mario Bros.ttf");
            _text = new Text { Font = _font };
            _text.CharacterSize = 22;
            _text.Color = Color.White;

            _gameWorld = new GameWorld(10000, this, CELL_SIZE);

            _atlas = new TextureAtlas(new Texture("Content/terminal8x8.png"), 8);
            _atlas.Items.Add(TileType.Wall, new Vector2f(3, 2));
            _atlas.Items.Add(TileType.Floor, new Vector2f(14, 2));
            _atlas.Items.Add(TileType.RoomFloor, new Vector2f(14, 2));
            _atlas.Items.Add(TileType.Door, new Vector2f(11, 2));
            _atlas.Items.Add(TileType.OpenDoor, new Vector2f(13, 2));

            _level = Level.Generate(_gameWorld, 101, 101, _atlas, _gameWorld.CellSize);
            _gameWorld.CurrentLevel = _level;

            player = _gameWorld.EntityManager.CreateEntity();
            _level.Player = player;

            _gameWorld.HealthComponents[player] = new HealthComponent { MaxHealth = 100, CurrentHealth = 100 };

            var sprite = new SpriteComponent { Sprite = new Sprite(_atlas.Texture) };
            sprite.Sprite.TextureRect = new IntRect(new Vector2i(0, 4 * _atlas.SpriteSize), new Vector2i(_atlas.SpriteSize, _atlas.SpriteSize));
            _gameWorld.SpriteComponents[player] = sprite;

            var start = _level.GetRandomEmptyTile();
            _gameWorld.SpatialComponents[player] = new SpatialComponent { Position = new Vector2f(start.Cell.X, start.Cell.Y) };

            _gameWorld.PhysicsComponents[player] = new PhysicsComponent();

            _gameWorld.CollisionComponents[player] = new TilemapCollisionComponent { Group =  CollisionGroup.Player };
            _gameWorld.InputComponents[player] = new InputComponent();


            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Health);
            //_gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Regeneration);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Sprite);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Spatial);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Physics);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Collision);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.MeleeCombat);

            //_gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Flammable);
            _gameWorld.EntityManager.AddComponent(player, XnaGameComponentType.Input);

            /*--------------------------*/

            orcs = new List<uint>();

            for (int i = 1; i < 5; i++)
            {
                var ent = _gameWorld.EntityManager.CreateEntity();
                _gameWorld.HealthComponents[i] = new HealthComponent { MaxHealth = 25, CurrentHealth = 25 };

                sprite = new SpriteComponent { Sprite = new Sprite(_atlas.Texture) };
                sprite.Sprite.TextureRect = new IntRect(new Vector2i(15 * _atlas.SpriteSize, 6 * _atlas.SpriteSize), new Vector2i(_atlas.SpriteSize, _atlas.SpriteSize));
                sprite.Tint = new Color(27, 126, 1);
                _gameWorld.SpriteComponents[i] = sprite;

                start = _level.GetRandomEmptyTile();
                _gameWorld.SpatialComponents[ent] = new SpatialComponent { Position = new Vector2f(start.Cell.X, start.Cell.Y) };
                _gameWorld.PhysicsComponents[ent] = new PhysicsComponent();
                _gameWorld.CollisionComponents[ent] = new TilemapCollisionComponent { Group = CollisionGroup.Enemy };
                _gameWorld.EnemyAIComponents[ent] = new EnemyAIComponent { MoveChance = 30 };

                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.Sprite);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.Spatial);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.Physics);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.Collision);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.Health);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.EnemyAI);
                _gameWorld.EntityManager.AddComponent(ent, XnaGameComponentType.MeleeCombat);
                orcs.Add(ent);
            }
            _level.UpdatePlayerFov(_gameWorld.SpatialComponents[player].Position);
        }