Hi Guys,
Please I need your help with making my button work. I have done everything possible to make it work, all to no avail. I will so appreciate your help.
My main class:
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
import com.jme3.collision.CollisionResults;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.input.MouseInput;
import com.jme3.input.RawInputListener;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.input.controls.Trigger;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.input.event.TouchEvent;
import com.jme3.light.AmbientLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Ray;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.Sphere;
import com.jme3.system.AppSettings;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;
import de.lessvoid.nifty.Nifty;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.LinkedList;
import javax.imageio.ImageIO;
/**
-
test
-
@author normenhansen
*/
public class Main extends SimpleApplication {//general objects
private Spatial sceneModel;
private Node ayo; //base node
private float xTopPos = -2.0f; //x cordinate constant//holes objects
private Geometry hole1;
private Geometry hole2;
private Geometry hole3;
private Geometry hole4;
private Geometry hole5;
private Geometry hole6;
private Geometry hole7;
private Geometry hole8;
private Geometry hole9;
private Geometry hole10;private Geometry target;
private Geometry selectedTarget; //selcted targetNifty nifty;
//Fire emitter
ParticleEmitter hole1_fire;
ParticleEmitter hole2_fire;
ParticleEmitter hole3_fire;
ParticleEmitter hole4_fire;
ParticleEmitter hole5_fire;
ParticleEmitter hole6_fire;
ParticleEmitter hole7_fire;
ParticleEmitter hole8_fire;
ParticleEmitter hole9_fire;
ParticleEmitter hole10_fire;//seed holders for all the holes
LinkedList<String> hole1_seeds_holder = new LinkedList<String>();
LinkedList<String> hole2_seeds_holder = new LinkedList<String>();
LinkedList<String> hole3_seeds_holder = new LinkedList<String>();
LinkedList<String> hole4_seeds_holder = new LinkedList<String>();
LinkedList<String> hole5_seeds_holder = new LinkedList<String>();
LinkedList<String> hole6_seeds_holder = new LinkedList<String>();
LinkedList<String> hole7_seeds_holder = new LinkedList<String>();
LinkedList<String> hole8_seeds_holder = new LinkedList<String>();
LinkedList<String> hole9_seeds_holder = new LinkedList<String>();
LinkedList<String> hole10_seeds_holder = new LinkedList<String>();//selected balls
LinkedList<String> selectedBalls = new LinkedList<String>();//ROWS
Geometry[] first_row_holes;
Geometry[] second_row_holes;//DIRECTIONS
private static final int LEFT_DIRECTION = 1;
private static final int RIGHT_DIRECTION = 2;
private static final int UP_DIRECTION = 3;
private static final int DOWN_DIRECTION = 4;//check if a hole was selected
private boolean selected = false;//GUI Design
private Picture cursor;//Game State
private static int computerScore = 0; //computer’s score
private static int playerScore = 0; //player’s score
private boolean comTurn = false; //computer’s turn
private String player = null; //active player//sound object
private AudioNode nature;
private AudioNode clickAudio;//input trigger for the holes
private final static Trigger TRIGGER_PLAY = new MouseButtonTrigger(MouseInput.BUTTON_LEFT);
private final static String MAPPING_PLAY = “Trigger Play”; //Action Mapping//redesigned cursor
private RawInputListener inputListener = new RawInputListener() {private float x = 0, y = 0; public void beginInput() { } public void endInput() { } public void onJoyAxisEvent(JoyAxisEvent evt) { } public void onJoyButtonEvent(JoyButtonEvent evt) { } public void onMouseMotionEvent(MouseMotionEvent evt) { x += evt.getDX(); y += evt.getDY(); // Prevent mouse from leaving screen AppSettings settings = Main.this.settings; x = FastMath.clamp(x, 0, settings.getWidth()); y = FastMath.clamp(y, 0, settings.getHeight()); // adjust for hotspot cursor.setPosition(x, y - 64); } public void onMouseButtonEvent(MouseButtonEvent evt) { } public void onKeyEvent(KeyInputEvent evt) { } public void onTouchEvent(TouchEvent evt) { }
};
public static void main(String[] args) {
Main app = new Main();
AppSettings settings = new AppSettings(true);
settings.setWidth(840);
settings.setTitle(“Mancala Official”);
app.setDisplayStatView(false);//set icon try { settings.setIcons(new BufferedImage[]{ ImageIO.read(new File("assets/Interface/icons/icon-1.png")), ImageIO.read(new File("assets/Interface/icons/icon-2.png")), ImageIO.read(new File("assets/Interface/icons/icon-3.png")), ImageIO.read(new File("assets/Interface/icons/icon-4.png")) }); } catch(Exception e) { e.printStackTrace(); } settings.useInput(); app.setSettings(settings); app.start();
}
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
viewPort.setBackgroundColor(ColorRGBA.BlackNoAlpha);//play sound nature = new AudioNode(assetManager, "Sounds/gladiator-battle-1.ogg", true); nature.setLooping(true); nature.setVolume(1); nature.play(); //hole click sound clickAudio = new AudioNode(assetManager,"Sounds/cartoon085.wav"); //fire emmit effect hole1_fire = initFireEmitter("Hole1 Fire"); hole2_fire = initFireEmitter("Hole2 Fire"); hole3_fire = initFireEmitter("Hole3 Fire"); hole4_fire = initFireEmitter("Hole4 Fire"); hole5_fire = initFireEmitter("Hole5 Fire"); hole6_fire = initFireEmitter("Hole6 Fire"); hole7_fire = initFireEmitter("Hole7 Fire"); hole8_fire = initFireEmitter("Hole8 Fire"); hole9_fire = initFireEmitter("Hole9 Fire"); hole10_fire = initFireEmitter("Hole10 Fire"); //add the designed cursor to the scene Texture tex = assetManager.loadTexture("Interface/Cursor.png"); cursor = new Picture("cursor"); cursor.setTexture(assetManager, (Texture2D) tex, true); cursor.setWidth(37); cursor.setHeight(79); guiNode.attachChild(cursor); inputManager.addRawInputListener(inputListener); cam.setLocation(new Vector3f(0.0f, 0.0f, 10.0f)); flyCam.setMoveSpeed(50f); //initScene(); //initialize scene initBox(); ayoLine(); //line seperator initStaple(new Vector3f(-1.5f, 0.00f, 5.0f)); initStaple(new Vector3f(1.5f, 0.00f, 5.0f)); initLight(); //initialize balls initBalls(hole1); //hole 1 balls initBalls(hole2); //hole 2 balls initBalls(hole3); //hole 3 balls initBalls(hole4); //hole 4 balls initBalls(hole5); //hole 5 balls initBalls(hole6); //hole 6 balls initBalls(hole7); //hole 7 balls initBalls(hole8); //hole 8 balls initBalls(hole9); //hole 9 balls initBalls(hole10); //hole 10 balls //populate holes in a row first_row_holes = new Geometry[]{hole1, hole2, hole3, hole4, hole5}; //first row second_row_holes = new Geometry[]{hole6, hole7, hole8, hole9, hole10}; //second row //initialize statemenager AyoStartScreen state = new AyoStartScreen(); //state.initialize(stateManager, this); stateManager.attach(state); callNiftyGui(state); //gui display //callHudNiftyGui(state); //hud screeen //set cursor visible inputManager.setCursorVisible(true); //Register Mapping inputManager.addMapping(MAPPING_PLAY, TRIGGER_PLAY); //Register Listeners inputManager.addListener(actionListener, new String[]{MAPPING_PLAY});
}
//input Listener
private ActionListener actionListener = new ActionListener()
{public void onAction(String name, boolean isPressed, float tpf) { if(name.equals(MAPPING_PLAY) && isPressed) { CollisionResults results = new CollisionResults(); Vector2f click2d = inputManager.getCursorPosition(); Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0f); Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f). subtractLocal(click3d); Ray ray = new Ray(click3d, dir); rootNode.collideWith(ray, results); if(results.size() != 0) { target = results.getClosestCollision().getGeometry(); } if(results.size() > 0 && !("Box".equals(target.getName()))) { if(target.getName().equals("Hole6") && selected == false) { //check if the balls holder is not empty if(!(hole6_seeds_holder.isEmpty())) { //play sound clickAudio.play(); float x = target.getLocalTranslation().getX(); //x coordinate float y = target.getLocalTranslation().getY(); //y coordinate float z = target.getLocalTranslation().getZ(); //x coordinate hole6_fire.setLocalTranslation(new Vector3f(x, y, z)); //remove hole1 fire if(!(rootNode.hasChild(hole6_fire))) { rootNode.attachChild(hole6_fire); deselectHole(hole6_fire); } //set player setPlayer("Player"); selected = true; selectedTarget = (Geometry) target; } if((hole6_seeds_holder.isEmpty())) { selected = false; } } if(target.getName().equals("Hole7") && selected == false) { //play sound clickAudio.play(); float x = target.getLocalTranslation().getX(); //x coordinate float y = target.getLocalTranslation().getY(); //y coordinate float z = target.getLocalTranslation().getZ(); //x coordinate hole7_fire.setLocalTranslation(new Vector3f(x, y, z)); //remove hole1 fire if(!(rootNode.hasChild(hole7_fire))) { rootNode.attachChild(hole7_fire); deselectHole(hole7_fire); } System.out.println(rootNode.getChildren()); } if(target.getName().equals("Hole8") && selected == false) { //play sound clickAudio.play(); float x = target.getLocalTranslation().getX(); //x coordinate float y = target.getLocalTranslation().getY(); //y coordinate float z = target.getLocalTranslation().getZ(); //x coordinate hole8_fire.setLocalTranslation(new Vector3f(x, y, z)); //remove hole1 fire if(!(rootNode.hasChild(hole8_fire))) { rootNode.attachChild(hole8_fire); deselectHole(hole8_fire); } System.out.println(rootNode.getChildren()); } if(target.getName().equals("Hole9") && selected == false) { //play sound clickAudio.play(); float x = target.getLocalTranslation().getX(); //x coordinate float y = target.getLocalTranslation().getY(); //y coordinate float z = target.getLocalTranslation().getZ(); //x coordinate hole9_fire.setLocalTranslation(new Vector3f(x, y, z)); //remove hole1 fire if(!(rootNode.hasChild(hole9_fire))) { rootNode.attachChild(hole9_fire); deselectHole(hole9_fire); } System.out.println(rootNode.getChildren()); } if(target.getName().equals("Hole10") && selected == false) { //play sound clickAudio.play(); float x = target.getLocalTranslation().getX(); //x coordinate float y = target.getLocalTranslation().getY(); //y coordinate float z = target.getLocalTranslation().getZ(); //x coordinate hole10_fire.setLocalTranslation(new Vector3f(x, y, z)); //remove hole1 fire if(!(rootNode.hasChild(hole10_fire))) { rootNode.attachChild(hole10_fire); deselectHole(hole10_fire); } System.out.println(rootNode.getChildren()); } } else { System.out.println("Empty"); } } }
};
private AnalogListener analogListener = new AnalogListener()
{public void onAnalog(String name, float value, float tpf) { System.out.println("Triggered the action: " + name); }
};
//deselect holes
private void deselectHole(ParticleEmitter name)
{
ParticleEmitter[] particles = new ParticleEmitter[]{
hole1_fire,
hole2_fire,
hole3_fire,
hole4_fire,
hole5_fire,
hole6_fire,
hole7_fire,
hole8_fire,
hole9_fire,
hole10_fire
};
for(int i = 0; i < particles.length; i++)
{
if(name.equals(particles[i]))
continue;
else
{
if(rootNode.hasChild(particles[i]))
rootNode.detachChild(particles[i]);
}
}
}@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
if(selected && player.equals(“Player”))
{
pickBalls();
}if(comTurn && player.equals("Computer")) { //check if it has won //else //randomly select hole //drop balls in anti-clockwise direction //update score }
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}private ParticleEmitter initFireEmitter(String name)
{
/** Uses Texture from jme3-test-data library! */
Material fireMat = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);
ParticleEmitter fireEffect = new ParticleEmitter(name, ParticleMesh.Type.Triangle, 10);
fireEffect.setMaterial(fireMat);
fireEffect.setImagesX(1); fireEffect.setImagesY(1); // 2x2 texture animation
fireEffect.setEndColor( new ColorRGBA(1f, 0f, 0f, 1f) ); // red
fireEffect.setStartColor( new ColorRGBA(1f, 1f, 0f, 0.5f) ); // yellow
fireEffect.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
fireEffect.setStartSize(0.2f);
fireEffect.setEndSize(0.1f);
fireEffect.setGravity(0f,0f,0f);
fireEffect.setLowLife(0.5f);
fireEffect.setHighLife(3f);
fireEffect.getParticleInfluencer().setVelocityVariation(0.3f);//return fire effect return fireEffect;
}
private void initBox()
{
Box b = new Box(4, 2, 2);
Geometry geom = new Geometry(“Box”, b);Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap",assetManager.loadTexture("Interface/Free-Wood-Texture-48.jpg")); geom.setMaterial(mat); //create parent node ayo = new Node("Ayo Game"); ayo.attachChild(geom); //attach five top holes hole1 = (Geometry) initCylinders("Hole1", xTopPos, 0.65f, 5.0f); ayo.attachChild(hole1); hole2 = (Geometry) initCylinders("Hole2", xTopPos + 1.0f, 0.65f, 5.0f); ayo.attachChild(hole2); hole3 = (Geometry) initCylinders("Hole3", xTopPos + 2.0f, 0.65f, 5.0f); ayo.attachChild(hole3); hole4 = (Geometry) initCylinders("Hole4", xTopPos + 3.0f, 0.65f, 5.0f); ayo.attachChild(hole4); hole5 = (Geometry) initCylinders("Hole5", xTopPos + 4.0f, 0.65f, 5.0f); ayo.attachChild(hole5); hole6 = (Geometry) initCylinders("Hole6", xTopPos, -0.65f, 5.0f); ayo.attachChild(hole6); hole7 = (Geometry) initCylinders("Hole7", xTopPos + 1.0f, -0.65f, 5.0f); ayo.attachChild(hole7); hole8 = (Geometry) initCylinders("Hole8", xTopPos + 2.0f, -0.65f, 5.0f); ayo.attachChild(hole8); hole9 = (Geometry) initCylinders("Hole9", xTopPos + 3.0f, -0.65f, 5.0f); ayo.attachChild(hole9); hole10 = (Geometry) initCylinders("Hole10", xTopPos + 4.0f, -0.65f, 5.0f); ayo.attachChild(hole10); rootNode.attachChild(ayo);
}
private Geometry initCylinders(String name, float x, float y, float z)
{
Vector3f v = new Vector3f(x, y, z);
Cylinder t = new Cylinder(5, 40, 1, 0, true);
Geometry geom2 = new Geometry(name, t);
geom2.setLocalTranslation(v);
geom2.setLocalScale(0.35f);
Material mat2 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat2.setTexture(“ColorMap”,assetManager.loadTexture(“Interface/wood.jpg”));
geom2.setMaterial(mat2);//return geometry return geom2;
}
private void ayoLine()
{
Box line = new Box(4.9f, 0.02f, 0.2f);
Geometry ayoGeom = new Geometry(“Ayo Line”, line);
Material lineMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
lineMat.setColor(“Color”, ColorRGBA.DarkGray);
ayoGeom.setMaterial(lineMat);
ayoGeom.setLocalTranslation(new Vector3f(0.0f, 0.0f, 6.0f));
ayoGeom.setLocalScale(0.4f);//attach to the rootNode ayo.attachChild(ayoGeom);
}
private void initStaple(Vector3f loc)
{
Box staple = new Box(0.2f, 0.07f, 0.0f);
Geometry stapleGeom = new Geometry(“Staple”, staple);
Texture stapleTexture = assetManager.loadTexture(“Interface/staple.png”);
Material stapleMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
stapleMat.setTexture(“ColorMap”, stapleTexture);
stapleGeom.setMaterial(stapleMat);
stapleGeom.setLocalTranslation(loc);ayo.attachChild(stapleGeom);
}
private void initAyoBall(String name, Vector3f v)
{
Sphere s = new Sphere(22, 22, 1);
Material mat3 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);Geometry geom3 = new Geometry(name, s); geom3.setLocalTranslation(v); geom3.setLocalScale(0.06f); mat3.setTexture("ColorMap",assetManager.loadTexture("Interface/ball.png")); geom3.setMaterial(mat3); ayo.attachChild(geom3);
}
//test random numbers
public static float randInRangeInc(float min, float max) {
return min + (float) (Math.random() * (max - min));
}private void initBalls(Geometry hole)
{
float x = hole.getLocalTranslation().getX() - 0.19f;
float y = hole.getLocalTranslation().getY() - 0.2f;
float z = hole.getLocalTranslation().getZ() + randInRangeInc(0.1f, 0.4f);if(hole.equals(hole1)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole1_ball " + i, v); //add to holder hole1_seeds_holder.add("hole1_ball " + i); } } if(hole.equals(hole2)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole2_ball " + i, v); //add to holder hole2_seeds_holder.add("hole2_ball " + i); } } if(hole.equals(hole3)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole3_ball " + i, v); //add to holder hole3_seeds_holder.add("hole3_ball " + i); } } if(hole.equals(hole4)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole4_ball " + i, v); //add to holder hole4_seeds_holder.add("hole4_ball " + i); } } if(hole.equals(hole5)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole5_ball " + i, v); //add to holder hole5_seeds_holder.add("hole5_ball " + i); } } if(hole.equals(hole6)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole6_ball " + i, v); //add to holder hole6_seeds_holder.add("hole6_ball " + i); } } if(hole.equals(hole7)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole7_ball " + i, v); //add to holder hole7_seeds_holder.add("hole7_ball " + i); } } if(hole.equals(hole8)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole8_ball " + i, v); //add to holder hole8_seeds_holder.add("hole8_ball " + i); } } if(hole.equals(hole9)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole9_ball " + i, v); //add to holder hole9_seeds_holder.add("hole9_ball " + i); } } if(hole.equals(hole10)) { //populate for(int i = 1; i <= 4; i++) { Vector3f v; //add balls to linkedlist holder v = new Vector3f(randInRangeInc((x + 0.1f), (x + 0.3f)), randInRangeInc(y, (y + 0.3f)) + 0.06f, z + 0.03f); initAyoBall("hole10_ball " + i, v); //add to holder hole10_seeds_holder.add("hole10_ball " + i); } }
}
private void initScene()
{
sceneModel = assetManager.loadModel(“Scenes/Scene.j3o”);
rootNode.attachChild(sceneModel);
}private void initLight()
{
/** A white ambient light source. */
AmbientLight ambient = new AmbientLight();
ambient.setColor(ColorRGBA.White);
rootNode.addLight(ambient);
}public void callNiftyGui(AyoStartScreen startScreen)
{
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,inputManager,audioRenderer,guiViewPort);
//create nifty gui object
nifty = niftyDisplay.getNifty();
//read screen.xml file
nifty.fromXml(“Interface/screen.xml”, “start”, startScreen);
//attach to the gui viewport as a processor
guiViewPort.addProcessor(niftyDisplay);
}//hud screen
public void callHudNiftyGui(AyoStartScreen hudScreen)
{
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,inputManager,audioRenderer,guiViewPort);
//create nifty gui object
nifty = niftyDisplay.getNifty();
//read screen.xml file
nifty.fromXml(“Interface/screen.xml”, “hud”, hudScreen);
//attach to the gui viewport as a processor
guiViewPort.addProcessor(niftyDisplay);
}/*
-
- ACTION SECTION
-
*/
private void pickBalls()
{
if(selectedTarget.getName().equals(“Hole6”))
{//loop through ball holder for(String name : hole6_seeds_holder) { //remove from list selectedBalls.add(name); } //clear holder hole6_seeds_holder.clear(); removeSelectedBalls(selectedBalls); //remove balls //return handler selected = false; }
}
//testing removal
private void removeSelectedBalls(LinkedList<String> name)
{
for(String n: name)
{
ayo.detachChild(getBallGeometry(n));
}
}//get ball object
private Geometry getBallGeometry(String name)
{
Geometry ballGeometry = (Geometry) ayo.getChild(name);
return ballGeometry;
}//set active player
private void setPlayer(String player)
{
this.player = player;
}//get active player
private String getPlayer()
{
return this.player;
} -
}
[/java]
ScreenController Class:
[java]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package mygame;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyMethodInvoker;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
/**
*
-
@author Upperlink
*/
public class AyoStartScreen extends AbstractAppState implements ScreenController {private Nifty nifty;
private Screen screen;
private SimpleApplication app;@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
this.app = (SimpleApplication) app;
}@Override
public void update(float tpf) {
//TODO: implement behavior during runtime
}@Override
public void cleanup() {super.cleanup();
super.cleanup();
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}public void bind(Nifty nifty, Screen screen) {
System.out.println(“Binded”);
this.nifty = nifty;
this.screen = screen;
}public void onStartScreen() {
Element niftyElement = nifty.getCurrentScreen().findElementByName(“StartButton”);
//niftyElement.getElementInteraction().getPrimary().setOnClickMethod(new NiftyMethodInvoker(nifty, “startGame()”, this));
}public void onEndScreen() {
System.out.println(“Ended”);
}//start game
private void startGame()
{
nifty.gotoScreen(“hud”);
}//quit game
private void quitGame()
{
app.stop();
}
}
[/java]
Xml File:
[java]
<?xml version=“1.0” encoding=“UTF-8”?>
<nifty>
<useStyles filename=“nifty-default-styles.xml” />
<useControls filename=“nifty-default-controls.xml” />
<registerSound id=“myclick” filename=“Interface/sounds/click_one.wav” />
<screen id=“start” controller=“mygame.AyoStartScreen”>
<layer id=“background” childLayout=“center”>
<image filename=“Interface/background.jpg”></image>
</layer>
<layer id=“foreground” childLayout=“vertical”>
<panel id=“panel_top” height=“25%” width=“75%” align=“center” childLayout=“center”>
<image filename=“Interface/logo.png”>
<interact onClick="startGame()"/> NOT WORKING
</image>
</panel>
<panel id="panel_mid" height="50%" width="75%" align="center" childLayout="center">
<text text="Mancala known to be one of the oldest games in the world originating from Africa it is one of the most ancient board games. It is a game that has been played for thousands of years in Africa. The mancala games grants avenues for new research in both mathematics and artificial intelligence. It is identified by peculiar properties the mancala game.The game is played on a board with a number of holes, in some African countries take Kenya for instance a playing board could have up to ten holes, usually arranged in two or more rows. Additional holes are used and they are called stores. The game is played with a pool of equal bean stones and each end of the board belongs to each player. Moves are made by sowing or moving a set of bean stones in an anticlockwise direction dropping a seed at a time in every hole passed, which is also a form of counting. The general aim or goal of the game is to have captured the highest number of playing beans.
" font="Interface/Fonts/Default.fnt" width="100%" height="100%" wrap="true" />
</panel>
<panel id="panel_bottom" height="25%" width="75%" align="center" childLayout="horizontal" >
<panel id="panel_bottom_left" height="50%" width="50%" valign="center" childLayout="center">
<control name="button" label="Start" id="StartButton" align="center" valign="center" visibleToMouse="true">
<effect>
<onClick name="playSound" sound="myclick"/>
</effect>
</control>
</panel>
<panel id="panel_bottom_right" height="50%" width="50%" valign="center" childLayout="center">
<control name="button" label="Quit" id="QuitButton" align="center" valign="center" visibleToMouse="true">
<interact onClick="quitGame()"/>
<effect>
<onClick name="playSound" sound="myclick"/>
</effect>
</control>
</panel>
</panel>
</layer>
</screen>
<screen id=“hud” controller=“mygame.AyoStartScreen”>
<layer id=“background” childLayout=“center”>
</layer>
<layer id="foreground" childLayout="horizontal">
<panel id="panel_left" width="15%" height="100%" childLayout="vertical" padding="270px,0px,0px,0px">
<panel id="panel_top_left1" width="100%" height="15%" childLayout="center">
<control name="label" color="#fff" text="Computer Pot: 123" width="100%" height="100%" />
</panel>
<panel id="panel_top_left2" width="100%" height="15%" childLayout="center">
<image filename="Interface/computer.png"></image>
</panel>
</panel>
<panel id="panel_mid" height="100%" width="70%" align="left" childLayout="vertical" padding="0px,0px,0px,140px">
<panel id="panel_top_mid1" width="100%" height="15%" childLayout="horizontal">
<panel id="panel_top_mid2" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#33af" text="Hole 1: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_top_mid3" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#f008" text="Hole 2: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_top_mid4" width="15%" height="100%" childLayout="center">
<control name="label" color="#000" backgroundColor="#ff8f" text="Hole 3: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_top_mid5" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#0f08" text="Hole 4: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_top_mid6" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#ff4500" text="Hole 5: 123" width="100%" height="100%" />
</panel>
</panel>
<panel id="panel_mid_mid1" width="100%" height="65%" childLayout="center">
</panel>
<panel id="panel_bottom_mid1" width="100%" height="15%" childLayout="horizontal"padding="20px,0px,0px,0px">
<panel id="panel_bottom_mid2" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#33af" text="Hole 1: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_bottom_mid3" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#f008" text="Hole 2: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_bottom_mid4" width="15%" height="100%" childLayout="center">
<control name="label" color="#000" backgroundColor="#ff8f" text="Hole 3: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_bottom_mid5" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#0f08" text="Hole 4: 4 Balls" width="100%" height="100%" />
</panel>
<panel id="panel_bottom_mid6" width="15%" height="100%" childLayout="center">
<control name="label" color="#fff" backgroundColor="#ff4500" text="Hole 5: 123" width="100%" height="100%" />
</panel>
</panel>
</panel>
<panel id="panel_right" width="15%" height="100%" childLayout="vertical" padding="270px,0px,0px,0px">
<panel id="panel_top_right1" width="100%" height="15%" childLayout="center">
<control name="label" color="#fff" text="Player Pot: 123" width="100%" height="100%" />
</panel>
<panel id="panel_top_right2" width="100%" height="15%" childLayout="center">
<image filename="Interface/player.png"></image>
</panel>
<panel id="panel_bot_right" width="100%" height="70%" valign="center" ></panel>
</panel>
</layer>
</screen>
</nifty>
[/java]
I will appreciate your help. Thank you