Hi
I’m working on a Connect 4 online game for my studies.
I’m trying to make an applet with jmonkey to integrate it in the game website.
The applet worked yersteday, but tonight it mysteriously does not want to start, whereas I didn’t make hudge changes in my code.
The webstart doesn’t work too but the .jar and windows .exe runs fine.
I’m a kind of newbie with jMonkey and I really don’t see where the problem is.
Could you help me ?
my whole jme project is here (dist and assets included) :
http://puissance4.olympe-network.com/Power4.zip
And here, just my 3 java classes.
[java]package mygame;
//classes du moteur 3D
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.light.DirectionalLight;
/**
- test
-
@author normenhansen
/
// La classe Power4 herite de la classe Simple application de jMonkey
public class Power4 extends SimpleApplication {
//l’application, à envoyer aux autres objets du puissance 4 lors de leur creation
public static Power4 app;
//grille
protected Grid grid;
protected int count=0;
public static void main(String[] args) {
app = new Power4();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
grid=new Grid( app);
grid.addToken(0,“red”);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
}
@Override
// la methode simpleUpdate est appellée à chaque boucle de l’application
//tpf est un ratio qui varie en fonction du nombre de boucle par seconde
//=>il permet de faire bouger les objets à la meme vitesse quelque soit le fps
public void simpleUpdate(float tpf) {
grid.update(tpf);
if (count<20)
{
if (grid.addToken(count%7,“yellow”)){
count++;}
}
else{
grid.rotate(tpf);
}
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]
[java]/
- To change this template, choose Tools | Templates
- and open the template in the editor.
*
- */
package mygame;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.scene.Node;
import com.jme3.asset.AssetManager;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
/**
*
-
@author Dromadaire fuchia
/
public class Grid{
//modèle 3D de la grille
protected Geometry model;
//variables propres à l’application
protected Node rootNode;
protected AssetManager assetManager;
//tableau de jetons
protected Token[][] tokens= new Token[7][6];
//constante : taille d’une case/2
public final float RADIUS2=0.525f;
//dernier jeton ajouté
protected Token lastToken;
//pivot nécessaire à la rotation de la grille
protected Node node;
//Constructeur
Grid(Power4 app){
//récupération des variables de l’application
rootNode=app.getRootNode();
assetManager=app.getAssetManager();
//Chargement du modèle et de la texture, avec transparence
model = (Geometry) assetManager.loadModel(“Models/test.j3o”);
Material mat2 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
Texture tex = assetManager.loadTexture(“Models/textgrille.png”);
mat2.setTexture(“ColorMap”, tex);
mat2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
model.setMaterial(mat2);
model.move(0,-3f,0);
node=new Node();
node.attachChild(model);
rootNode.attachChild(node);
}
public void update(float tpf){
if (lastToken!=null){
lastToken.update(tpf);
}
}
public boolean rotate(float tpf){
node.rotate(0,tpf,0);
return true;
}
public boolean addToken(int column,String color){
if ((lastToken==null )|| (lastToken.getStopped())){
int i=-1;
while((i<=4)&&(tokens[column][i+1]==null)){
i++;
}
if (i!=-1)
{
tokens[column]=new Token(this,column,i,color);
lastToken=tokens[column];
return true;
}
else
{
return false;
}
}
else return false;
}
public Node getNode(){
return node;
}
public Node getRootNode(){
return rootNode;
}
public AssetManager getAssetManager(){
return assetManager;
}
}
[/java]
[java]/
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package mygame;
import com.jme3.scene.shape.Sphere;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.texture.Texture;
import com.jme3.util.TangentBinormalGenerator;
/**
*
- @author Dromadaire fuchia
/
public class Token {
public final float RADIUS1=0.35f;
public final float RADIUS2=0.525f;
//grille a laquelle appartient le jeton
protected Grid grid;
// couleur du jeton
protected String color;
//modele 3D du jeton
protected Geometry model;
//booléen : est-ce que le jeton a fini de tomber ou pas
protected boolean stopped;
protected int line;
Token(Grid grid, int column, int line, String color){
this.color=color;
this.grid=grid;
this.line=line;
stopped=false;
Sphere s = new Sphere(8,8, RADIUS1);
model= new Geometry(“jeton”, s);
//effets de lumière…
s.setTextureMode(Sphere.TextureMode.Projected);
TangentBinormalGenerator.generate(model);
Material mat_lit = new Material(grid.getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);
mat_lit.setTexture(“DiffuseMap”, grid.getAssetManager().loadTexture(“Textures/Pond.jpg”));
mat_lit.setTexture(“NormalMap”, grid.getAssetManager().loadTexture(“Textures/Pond_normal.png”));
mat_lit.setBoolean(“UseMaterialColors”,true);
if (color==“red”)
{
mat_lit.setColor(“Specular”,new ColorRGBA(1f,0.7f,0.5f,1f));
mat_lit.setColor(“Diffuse”,new ColorRGBA(1f,0.2f,0.2f,1f) );
}
else if (color==“yellow”)
{
mat_lit.setColor(“Specular”,new ColorRGBA(0.9f,0.9f,0.5f,1f));
mat_lit.setColor(“Diffuse”,new ColorRGBA(0.8f,0.7f,0.1f,1f) );
}
else System.err.println(“Erreur : couleur du jeton non conforme”);
mat_lit.setFloat(“Shininess”, 5f); // [1,128]
model.setMaterial(mat_lit);
// Rotate it a bit
model.move(-6RADIUS2+(float)(column2RADIUS2),5RADIUS2,0);
grid.getNode().attachChild(model);
}
public void update(float tpf){
if (!stopped){
if (model.getLocalTranslation().getY()>(5RADIUS2-2lineRADIUS2)){
if (tpf>0.1f){tpf=0.1f;}
model.move(0,(float)-6*tpf,0);
}
else
stopped=true;
}
}
public boolean getStopped(){
return stopped;
}
}
[/java]
PS : I’m sorry for my poor English, it is not my native language.
You can see my french comments in my code