floortile.java

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

JAVA
91
字号
/*
 * FloorTile.java
 *
 * Created on 22. Dezember 2006, 20:50
 *
 * 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.Matrix3f;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.SharedNode;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.RenderState;
import java.util.HashMap;
import java.util.Map;
import kanjitori.graphics.shape.FloorQuad;

/**
 *
 * @author Pirx
 */
public class FloorTile extends AbstractMeshTile {
    
    private static final String TEXTURE = "texture";
    private static final String FLIPPED = "flipped";
    
    private String texture;
    boolean flipped = false;  //for ceilings use flipped = true
    private FloorQuad floor;
    
    /** Creates a new instance of FloorTile */
    public FloorTile(String name, String texture) {
        super(name);
        this.texture = texture;
    }

    public FloorTile(String name, String texture, boolean flipped) {
        super(name);
        this.texture = texture;
        this.flipped = flipped;
    }
    
    public FloorTile() {
    }
            
    public void init() {    
        floor = new FloorQuad("floor", 2, 2, flipped ? FloorQuad.DOWN : FloorQuad.UP);
    }

    public void setParams(Map<String, String> map) {
        texture = map.get(TEXTURE);
        String fl = map.get(FLIPPED); 
        if (fl != null) {
           flipped = Boolean.parseBoolean(fl); 
        }
    }

    public Map<String, String> getParams() {
        Map<String, String> map = new HashMap<String, String>();
        map.put(TEXTURE, texture);
        map.put(FLIPPED, "" + flipped);
        return map;
    }

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

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

    public int getSize() {
        return 1;
    }
    
}

⌨️ 快捷键说明

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