added game end, added sky, minor fixes

This commit is contained in:
Raybz@Raybz 2013-06-27 13:03:45 +02:00
parent 416ebca4b2
commit b960885942
6 changed files with 172 additions and 19 deletions

View File

@ -217,7 +217,7 @@ public class AudioDataManager {
}
public float getMovementData() {
return 0.25f;
return 0.33f;
}
public float getSpeedData() {

View File

@ -39,7 +39,7 @@ public class GlowingHexPrism extends Node {
float glowPercentage, AudioDataManager adm) {
super("HexPrism " + position);
Material prismMat = Materials.HEX.create();
Material prismMat = Materials.HEX.create();
prismMat.setColor("Diffuse", ColorRGBA.Black);
prism = new Geometry("Prism " + position, new HexPrism(size, height));
prism.setMaterial(prismMat);

View File

@ -20,12 +20,14 @@ import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import org.wyrez.shootingstars.controls.GroundBorderGlowControl;
import org.wyrez.shootingstars.controls.GroundMoveControl;
import org.wyrez.shootingstars.data.AudioDataManager;
import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.helper.MathHelper;
import org.wyrez.shootingstars.mesh.HexPrism;
/**
@ -34,28 +36,39 @@ import org.wyrez.shootingstars.mesh.HexPrism;
*/
public class Ground extends Node {
public Ground(AudioDataManager adm) {
this(adm, 1000f);
private Node ground;
private Node sky;
public Ground(AudioDataManager adm, GameSettings settings) {
this(adm, settings, 1000f);
}
public Ground(AudioDataManager adm, float radius) {
this(adm, radius, 0.1f);
public Ground(AudioDataManager adm, GameSettings settings, float radius) {
this(adm, settings, radius, 0.1f);
}
public Ground(AudioDataManager adm, float radius, float factor) {
public Ground(AudioDataManager adm, GameSettings settings, float radius, float factor) {
super("Ground");
generateHexGrid(adm, radius, factor);
ground = generateHexGrid(adm, radius, factor);
sky = generateHexGrid(adm, radius, factor);
sky.rotate(0f, 0f, MathHelper.degreeToRadian(180f));
sky.move(0f, settings.getVideoHeight() + 200f, 0f);
this.attachChild(ground);
this.attachChild(sky);
addLight();
}
//TODO cleanup
private void generateHexGrid(AudioDataManager adm, float borderWidth, float factor) {
private Node generateHexGrid(AudioDataManager adm, float borderWidth, float factor) {
float size = borderWidth * factor;
int maxIterations = (int) (borderWidth / size) - 2;
Node node = new Node("hexGrid");
Node prism = new GlowingHexPrism(new Vector3f(0f, -140f, 0f), size, 150f, 0.8f, adm);
prism.addControl(new GroundMoveControl(adm));
this.attachChild(prism);
node.attachChild(prism);
float xcc = 0f;
float ycc = 0f;
@ -74,12 +87,12 @@ public class Ground extends Node {
hex.setMaterial(Materials.HEX.create());
hex.setLocalTranslation(new Vector3f(xc, 0f, yc));
hex.addControl(new GroundBorderGlowControl(adm));
this.attachChild(hex);
node.attachChild(hex);
} else {
prism = new GlowingHexPrism(new Vector3f(xc, -140f, yc), size,
150f, 0.8f, adm);
prism.addControl(new GroundMoveControl(adm));
this.attachChild(prism);
node.attachChild(prism);
}
xc = xc + dx;
yc = yc + dy;
@ -90,6 +103,7 @@ public class Ground extends Node {
dy = dyn;
}
}
return node;
}
private void addLight() {

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.game;
import uk.co.caprica.vlcj.binding.internal.libvlc_media_t;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventListener;
/**
*
* @author Darth Affe
*/
public class MediaPlayerEventListenerBase implements MediaPlayerEventListener {
public void mediaChanged(MediaPlayer mp, libvlc_media_t l, String string) {
}
public void opening(MediaPlayer mp) {
}
public void buffering(MediaPlayer mp, float f) {
}
public void playing(MediaPlayer mp) {
}
public void paused(MediaPlayer mp) {
}
public void stopped(MediaPlayer mp) {
}
public void forward(MediaPlayer mp) {
}
public void backward(MediaPlayer mp) {
}
public void finished(MediaPlayer mp) {
}
public void timeChanged(MediaPlayer mp, long l) {
}
public void positionChanged(MediaPlayer mp, float f) {
}
public void seekableChanged(MediaPlayer mp, int i) {
}
public void pausableChanged(MediaPlayer mp, int i) {
}
public void titleChanged(MediaPlayer mp, int i) {
}
public void snapshotTaken(MediaPlayer mp, String string) {
}
public void lengthChanged(MediaPlayer mp, long l) {
}
public void videoOutput(MediaPlayer mp, int i) {
}
public void error(MediaPlayer mp) {
}
public void mediaMetaChanged(MediaPlayer mp, int i) {
}
public void mediaSubItemAdded(MediaPlayer mp, libvlc_media_t l) {
}
public void mediaDurationChanged(MediaPlayer mp, long l) {
}
public void mediaParsedChanged(MediaPlayer mp, int i) {
}
public void mediaFreed(MediaPlayer mp) {
}
public void mediaStateChanged(MediaPlayer mp, int i) {
}
public void newMedia(MediaPlayer mp) {
}
public void subItemPlayed(MediaPlayer mp, int i) {
}
public void subItemFinished(MediaPlayer mp, int i) {
}
public void endOfSubItems(MediaPlayer mp) {
}
}

View File

@ -19,9 +19,11 @@ package org.wyrez.shootingstars.game;
import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;
import com.jme3.light.AmbientLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
@ -102,7 +104,7 @@ public class Player extends Node {
weaponContainer.rotate(MathHelper.degreeToRadian(-10f), MathHelper.degreeToRadian(10f), MathHelper.degreeToRadian(-5f));
weaponContainer.move(-0.41f, -0.28f, 9f);
weaponContainer.scale(0.75f);
this.attachChild(weaponContainer);

View File

@ -32,6 +32,7 @@ import org.wyrez.shootingstars.factories.Particles;
import org.wyrez.shootingstars.game.Cinema;
import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.game.Ground;
import org.wyrez.shootingstars.game.MediaPlayerEventListenerBase;
import org.wyrez.shootingstars.game.Player;
import org.wyrez.shootingstars.game.StarManager;
import org.wyrez.shootingstars.gui.GameGUI;
@ -40,6 +41,7 @@ import org.wyrez.shootingstars.helper.ScreenHelper;
import org.wyrez.shootingstars.helper.UserDataKeys;
import org.wyrez.shootingstars.states.util.OptionSettings;
import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
@ -69,6 +71,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
private Ground ground;
private Node player;
private boolean isRunning = false;
private boolean isFinished = false;
public GameState(Node rootNode, Screen screen, StateManager stateManager,
AssetManager assetManager, ViewPort viewPort, OptionSettings options,
@ -89,12 +92,12 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
this.settings = settings;
Particles.setParticleDensity(options.getParticleDensity());
}
public void loadGround() {
ground = new Ground(audioDataManager, FIELD_RADIUS);
ground = new Ground(audioDataManager, settings, FIELD_RADIUS);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
viewPort.addProcessor(fpp);
@ -104,6 +107,12 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(),
settings.getVideoWidth(), settings.getVideoHeight(),
settings.getVideoWidth() * settings.getVideoDepth(), cinema);
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventListenerBase() {
@Override
public void finished(MediaPlayer mp) {
isFinished = true;
}
});
mediaPlayer.prepareMedia(settings.getVideoFile());
}
@ -167,6 +176,9 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
audioDataManager.update(tpf);
starManager.update(tpf);
}
if (isFinished) {
finished();
}
}
@Override
@ -192,13 +204,22 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("ESC") && !isPressed) {
setRunning(false);
mediaPlayer.pause();
inputManager.setCursorVisible(true);
gui.showMenu();
if (isRunning) {
pause();
} else {
resume();
}
}
}
public void pause() {
setRunning(false);
player.setUserData(UserDataKeys.SHOOTING, false);
mediaPlayer.pause();
inputManager.setCursorVisible(true);
gui.showMenu();
}
public void resume() {
gui.resumeGame();
inputManager.setCursorVisible(false);
@ -206,6 +227,10 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
setRunning(true);
}
public void finished() {
stateManager.setState(State.HIGHSCORE);
}
public void cancelTrack() {
stateManager.setState(State.MENU);
}