tubetile.java
来自「一个JAVA程序员的游戏」· Java 代码 · 共 100 行
JAVA
100 行
/*
* TubeTile.java
*
* Created on 22. Dezember 2006, 23:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package kanjitori.graphics.tile;
import com.jme.bounding.BoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Vector3f;
import com.jme.scene.Line;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.shape.Cylinder;
import com.jme.scene.shape.Extrusion;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Pirx
*/
public class TubeTile extends AbstractTile {
private static final float[] RADIUS = new float[]{0, 0.8f, 0.4f, 0.3f, 0.2f };
private static final int[] SAMPLES = new int[]{0, 25, 15, 15, 15};
private static final float[][][] COORDS = new float[][][]{
{{}},
{{0, 0}},
{{0.5f, 0.5f}, {-0.5f, -0.5f}},
{{0.4f, -0.6f}, {-0.4f, -0.6f}, {0, 0.5f}},
{{-0.6f, -0.6f}, {-0.6f, 0.6f}, {0.6f, -0.6f}, {0.6f, 0.6f},}
};
private static final String TEXTURE = "tex";
private static final String TUBES = "tubes";
private static final String TYPE = "type";
private String texture;
private int tubes;
private Type type;
public enum Type {NS, OW};
/** Creates a new instance of TubeTile */
public TubeTile(String name, Type type, int tubes, String texture) {
super(name);
this.texture = texture;
this.tubes = tubes;
this.type = type;
}
public TubeTile() {
}
public void init() {
node = new Node("tube");
Cylinder cyl= new Cylinder("cyl", 3, SAMPLES[tubes], RADIUS[tubes], 2, false);
cyl.setRenderState(getMaterialState(null));
cyl.setRenderState(loadTexture(texture));
cyl.setModelBound(new BoundingBox());
cyl.updateModelBound();
for (int i = 0; i < tubes; i++) {
SharedMesh mesh = new SharedMesh("cyl", cyl);
mesh.setLocalTranslation(new Vector3f(COORDS[tubes][i][0], COORDS[tubes][i][1], 0));
node.attachChild(mesh);
}
if (type == Type.OW) {
Matrix3f rotMatrix = new Matrix3f();
rotMatrix.fromAngleAxis(FastMath.PI/2, new Vector3f(0,1,0));
node.setLocalRotation(rotMatrix);
}
}
public void setParams(Map<String, String> map) {
texture = map.get(TEXTURE);
tubes = Integer.parseInt(map.get(TUBES));
type = Type.valueOf(map.get(TYPE));
}
public Map<String, String> getParams() {
Map<String, String> map = new HashMap<String, String>();
map.put(TEXTURE, texture);
map.put(TUBES, "" + tubes);
map.put(TYPE, type.toString());
return map;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?