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

📄 gamescreen.java

📁 青蛙過河~ 就是青蛙過馬路 過馬路很危險請小心... that s a
💻 JAVA
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.* ;
import javax.microedition.lcdui.*;
import java.util.*;

public class GameScreen extends GameCanvas implements Runnable{
	
	
	private RoadRun theMidlet;					
  	private boolean running=true;
   	private int cps=0;
  	private int cyclesThisSecond=0;
	private long lastCPSTime=0;
	private static final int MAX_CPS = 50;
	private static final int MS_PER_FRAME = 1000 / MAX_CPS;
	
	private Image 	     img;
	
	private static int statusLineHeight=10;
	private int laneHeight=0;
	private static final int topMargin = 3;
	
	private TruckActor	truck[]=new TruckActor[8];
	private CarActor	car[]=new CarActor[8];
	
    private WombatActor wombat;

	private long lastCycleTime;

	private Graphics g=getGraphics();
	
   	public GameScreen(RoadRun midlet){
   		
   		super(true);
       	theMidlet = midlet;
       	initResources();
       	
       	// create the game thread			
       	Thread t = new Thread(this);
   	   	t.start();

   	} 
   
   	public void run(){
   		while(running){
   			
      		// create the game thread
      		long cycleStartTime = System.currentTimeMillis();
      		input();
			cycle();
      		render(); 
			if (System.currentTimeMillis() - lastCPSTime > 1000){
         		lastCPSTime=System.currentTimeMillis();
         		cps = cyclesThisSecond;
         		cyclesThisSecond = 0;
      		} else
         		cyclesThisSecond++;

      		// sleep if we've finished our work early
      		long timeSinceStart = (cycleStartTime - System.currentTimeMillis());
      		if (timeSinceStart < MS_PER_FRAME){
         		try{
            		Thread.sleep(MS_PER_FRAME - timeSinceStart);
         		}catch(java.lang.InterruptedException e){}
      		}
   		}
   		
   		theMidlet.gameOver();
   	}
   
   	public int getLaneHeight(){
   		return laneHeight;
	}
   	
   	public int getLaneYPos(int lane){
   	// convenience method to return the y position of a lane number
   		return (lane * laneHeight)+1+topMargin;
	}


	private void initResources(){
		try{
			
			// set up our world variables
			int heightMinusStatus = getHeight() - statusLineHeight;  //搭

⌨️ 快捷键说明

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