private void killPlayer() { player.removeFromParent(); player.getControl(PlayerControl.class).reset(); player.setUserData("alive", false); player.setUserData("dieTime", System.currentTimeMillis()); enemyNode.detachAllChildren(); blackHoleNode.detachAllChildren(); particleManager.playerExplosion(player.getLocalTranslation()); if (!hud.removeLife()) { hud.endGame(); gameOver = true; } }
@Override public void render(Window window) { if (hud != null) { hud.updateSize(window); } renderer.render(window, camera, scene, hud); }
@Override public void cleanup() { renderer.cleanup(); scene.cleanup(); if (hud != null) { hud.cleanup(); } }
@Override public void hovered() { super.hovered(); if (world.mouse.shift_down) { if (world.mouse.rb_pressed) { DescWindow temp = new DescWindow(world, world.mouse.x, world.mouse.y); temp.updateText(effect); temp.open(); } } world.descBox.updateText(effect.getHoveredText()); }
@Override public void simpleUpdate(float tpf) { if ((Boolean) player.getUserData("alive")) { spawnEnemies(); spawnBlackHoles(); handleCollisions(); handleGravity(tpf); } else if (System.currentTimeMillis() - (Long) player.getUserData("dieTime") > 4000f && !gameOver) { // spawn player player.setLocalTranslation(500, 500, 0); guiNode.attachChild(player); player.setUserData("alive", true); sound.spawn(); grid.applyDirectedForce(new Vector3f(0, 0, 5000), player.getLocalTranslation(), 100); } grid.update(tpf); hud.update(); }
@Override public void calc() { x = world.cam.width - 36; y = world.cam.height - 36 * (1 + world.player.effectGraphics.indexOf(this)); super.calc(); }
@Override public void simpleInitApp() { // setup camera for 2D games cam.setParallelProjection(true); cam.setLocation(new Vector3f(0, 0, 0.5f)); getFlyByCamera().setEnabled(false); // turn off stats (you can leave it on, if you want) setDisplayStatView(false); setDisplayFps(false); // initializing the bloom filter FilterPostProcessor fpp = new FilterPostProcessor(assetManager); BloomFilter bloom = new BloomFilter(); bloom.setBloomIntensity(2f); bloom.setExposurePower(2); bloom.setExposureCutOff(0f); bloom.setBlurScale(1.5f); fpp.addFilter(bloom); guiViewPort.addProcessor(fpp); guiViewPort.setClearColor(true); // setup input handling inputManager.setMouseCursor((JmeCursor) assetManager.loadAsset("Textures/Pointer.ico")); inputManager.addMapping("mousePick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addListener(this, "mousePick"); inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D)); inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_S)); inputManager.addMapping("return", new KeyTrigger(KeyInput.KEY_RETURN)); inputManager.addListener(this, "left"); inputManager.addListener(this, "right"); inputManager.addListener(this, "up"); inputManager.addListener(this, "down"); inputManager.addListener(this, "return"); // setup the hud hud = new Hud(assetManager, guiNode, settings.getWidth(), settings.getHeight()); hud.reset(); // sounds sound = new Sound(assetManager); sound.startMusic(); sound.spawn(); // particles particleManager = new ParticleManager( guiNode, getSpatial("Laser"), getSpatial("Glow"), settings.getWidth(), settings.getHeight()); // grid Rectangle size = new Rectangle(0, 0, settings.getWidth(), settings.getHeight()); Vector2f spacing = new Vector2f(25, 25); grid = new Grid(size, spacing, guiNode, assetManager); // setup the player player = getSpatial("Player"); player.setUserData("alive", true); player.move(settings.getWidth() / 2, settings.getHeight() / 2, 0); player.addControl( new PlayerControl(settings.getWidth(), settings.getHeight(), particleManager)); guiNode.attachChild(player); // setup the bulletNode bulletNode = new Node("bullets"); guiNode.attachChild(bulletNode); // setup the enemyNode enemyNode = new Node("enemies"); guiNode.attachChild(enemyNode); // setup the blackholeNode blackHoleNode = new Node("black_holes"); guiNode.attachChild(blackHoleNode); // setup the particleNode particleNode = new Node("particles"); guiNode.attachChild(particleNode); }
private void handleCollisions() { // should the player die? for (int i = 0; i < enemyNode.getQuantity(); i++) { if ((Boolean) enemyNode.getChild(i).getUserData("active")) { if (checkCollision(player, enemyNode.getChild(i))) { killPlayer(); } } } // should an enemy die? int i = 0; while (i < enemyNode.getQuantity()) { int j = 0; while (j < bulletNode.getQuantity()) { if (checkCollision(enemyNode.getChild(i), bulletNode.getChild(j))) { // add points depending on the type of enemy if (enemyNode.getChild(i).getName().equals("Seeker")) { hud.addPoints(2); hud.addEmp(); } else if (enemyNode.getChild(i).getName().equals("Wanderer")) { hud.addPoints(1); hud.addEmp(); } particleManager.enemyExplosion(enemyNode.getChild(i).getLocalTranslation()); enemyNode.detachChildAt(i); bulletNode.detachChildAt(j); sound.explosion(); break; } j++; } i++; } // is something colliding with a black hole? for (i = 0; i < blackHoleNode.getQuantity(); i++) { Spatial blackHole = blackHoleNode.getChild(i); if ((Boolean) blackHole.getUserData("active")) { // player if (checkCollision(player, blackHole)) { killPlayer(); } // enemies int j = 0; while (j < enemyNode.getQuantity()) { if (checkCollision(enemyNode.getChild(j), blackHole)) { particleManager.enemyExplosion(enemyNode.getChild(j).getLocalTranslation()); enemyNode.detachChildAt(j); } j++; } // bullets j = 0; while (j < bulletNode.getQuantity()) { if (checkCollision(bulletNode.getChild(j), blackHole)) { bulletNode.detachChildAt(j); blackHole.getControl(BlackHoleControl.class).wasShot(); particleManager.blackHoleExplosion(blackHole.getLocalTranslation()); if (blackHole.getControl(BlackHoleControl.class).isDead()) { blackHoleNode.detachChild(blackHole); sound.explosion(); } } j++; } } } }