gangwaytile.java.svn-base

来自「一个JAVA程序员的游戏」· SVN-BASE 代码 · 共 96 行

SVN-BASE
96
字号
/*
 * GangwayTile.java
 *
 * Created on 26. Dezember 2006, 22:07
 *
 * 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.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.shape.Cylinder;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.LightState;
import com.jme.scene.state.RenderState;
import java.util.HashMap;
import java.util.Map;

/**
 * Provides the "handles" on both sides of a "gangway".
 * @author Pirx
 */
public class GangwayTile extends AbstractTile implements Tile {
    
    public enum Type {NS, OW};
    
    private static final float COORDS_H[][] = new float[][]{{1,-0.3f},{1, -0.6f}, {-1,-0.3f},{-1, -0.6f}};
    private static final float COORDS_V[][] = new float[][]{{1,-0.8f},{1, 0.8f}, {-1,-0.8f},{-1, 0.8f}};
    
    private static final String TYPE = "type";
    private Type type;
    
    /** Creates a new instance of GangwayTile */
    public GangwayTile(String name, Type type) {
        super(name);
        this.type = type;
    }
    
    public GangwayTile() {
    }
    
    public void init() {
        node = new Node("GangwayTile");
        
        RenderState mat = getMaterialState(new ColorRGBA(0.1f,0.1f,0.1f,1));
        RenderState tex = loadTexture("data/bot_pole.png");
        
        Cylinder cylH= new Cylinder("cyl", 3, 6 , 0.01f, 2, true);
        cylH.setRenderState(mat);
        cylH.setRenderState(tex);
        cylH.setModelBound(new BoundingBox());
        cylH.updateModelBound();
        for (int i = 0; i < 4; i++) {
            SharedMesh mesh = new SharedMesh("cylH", cylH);
            mesh.setLocalTranslation(new Vector3f(COORDS_H[i][0], COORDS_H[i][1], 0));
            node.attachChild(mesh);
        }        
        Cylinder cylV= new Cylinder("cyl", 3, 6 , 0.01f, 0.7f, true);
        cylV.setRenderState(mat);
        cylV.setRenderState(tex);
        cylV.setModelBound(new BoundingBox());
        cylV.updateModelBound();
        Matrix3f cRotMatrix = new Matrix3f();
        cRotMatrix.fromAngleAxis(FastMath.PI/2, new Vector3f(1,0,0));
        cylV.setLocalRotation(cRotMatrix);
        for (int i = 0; i < 4; i++) {
            SharedMesh mesh = new SharedMesh("cylV", cylV);
            mesh.setLocalTranslation(new Vector3f(COORDS_V[i][0], -0.65f, COORDS_V[i][1]));
            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) {
        type = Type.valueOf(map.get(TYPE));
    }

    public Map<String, String> getParams() {
        Map<String, String> map = new HashMap<String, String>();
        map.put(TYPE, type.toString());
        return map;
    }    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?