public void Initialize(Game2D game, ILevelDataProvider levelDataProvider) { _gameInformation = new GameInformation(game, levelDataProvider) { Width = BombGame.Tilesize * 15 }; _graphicsDevice = game.GraphicsDevice; _levelData = levelDataProvider; _context = new Render3DContext(game); _objectsToRender = new List <IRenderObject> { new Level(game.GraphicsDevice, game.Content, levelDataProvider) }; _bombGeometry = new ModelGeometry(this, game.GraphicsDevice, game.Content.Load <Model>("Models/Bomb/BombMesh"), _context.ToonEffect); _playerGeometry = new ModelGeometry(this, game.GraphicsDevice, game.Content.Load <Model>("Models/Player/bomberman"), _context.ToonEffect); _baseItemGeometry = new ModelGeometry(this, game.GraphicsDevice, game.Content.Load <Model>("Models/items/itemBase"), _context.ToonEffect); _fireOverlayGeometry = new ModelGeometry(this, game.GraphicsDevice, game.Content.Load <Model>("Models/items/fireoverlay"), _context.ToonEffect); _explosionFragmentManager = new ExplosionFragmentManager(game, _levelData); _players = new List <Player>(); foreach (var figure in _levelData.Figures) { var player = new Player(figure, _playerGeometry); AddRenderObject(player); _players.Add(player); } foreach (var itemDataProvider in _levelData.ItemData) { AddRenderObject(new Item3D(itemDataProvider, _baseItemGeometry, _fireOverlayGeometry)); } }
/// <summary> /// Loads the level and all related GameObjects like <c>LevelElement</c>s using the <c>ILevelLoader</c> /// </summary> public void LoadLevel() { if (MainMenuPlayerPreferences.InLevelCreationMode) { dataProvider = DeserializeLevel(); levelLoader = new BasicLevelLoader(dataProvider); } // Execute the following in try catch blocks, because levelLoader could be null. try { levelDataCollection = new LevelDataCollection(); level = levelLoader.LoadLevel(); levelDataCollection.levelElements = levelLoader.LoadLevelElements(transform); levelDataCollection.levelItemsData = levelLoader.LoadItemsData(); levelDataCollection.levelItems = levelLoader.LoadItems(transform, levelDataCollection.levelItemsData); if (MainMenuPlayerPreferences.InLevelCreationMode) { levelDataCollection.enemyData = dataProvider.GetEnemyData(); levelDataCollection.enemies = LoadEnemies(levelDataCollection.enemyData); JsonDataProvider jsonDataProvider = (JsonDataProvider)dataProvider; levelDataCollection.playerData = jsonDataProvider.GetPlayerData(); } } catch (NullReferenceException ex) { Debug.LogError("Cannot load level. No ILevelLoader assigned!"); throw new NullReferenceException("Cannot load level. No ILevelLoader assigned!", ex); } }
public ExplosionFragmentManager(Game2D game, ILevelDataProvider level) { _level = level; _texture = game.Content.Load <Texture2D>("Textures/explosionparticle"); _particleEffect = game.Content.Load <Effect>("Effects/ParticleEffect"); _worldViewProjParameter = _particleEffect.Parameters["WorldViewProjection"]; _textureParameter = _particleEffect.Parameters["DiffuseTexture"]; _instances = new List <ExplosionFragment>(); _quadVertexBuffer = new VertexBuffer(game.GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); _quadVertexBuffer.SetData(GeometryCreator.GenerateQuad(QuadOrientation.UnitY, Vector3.Zero)); }
public Level(GraphicsDevice device, ContentManager content, ILevelDataProvider levelDataProvider) { _levelData = levelDataProvider; _device = device; _wallTexture = content.Load <Texture2D>("Textures/wall"); _boxCube = new Cube(device, content.Load <Texture2D>("Textures/box")); _grassTexture = content.Load <Texture2D>("Textures/grass"); _groundVertexBuffer = new VertexBuffer(_device, VertexPositionNormalTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); _groundVertexBuffer.SetData(GeometryCreator.GenerateQuad(QuadOrientation.UnitY, Vector3.Zero, 15, 13)); GenerateContent(); }
public void LoadLevel_ReturnNewLevel() { // Arrange. ILevelDataProvider levelDataProvider = Substitute.For <ILevelDataProvider>(); BasicLevelLoader basicLevelLoader = new BasicLevelLoader(levelDataProvider); LevelData expectedLevelData = new LevelData { size = new Vector2Int(100, 100) }; levelDataProvider.GetLevelData().Returns(expectedLevelData); // Act. Level actualResult = basicLevelLoader.LoadLevel(); // Assert. NUnit.Framework.Assert.AreEqual(expectedLevelData.size, actualResult.GetLevelSize()); }
public void Update(ILevelDataProvider level, float elapsed, double localTimeStamp, double remoteTimeStamp) { Direction = _serverSendDirection; float distanceCanTravel = elapsed * Speed; if (_serverSendWalkDirection == Vector2.Zero) { Interpolate(_serverSendPosition, distanceCanTravel); } else if (_serverSendWalkDirection == WalkDirection) { Vector2 moveStep = _serverSendWalkDirection * (float)(remoteTimeStamp - _lastServerTimeStamp) * Speed; Vector2 currentPredictedPosition = LevelHelper.HandleCollisionSlide(level, _serverSendPosition, moveStep); Interpolate(currentPredictedPosition, distanceCanTravel); } else { Vector2 moveStep = _serverSendWalkDirection * (float)(remoteTimeStamp - _lastServerTimeStamp) * Speed; Vector2 currentPredictedPosition = LevelHelper.HandleCollisionSlide(level, _serverSendPosition, moveStep); Interpolate(currentPredictedPosition, distanceCanTravel); } WalkDirection = _serverSendWalkDirection; }
private void Start() { if (MainMenuPlayerPreferences.InLevelCreationMode) { return; } if (MainMenuPlayerPreferences.LoadFromJson) { dataProvider = DeserializeLevel(); } else { dataProvider = new TestLevelDataProvider(); } levelLoader = new BasicLevelLoader(dataProvider); LoadLevel(); if (MainMenuPlayerPreferences.LoadFromJson) { JsonDataProvider jsonDataProvider = (JsonDataProvider)dataProvider; levelDataCollection.playerData = jsonDataProvider.GetPlayerData(); } levelDataCollection.enemyData = dataProvider.GetEnemyData(); levelDataCollection.enemies = LoadEnemies(levelDataCollection.enemyData); if (serializeLevel) { SerializeLevel(); } StartLevel(); }
public BasicLevelLoader(ILevelDataProvider dataProvider) { this.dataProvider = dataProvider; }