private void updateNavBarTitle() { if (modelController.getPageData().size() > 1) { setTitle( String.format( "Photos (%d of %d)", modelController.getCurrentPageIndex() + 1, modelController.getPageData().size())); } else { PhotoAnnotation viewController = modelController.getPageData().get((int) modelController.getCurrentPageIndex()); setTitle(viewController.getTitle()); } }
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(); }
// Configurations for player upon death public void playerDeath() { SoundManager.get().playSound("death"); deathTimer = new MillisecTimer(); playerModel.death(); distanceScrolled = 0.0f; scrollDelta = 0; activeBullets.clear(); activeEnemies.clear(); loadObjects(levelFile, queuedEnemies, levelPickups); // Game Over if player runs out of lives if (playerModel.getLives() < 0) { modelController.setMainModel(new GameOverModel(modelController)); modelController .getViewController() .setMainView(new GameOverView(modelController.getViewController())); } }
@Override public void viewDidLoad() { super.viewDidLoad(); modelController = new ModelController(); // Do any additional setup after loading the view, typically from a nib. // Configure the page view controller and add it as a child view // controller. pageViewController = new UIPageViewController( UIPageViewControllerTransitionStyle.PageCurl, UIPageViewControllerNavigationOrientation.Horizontal, null); pageViewController.setDelegate(this); modelController.setPageData(photosToShow); UIStoryboard storyboard = new UIStoryboard("Main", null); DataViewController startingViewController = modelController.getViewControllerAtIndex(0, storyboard); NSArray<UIViewController> viewControllers = new NSArray<UIViewController>(startingViewController); pageViewController.setViewControllers( viewControllers, UIPageViewControllerNavigationDirection.Forward, false, null); updateNavBarTitle(); pageViewController.setDataSource(modelController); addChildViewController(pageViewController); getView().addSubview(pageViewController.getView()); pageViewController.didMoveToParentViewController(this); // add the page view controller's gesture recognizers to the book view // controller's view // so that the gestures are started more easily getView().setGestureRecognizers(pageViewController.getGestureRecognizers()); pageAnimationFinished = true; }
LevelModel(ModelController theModelController) { modelController = theModelController; currentLevel = Level.TEST; loadLevel(currentLevel); playerModel = new PlayerModel(this); theModelController .getViewController() .getDrawPanel() .getInputHandler() .registerInputResponder(playerModel); paused = false; deathTimer = null; }
/** * manages the boss. Checks if boss is dead and goes to next level, Check if boss is shot. Flips * boss image as necessary and finally handles the boss shooting */ private void updateBoss(float dt) { if (boss != null) { // Check if boss needs flipped (Boss cannot access the player to get his x and y position so I // calculate this here) if (playerModel.getXPos() > boss.getXPos() + 30 && boss.direction == false) { boss.direction = true; if (boss.curFrame == 2) { boss.curFrame = 1; } else { boss.curFrame = 0; } } else if (playerModel.getXPos() < boss.getXPos() + 30 && boss.direction == true) { boss.direction = false; if (boss.curFrame == 1) { boss.curFrame = 2; } else { boss.curFrame = 3; } } // // Check if boss gets shot ArrayList<Bullet> bulletsToRemove = new ArrayList<Bullet>(); for (Bullet b : playerModel.getBulletList()) { if (boss.checkBullet(b)) { bulletsToRemove.add(b); } } playerModel.getBulletList().removeAll(bulletsToRemove); // Check if player is hit by spinning arm // Here I check each piece of arm individually for (int i = 0; i < boss.armPieces.size(); i++) { // Player dies if he collides with arm if (Utils.boxCollision( new Rectangle(boss.armPieces.get(i).x, boss.armPieces.get(i).y, 32, 32), playerModel.getBoundingBox())) { boss.setXPos(300); boss.theta = 0; playerDeath(); } } // check if boss is dead (Boss doesn't have enough access to change to a new test level) if (boss.health <= 0) { modelController.setMainModel(new LevelModel(modelController, "assets/underworld.json")); modelController .getViewController() .setMainView(new LevelView(modelController.getViewController(), "next")); SoundManager sm = SoundManager.get(); sm.playSound("underworld"); sm.stopSound("music"); } // boss shoots 3 bullets at a time if (boss.shootBullet()) { if (boss.direction == false) { Vector2 playerPos = new Vector2( playerModel.getXPos(), playerModel .getYPos()); // Obtains player's location to shoot towards that direction Vector2 enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 19); Vector2 dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 19, dir)); enemyPos = new Vector2(boss.xPos + 5, boss.yPos + 47); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 5, boss.yPos + 47, dir)); enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 72); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 72, dir)); } else { Vector2 playerPos = new Vector2( playerModel.getXPos(), playerModel .getYPos()); // Obtains player's location to shoot towards that direction Vector2 enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 19); Vector2 dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 19, dir)); enemyPos = new Vector2(boss.xPos + 88, boss.yPos + 47); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 88, boss.yPos + 47, dir)); enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 72); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 72, dir)); } } boss.update(dt); } }