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

📄 spinobstaclecontainer.java

📁 一个在J2ME手机平台上两个人通过蓝牙建立连接从而进行赛车游戏
💻 JAVA
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.io.*;
import java.lang.*;
import com.mascotcapsule.micro3d.v3.*;
import java.util.Timer;
import java.util.TimerTask;

/*
 * SpinObstacleContainer class.
 * It creates a net of cubes in proper positions.
 * It creates task to rotate all cubes periodically.
 * Every cube gets assigned on construction, how much it will rotate every turn.
 * On redraw (render function) it call every cube to redraw.
 * It calls every cube to update itself according to new camera position when 
 * needed (updateCamPosition)
 */
public class SpinObstacleContainer
{
  private int mTabSize = 0;
  private CubeUnit[] cubes;

  Timer timer = new Timer();    // Timer to implement animation

  // temporary variable, reused in calculations
  private AffineTrans tmpAT = new AffineTrans();


  public SpinObstacleContainer(int aWidth, int aHeight, int aPosZ, int aDelay,
                               AffineTrans aCamTrans, Effect3D aEffect)
  {
    try {
      mTabSize = 16;
      cubes = new CubeUnit[mTabSize];

      int tabIndex = 0;
      for( int i=0; i<4; ++i) {
        for( int j=0; j<4; ++j ) {
          cubes[tabIndex] = new CubeUnit(-650+i*400, 650-j*400, aPosZ,
                                  0, 0, 0, aWidth, aHeight, aCamTrans, tmpAT,
                                  j*10+10, 15, 30, aEffect);
          ++tabIndex;
        }
      }
      timer.schedule( new MyUpdateTimerTask(), 0, aDelay ); // Start timer
    }
    catch(Exception e) {
      System.out.println("Failed to create cubes");
    }
    System.out.println("Obstacles created.");
  }

  public void render(Graphics3D g3d)
  {
    for( int i=0; i<mTabSize; ++i) {
      cubes[i].render(g3d);
    }
  }

  public void updateCamPosition(AffineTrans aCamTrans)
  {
    for( int i=0; i<mTabSize; ++i) {
      cubes[i].updateRotation();
      cubes[i].updateCamPosition(aCamTrans, tmpAT);
    }
  }

  class MyUpdateTimerTask extends TimerTask
  {
    public void run()
    {
      for( int i=0; i<mTabSize; ++i) {
        cubes[i].increaseAngles();
      }
    }
  }

}


⌨️ 快捷键说明

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