improved material handling
This commit is contained in:
parent
62122dcb7e
commit
a056861e75
@ -44,7 +44,6 @@ public class GroundBorderGlowControl extends BaseControl {
|
||||
public void setSpatial(Spatial spatial) {
|
||||
super.setSpatial(spatial);
|
||||
this.material = ((Geometry) spatial).getMaterial();
|
||||
this.material.setColor("GlowColor", ColorRGBA.Black);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -46,7 +46,6 @@ public class GroundGlowControl extends BaseControl {
|
||||
public void setSpatial(Spatial spatial) {
|
||||
super.setSpatial(spatial);
|
||||
this.material = ((Geometry) spatial).getMaterial();
|
||||
this.material.setColor("GlowColor", ColorRGBA.Black);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -26,13 +26,13 @@ import org.wyrez.shootingstars.helper.UserDataKeys;
|
||||
* @author Darth Affe
|
||||
*/
|
||||
public class PlayerCamControl extends BaseControl {
|
||||
|
||||
|
||||
private Camera camera;
|
||||
|
||||
|
||||
public PlayerCamControl(Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
if (spatial.getUserData(UserDataKeys.RUNNING)) {
|
||||
@ -40,7 +40,7 @@ public class PlayerCamControl extends BaseControl {
|
||||
camera.setRotation(spatial.getLocalRotation());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Control cloneForSpatial(Spatial spatial) {
|
||||
PlayerCamControl control = new PlayerCamControl(camera);
|
||||
control.setSpatial(spatial);
|
||||
|
||||
@ -86,7 +86,7 @@ public class PlayerShootControl extends BaseControl implements ActionListener {
|
||||
}
|
||||
|
||||
public void onAction(String name, boolean isPressed, float tpf) {
|
||||
if (name.equals(MAPPING_PLAYER_MOUSE_LEFT_CLICK)) {
|
||||
if (name.equals(MAPPING_PLAYER_MOUSE_LEFT_CLICK) && (Boolean) spatial.getUserData(UserDataKeys.RUNNING)) {
|
||||
if (isPressed) {
|
||||
setShooting(true);
|
||||
} else {
|
||||
|
||||
@ -18,6 +18,7 @@ package org.wyrez.shootingstars.factories;
|
||||
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -25,16 +26,21 @@ import com.jme3.material.Material;
|
||||
*/
|
||||
public enum Materials {
|
||||
|
||||
UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null),
|
||||
HEX("Common/MatDefs/Light/Lighting.j3md", "Textures/Hex.png"),
|
||||
GLOW("Common/MatDefs/Light/Lighting.j3md", null);
|
||||
UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null, null, null),
|
||||
HEX("Common/MatDefs/Light/Lighting.j3md", "Textures/Hex.png", null, null),
|
||||
WEAPON("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Cyan),
|
||||
GLOW("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Black);
|
||||
private static AssetManager assetManager;
|
||||
private String material;
|
||||
private String texture;
|
||||
private ColorRGBA color;
|
||||
private ColorRGBA glowColor;
|
||||
|
||||
Materials(String material, String texture) {
|
||||
Materials(String material, String texture, ColorRGBA color, ColorRGBA glowColor) {
|
||||
this.material = material;
|
||||
this.texture = texture;
|
||||
this.color = color;
|
||||
this.glowColor = glowColor;
|
||||
}
|
||||
|
||||
public Material create() {
|
||||
@ -42,6 +48,12 @@ public enum Materials {
|
||||
if (texture != null) {
|
||||
mat.setTexture("DiffuseMap", assetManager.loadTexture(texture));
|
||||
}
|
||||
if (color != null) {
|
||||
mat.setColor("Diffuse", color);
|
||||
}
|
||||
if (color != null) {
|
||||
mat.setColor("GlowColor", glowColor);
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,6 @@ public class GlowingHexPrism extends Node {
|
||||
this.attachChild(prism);
|
||||
|
||||
Material glowMat = Materials.GLOW.create();
|
||||
glowMat.setColor("Diffuse", ColorRGBA.White);
|
||||
glow = new Geometry("Prism " + position, new HexPrism(position.add(
|
||||
0f, height, 0f), size * glowPercentage, height * 0.001f));
|
||||
glow.setMaterial(glowMat);
|
||||
|
||||
@ -22,10 +22,9 @@ import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import org.wyrez.shootingstars.data.AudioDataManager;
|
||||
import org.wyrez.shootingstars.controls.GroundBorderGlowControl;
|
||||
import org.wyrez.shootingstars.controls.GroundGlowControl;
|
||||
import org.wyrez.shootingstars.controls.GroundMoveControl;
|
||||
import org.wyrez.shootingstars.data.AudioDataManager;
|
||||
import org.wyrez.shootingstars.factories.Materials;
|
||||
import org.wyrez.shootingstars.mesh.HexPrism;
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ import org.wyrez.shootingstars.controls.PlayerCamControl;
|
||||
import org.wyrez.shootingstars.controls.PlayerMouseControl;
|
||||
import org.wyrez.shootingstars.controls.PlayerMoveControl;
|
||||
import org.wyrez.shootingstars.controls.PlayerShootControl;
|
||||
import org.wyrez.shootingstars.controls.WeaponProjectileControl;
|
||||
import org.wyrez.shootingstars.factories.Materials;
|
||||
import org.wyrez.shootingstars.game.Cinema;
|
||||
import org.wyrez.shootingstars.game.GameSettings;
|
||||
@ -67,6 +68,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
private Cinema cinema;
|
||||
private Ground ground;
|
||||
private Spatial player;
|
||||
private Spatial weapon;
|
||||
private boolean isRunning = false;
|
||||
|
||||
public GameState(Node rootNode, Screen screen, StateManager stateManager,
|
||||
@ -112,10 +114,15 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
player = new Geometry("player", new Box(Vector3f.ZERO, 1f, 1f, 1f)); //TODO start location?
|
||||
player.setMaterial(Materials.UNSHADED.create());
|
||||
player.setUserData(UserDataKeys.RUNNING, false);
|
||||
player.setUserData(UserDataKeys.SHOOTING, false);
|
||||
player.addControl(new PlayerMouseControl(inputManager, camera));
|
||||
player.addControl(new PlayerMoveControl(audioDataManager));
|
||||
player.addControl(new PlayerShootControl(inputManager, gui));
|
||||
player.addControl(new PlayerCamControl(camera));
|
||||
|
||||
weapon = new Geometry("weapon", new Box(0.01f, 0.01f, 2f));
|
||||
weapon.addControl(new WeaponProjectileControl(rootNode, player));
|
||||
weapon.setMaterial(Materials.WEAPON.create());
|
||||
}
|
||||
|
||||
private void setRunning(boolean running) {
|
||||
@ -135,6 +142,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
rootNode.attachChild(cinema);
|
||||
rootNode.attachChild(ground);
|
||||
rootNode.attachChild(player);
|
||||
rootNode.attachChild(weapon);
|
||||
gui.setWait();
|
||||
gui.attach();
|
||||
}
|
||||
@ -142,6 +150,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
@Override
|
||||
public void stateDetached(AppStateManager stateManager) {
|
||||
gui.detach();
|
||||
rootNode.detachChild(weapon);
|
||||
rootNode.detachChild(player);
|
||||
rootNode.detachChild(ground);
|
||||
rootNode.detachChild(cinema);
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.wyrez.shootingstars.states;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
import org.wyrez.shootingstars.ShootingStars;
|
||||
@ -47,8 +46,9 @@ public class MenuState extends AbstractAppState implements MenuListener {
|
||||
|
||||
public void exitGame() {
|
||||
shootingStars.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
public void openhighscore() {
|
||||
stateManager.setState(State.HIGHSCORE);
|
||||
}
|
||||
@ -66,8 +66,4 @@ public class MenuState extends AbstractAppState implements MenuListener {
|
||||
public void stateDetached(AppStateManager stateManager) {
|
||||
gui.detach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user