⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jar.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
字号:
/*
 * Jar.java
 *
 * Created on den 28 juni 2005, 15:04
 */

package com.sonyericsson.app.game3d.honeycave;

import javax.microedition.midlet.*;
import com.mascotcapsule.micro3d.v3.*;

/**
 * A jar that gives the player 50 points when picked up.
 *
 * @author  Telescope Software AB
 * @version
 */
public class Jar
{
   /** Needs this to play a sound when it is taken. */
    private static GameEngine gameEngine;
    /* Collision box sizes. */
    private static final int WIDTH_HALF = 70/2;
    private static final int HEIGHT = 70;
    private static final int DEPTH_HALF = 70/2;
    
    /** If this jar is taken by player. */
    public boolean taken = false;
    /** Position in the world. */
    public Vector3D position = new Vector3D();
    
    /** Figure model for jar. */
    private static Figure figure;
    private static AffineTrans transform = new AffineTrans();
    private static AffineTrans layoutTransform =  new AffineTrans();
    
    
    /** Creates a new Jar.
     * @param gameEngine the GameEngine controlling the game this Jar is part of.
     * The Jar needs this to play sounds when taken.
     **/
    public Jar(GameEngine gameEngine)
    {
	this.gameEngine = gameEngine;
    }
    
    
    /** Loads the model used to render the bonus jars. */
    public static boolean loadModel()
    {
	try
	{
	    figure = new Figure("/items/jar.mbac");
	} catch (Exception e)
	{
	    System.err.println("Jar Figure loading failed!");
	    e.printStackTrace();
	    return false; // failed
	}
	
	return true; // success
    }
    
    /** Sets position of this bonus jar. This will
     * also set transform matrix.
     * @param pos the position to be used. Values of this
     * Vector3D will be copied. */
    public void setPosition(Vector3D pos)
    {
	position.set(pos);
	transform.setIdentity();
	transform.m03 = position.x;
	transform.m13 = position.y;
	transform.m23 = position.z;
    }
    
    
    /** Checks if box collides with this jar. If it does
     * then #GameEngine.playerHasTakenJar will be called.
     *
     * @param pos the position of the box. x and z is the box's
     * center and y is the box's bottom.
     * @param xHalfSize half the size of box side along x-axis
     * @param zHalfSize half the size of box side along z-axis
     * @param yFullSize the size of the box along the y-axis
     *
     */
    public void checkCollision(Vector3D pos, int xHalfSize,
    int zHalfSize, int yFullSize)
    {
	if (taken)
	    return; // Jar is already taken by bear
	
	if (pos.x-xHalfSize>position.x+WIDTH_HALF || pos.x+xHalfSize<position.x-WIDTH_HALF
	|| pos.y>position.y+HEIGHT/2 || pos.y+yFullSize<position.y-HEIGHT/2
	|| pos.z-zHalfSize>position.z+DEPTH_HALF || pos.z+zHalfSize<position.z-DEPTH_HALF)
	{
	    // No collision
	    return;
	}
	
	// Collision
	gameEngine.playerHasTakenJar();
	taken = true;
    }
    
    /** Render this Jar.
     *
     * @param worldTrans the transform used to transform objects into camera view
     **/
    public void draw(AffineTrans worldTrans, Graphics3D g3D, FigureLayout fl, Effect3D eff)
    {
	if (taken)
	    return; // Jar is taken by bear, don't draw
	
	AffineTrans transToRestore = fl.getAffineTrans();
	
	layoutTransform.set(worldTrans);
	
	transform.m03 = position.x;
	transform.m13 = position.y;
	transform.m23 = position.z;
	layoutTransform.mul(transform);
	
	fl.setAffineTrans(layoutTransform);
	eff.setLight(PlayerCharacter.light);
	g3D.renderFigure(figure,0,0, fl, eff);
	eff.setLight(null);
	fl.setAffineTrans(transToRestore);
    }
    
     
}

⌨️ 快捷键说明

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