LevelModel(ModelController theModelController, String fileLocation) { modelController = theModelController; levelFile = loadToJson(fileLocation); tileMap = new TileMap(levelFile); playerModel = new PlayerModel(this); theModelController .getViewController() .getDrawPanel() .getInputHandler() .registerInputResponder(playerModel); distanceScrolled = 0.0f; scrollVelocity = 0.05f; scrollDelta = 0; queuedEnemies = new ArrayList<EnemyModel>(); activeEnemies = new ArrayList<EnemyModel>(); activeBullets = new ArrayList<Bullet>(); levelPickups = new ArrayList<Pickup>(); // Retrieves Enemies, pickups, and tileMap loadObjects(levelFile, queuedEnemies, levelPickups); paused = false; deathTimer = null; SoundManager.get().playSound("music"); mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth(); }
public boolean wallCollision(Bullet bullet) { Rectangle boundingBox = bullet.getBoundingBox(); int tile; int tileWidth = tileMap.getTileWidth(); int tileHeight = tileMap.getTileHeight(); /* * nested four loop only is grabbing the 4 corners of the * bullet's hit box and checking the type of tiles that they * contact. The current bullets range from 8x8 to 17x17, so they * all can contact the same range of tiles at any given time: * 1-4 A bullet expires on contact with a solid object(besides * ring bullets) */ for (int y = bullet.yPos; y <= bullet.yPos + boundingBox.getHeight(); y += boundingBox.getHeight()) { for (int x = bullet.xPos; x <= bullet.xPos + boundingBox.getWidth(); x += boundingBox.getWidth()) { int tileCoordX = (int) (x + distanceScrolled) / tileWidth; int tileCoordY = y / tileHeight; tile = tileMap.getTile(((tileCoordY) * tileMap.getTileMapWidth()) + (tileCoordX)); if (tile < 17 || 23 < tile) { return true; } } } return false; }
public void loadLevel(Level level) { levelFile = loadToJson(level); tileMap = new TileMap(levelFile); distanceScrolled = 0.0f; scrollVelocity = 0.05f; scrollDelta = 0; queuedEnemies = new ArrayList<EnemyModel>(); activeEnemies = new ArrayList<EnemyModel>(); activeBullets = new ArrayList<Bullet>(); levelPickups = new ArrayList<Pickup>(); // Retrieves Enemies, pickups, and tileMap loadObjects(levelFile, queuedEnemies, levelPickups); SoundManager.get().playSound("music"); mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth(); }