From a056861e7587a0ee4382c2b4b4e0851ab8946405 Mon Sep 17 00:00:00 2001 From: "Raybz@Raybz" Date: Fri, 21 Jun 2013 10:38:43 +0200 Subject: [PATCH] improved material handling --- .../controls/GroundBorderGlowControl.java | 1 - .../controls/GroundGlowControl.java | 1 - .../controls/PlayerCamControl.java | 8 ++++---- .../controls/PlayerShootControl.java | 2 +- .../shootingstars/factories/Materials.java | 20 +++++++++++++++---- .../shootingstars/game/GlowingHexPrism.java | 1 - .../org/wyrez/shootingstars/game/Ground.java | 3 +-- .../wyrez/shootingstars/states/GameState.java | 9 +++++++++ .../wyrez/shootingstars/states/MenuState.java | 8 ++------ 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java index 38700e6..0e5413b 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundBorderGlowControl.java @@ -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 diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java index 3673eac..ccecc6e 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java @@ -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 diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java index 2a64f5d..24854a2 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java @@ -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); diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java index 838cbd5..255e721 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java @@ -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 { diff --git a/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java index 9e4b3fe..459a654 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java +++ b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java @@ -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; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java b/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java index 1d2cdd6..a6cd002 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/GlowingHexPrism.java @@ -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); diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java index 6448b98..f1d1594 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java @@ -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; diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 3d79f8e..f6e36d3 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -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); diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java b/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java index 60d9f6c..49d56ae 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java @@ -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) { - } }