package game.entities;
import javax.microedition.m3g.*;
import game.terrain.*;
public class Car
{
static Group carGroup;
public CarCanvas parent;
public Velocity velocity = new Velocity();
public float [] carCoords = new float[3];
public static float matrix[]=new float[16];
private static final float X_POS = 0.0f;
private static final float Y_POS = 0.01f;
private static final float Z_POS = 0.0f;
private static float ANGLE_INCR = 2.0f;
public static float MOVE_INCR = 0.0f;
public boolean upPressed = false;
public boolean downPressed = false;
public boolean leftPressed = false;
public boolean rightPressed = false;
private Transform trans = new Transform();
private float[] transMat = new float[16];
public float xCoord, yCoord, zCoord;
public float xAngle = 0;
public float yAngle;
public float zAngle = 0;
float lol = 0;
private Group transGroup = new Group();
private Group group = new Group();
private Camera backcam = new Camera();
private Camera nosecam = new Camera();
private Camera sidecam = new Camera();
public int width;
public int height;
Group wheel1;
Group wheel2;
Group wheel3;
Group wheel4;
Transform tr_cam = new Transform();
private boolean up_cam = false;
private boolean down_cam = false;
static final int UP_CAM = 9;
static final int DOWN_CAM = 11;
static final int SHOW_POSITION = 10;
static final int UP = 1; //Canvas.UP = UP
static final int DOWN = 6; //Canvas.DOWN = DOWN
static final int LEFT = 2; //Canvas.LEFT = LEFT
static final int RIGHT = 5;//Canvas.RIGHT = RIGHT
private MobileBackground mobileBackGnd;
private Group floorGroup ;
private RayIntersection ri = new RayIntersection();
private final float MAX_HEIGHT =100f;
public void up_cam()
{
backcam.getTransform(tr_cam);
tr_cam.postTranslate(0,0.05f,0);
backcam.setTransform(tr_cam);
}
public void down_cam()
{
backcam.getTransform(tr_cam);
tr_cam.postTranslate(0,-0.05f,0);
backcam.setTransform(tr_cam);
}
//构造函数
public Car(int w, int h)
{
width = w;
height = h;
set();
}
private Group scaleCar = new Group();
public void set()
{
setCamera();
setCarEntity();
transGroup = new Group();
trans.postTranslate(X_POS, Y_POS, Z_POS);
transGroup.addChild(backcam);
transGroup.addChild(nosecam);
transGroup.addChild(sidecam);
scaleCar.addChild(carGroup);
scaleCar.scale(0.5f, 0.5f, 0.5f);
transGroup.addChild(scaleCar);
transGroup.setTransform(trans);
yAngle = 0.0f;
wheel1 = (Group) carGroup.find(65);
wheel2 = (Group) carGroup.find(69);
wheel3 = (Group) carGroup.find(63);
wheel4 = (Group) carGroup.find(67);
}
public void setCamera()
{
float aspectRatio = ((float) width) / ((float) height);
backcam.postRotate(-20,1,0,0);
backcam.setTranslation(0,2,4);;
backcam.setPerspective(60.0f, aspectRatio, 0.5f, 1000.0f);
nosecam.setPerspective(60.0f,aspectRatio,0.5f,1000);
nosecam.setTranslation(0,0.75f,0.25f);
sidecam.setPerspective(60.0f,aspectRatio,0.5f,1000);
sidecam.setTranslation(-2,0.75f,2.5f);
sidecam.postRotate(-45,0,1,0);
}
public void setCarEntity()
{
World carw = loadWorld("/models/car.m3g");
carGroup = (Group) carw.find(62);
carw.removeChild(carGroup);
}
//载入World
public World loadWorld(String fn)
{
Object3D[] tile = load(fn);
World w = null;
for (int i = 0; i < tile.length; i++){
try{
w = (World)tile[i];
break;
}catch(Exception ex){
}
}
return w;
}
//载入3DObject
public Object3D[] load( String fn ){
Object3D[] obj = null;
try {
obj = Loader.load(fn);
} catch(Exception e) {
e.printStackTrace();
}
return obj;
}
public Group getCameraGroup()
{
return transGroup;
}
public Group getObjectGroup()
{
return group;
}
//获取照相机
public Camera getBackCamera()
{
return backcam;
}
public Camera getNoseCamera() {
return nosecam;
}
public Camera getSideCamera() {
return sidecam;
}
//响应键盘(按下)
public void pressedKey(int gameAction){
switch(gameAction) {
case UP_CAM: up_cam = true; break;
case DOWN_CAM: down_cam = true; break;
case UP: upPressed = true; break;
case DOWN: downPressed = true; break;
case LEFT: leftPressed = true; break;
case RIGHT: rightPressed = true; break;
default: break;
}
}
//响应键盘(释放)
public void releasedKey(int gameAction){
switch(gameAction) {
case UP_CAM: up_cam = false; break;
case DOWN_CAM: down_cam = false; break;
case UP: upPressed = false; break;
case DOWN: downPressed = false; break;
case LEFT: leftPressed = false; break;
case RIGHT: rightPressed = false; break;
default: break;
}
}
//响应键盘,移动汽车
public void update(){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
if( up_cam )
{
up_cam();
}
if( down_cam )
{
down_cam();
}
transGroup.getTransform(trans);
getPosition();
if (upPressed){
if (MOVE_INCR >= 0)
MOVE_INCR = velocity.accelerate();
else if (MOVE_INCR < 0)
MOVE_INCR = -velocity.brake(20);
}
else if (downPressed){
if (MOVE_INCR <= 0){
MOVE_INCR = -velocity.accelerate();
}else if (MOVE_INCR > 0){
MOVE_INCR = velocity.brake();
}
}else{
if (MOVE_INCR >= 0)
MOVE_INCR = velocity.brake(60);
else
MOVE_INCR = -velocity.brake(60);
}
if (MOVE_INCR != 0)
{
if(leftPressed || rightPressed)
updateYaw();
}
updateMove();
backcam.setTranslation(lol,2.5f,4);
float f[] = new float[4];
wheel2.getOrientation(f);
if(leftPressed){
if (lol > -1)
lol = lol - 0.1f;
if (f[0] < 140) {
wheel1.postRotate( -5, 0, 0, 1);
wheel2.postRotate( -5, 0, 0, 1);
}
}else if(rightPressed){
if (lol < 1)
lol = lol + 0.1f;
if (f[0] > 100) {
wheel1.postRotate(5, 0, 0, 1);
wheel2.postRotate(5, 0, 0, 1);
}
}else{
if (lol < -0.1f)
lol = lol + 0.1f;
else if (lol > 0.1f)
lol = lol - 0.1f;
else
lol = 0;
if (f[0] > 119.99975f) {
wheel1.postRotate(5, 0, 0, 1);
wheel2.postRotate(5, 0, 0, 1);
}else if (f[0] < 119.99975f) {
wheel1.postRotate( -5, 0, 0, 1);
wheel2.postRotate( -5, 0, 0, 1);
}
}
wheel1.getChild(0).postRotate(-MOVE_INCR * 100,0,1,0);
wheel2.getChild(0).postRotate(-MOVE_INCR * 100,0,1,0);
wheel3.getChild(0).postRotate(-MOVE_INCR * 100,0,1,0);
wheel4.getChild(0).postRotate(-MOVE_INCR * 100,0,1,0);
terrainCheck();
}
//更新汽车的移动位置
public void updateMove(){
trans.postTranslate(0, 0, -MOVE_INCR);
}
//更新汽车的偏移角
public void updateYaw(){
if (leftPressed) {
yAngle += ANGLE_INCR;
}else if (rightPressed){
yAngle -= ANGLE_INCR;
}
if (yAngle >= 360.0f)
yAngle -= 360.0f;
else if (yAng
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
移动3D赛车游戏_J2ME手机游戏源代码 (261个子文件)
Car.class 9KB
Car.class 9KB
Car.class 9KB
Car.class 9KB
CarCanvas.class 8KB
CarCanvas.class 8KB
CarCanvas.class 8KB
CarCanvas.class 8KB
texCanvas.class 5KB
texCanvas.class 5KB
texCanvas.class 5KB
HeightMap.class 4KB
VertexCanvas.class 4KB
VertexCanvas.class 4KB
VertexCanvas.class 4KB
HeightMap.class 4KB
HeightMap.class 4KB
HeightMap.class 4KB
MeshFactory.class 3KB
MeshFactory.class 3KB
MeshFactory.class 3KB
MeshFactory.class 3KB
MobileBackground.class 1KB
MobileBackground.class 1KB
MobileBackground.class 1KB
MobileBackground.class 1KB
CarCanvas$Repainter.class 1KB
CarCanvas$Repainter.class 1KB
CarCanvas$Repainter.class 1KB
CarCanvas$Repainter.class 1KB
VertexMIDletMain.class 1KB
VertexMIDletMain.class 1KB
VertexMIDletMain.class 1KB
texMIDletMain.class 1KB
texMIDletMain.class 1KB
texMIDletMain.class 1KB
Velocity.class 1015B
Velocity.class 946B
Velocity.class 934B
Velocity.class 934B
MainMIDlet.class 913B
MainMIDlet.class 913B
MainMIDlet.class 913B
MainMIDlet.class 913B
GameCarTerrain.jad 361B
GameCarTerrain.jar 524KB
obfuscated.jar 523KB
before-obfuscation.jar 523KB
Car.java 10KB
Car.java 10KB
CarCanvas.java 7KB
CarCanvas.java 7KB
HeightMap.java 4KB
HeightMap.java 4KB
texCanvas.java 4KB
texCanvas.java 4KB
MeshFactory.java 3KB
MeshFactory.java 3KB
VertexCanvas.java 2KB
VertexCanvas.java 2KB
MobileBackground.java 1KB
MobileBackground.java 1KB
Velocity.java 766B
Velocity.java 766B
VertexMIDletMain.java 686B
VertexMIDletMain.java 686B
texMIDletMain.java 667B
texMIDletMain.java 667B
MainMIDlet.java 440B
MainMIDlet.java 440B
car.m3g 16KB
car.m3g 16KB
car.m3g 16KB
car.m3g 16KB
manifest.mf 292B
MANIFEST.MF 106B
CELIGT4_128X128.png 66KB
CELIGT4_128X128.png 66KB
CELIGT4_128X128.png 66KB
CELIGT4_128X128.png 66KB
clouds.png 36KB
clouds.png 36KB
clouds.png 36KB
clouds.png 36KB
2 - CELIGT4_128X128.png 28KB
2 - CELIGT4_128X128.png 28KB
2 - CELIGT4_128X128.png 28KB
2 - CELIGT4_128X128.png 28KB
1 - CELIGT4_128X128.png 28KB
1 - CELIGT4_128X128.png 28KB
1 - CELIGT4_128X128.png 28KB
1 - CELIGT4_128X128.png 28KB
0 - CELIGT4_128X128.png 26KB
0 - CELIGT4_128X128.png 26KB
0 - CELIGT4_128X128.png 26KB
0 - CELIGT4_128X128.png 26KB
4 - CELIGT4_128X128.png 26KB
4 - CELIGT4_128X128.png 26KB
4 - CELIGT4_128X128.png 26KB
4 - CELIGT4_128X128.png 26KB
共 261 条
- 1
- 2
- 3
colinit
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页