Example #1
0
        public GameWorld(uint maxEntities, Game game, int cellSize)
        {
            CellSize = cellSize;

            HealthComponents = new HealthComponent[MAX_ENTITIES];
            SpatialComponents = new SpatialComponent[MAX_ENTITIES];
            RegenerationComponents = new RegenerationComponent[MAX_ENTITIES];
            SpriteComponents = new SpriteComponent[MAX_ENTITIES];
            PhysicsComponents = new PhysicsComponent[MAX_ENTITIES];
			CollisionComponents = new TilemapCollisionComponent[MAX_ENTITIES];
			FlammableComponents = new FlammableComponent[MAX_ENTITIES];
            InputComponents = new InputComponent[MAX_ENTITIES];
            EnemyAIComponents = new EnemyAIComponent[MAX_ENTITIES];
            MeleeCombatComponents = new MeleeCombatComponent[MAX_ENTITIES];

            for (int i = 0; i < MAX_ENTITIES; i++)
            {
                HealthComponents[i] = new HealthComponent();
                SpatialComponents[i] = new SpatialComponent();
                RegenerationComponents[i] = new RegenerationComponent();
                SpatialComponents[i] = new SpatialComponent();
                PhysicsComponents[i] = new PhysicsComponent();
                CollisionComponents[i] = new TilemapCollisionComponent();
                FlammableComponents[i] = new FlammableComponent();
                InputComponents[i] = new InputComponent();
                EnemyAIComponents[i] = new EnemyAIComponent();
                MeleeCombatComponents[i] = new MeleeCombatComponent();
            }


            HealthSubsystem = new HealthSubsystem(this);
            PhysicsSubsystem = new PhysicsSubsystem(this);
            SpriteRendererSubsystem = new SpriteRendererSubsystem(game.Window, this);
			CollisionSubsystem = new CollisionSubsystem (this);
			StatusEffectsSubsystem = new StatusEffectsSubsystem (this);
            InputSubsystem = new InputSubsystem(this);
            EnvironmentalSubsystem = new EnvironmentalSubsystem(this);
            AISubsystem = new AISubsystem(this);
            MeleeCombatSubsystem = new MeleeCombatSubsystem(this);
        }
Example #2
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);
        }