blocktile.java

来自「一个JAVA程序员的游戏」· Java 代码 · 共 92 行

JAVA
92
字号
/*
 * BlockTile.java
 *
 * Created on 22. Dezember 2006, 21:03
 *
 * 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.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.SharedNode;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Box;
import com.jme.scene.state.RenderState;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Pirx
 */
public class BlockTile extends AbstractMeshTile {
    
    private static final String TEXTURE = "texture";
    private static final String LOW = "low";
    private static final String HIGH = "high";
    
    private String texture;
    private float low;
    private float high;
    private Box block;
    
    /** Creates a new instance of BlockTile */
    public BlockTile(String name, String texture, float low, float high) {
        super(name);
        this.texture = texture;
        this.low = low;
        this.high = high;
    }
    
    public BlockTile(String name, String texture, float high) {
        super(name);
        this.texture = texture;
        this.low = -1;
        this.high = high;
    }
    
    public BlockTile() {
    }
    
    public void init() {
        block = new Box("block", new Vector3f(-1, low, -1), new Vector3f(1, high, 1));
    }

    public void setParams(Map<String, String> map) {
        texture = map.get(TEXTURE);
        low = Float.parseFloat(map.get(LOW));
        high = Float.parseFloat(map.get(HIGH));
    }

    public Map<String, String> getParams() {
        Map<String, String> map = new HashMap<String, String>();
        map.put(TEXTURE, texture);
        map.put(LOW, "" + low);
        map.put(HIGH, "" + high);
        return map;
    }    

    public TriMesh getMesh(int index) {
        if (block == null) {
            init();
        }
        return block;
    }

    public RenderState[] getRenderStates(int index) {
        return new RenderState[]{
            getMaterialState(null), 
            loadTexture(texture)
        };
    }

    public int getSize() {
        return 1;
    }
    
}

⌨️ 快捷键说明

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