📄 gamescreen.java
字号:
protected void hideNotify() {
StopSound();
isShow = false;
}
protected void showNotify() {
playSound(GameConstant.MUSIC_GAME_STATE);
isShow = true;
}
public void run() {
while (isRun) {
while (isShow) {
long st = System.currentTimeMillis();
main();
repaint();
serviceRepaints();
// System.gc();
// System.out.println("free memory =
// "+Runtime.getRuntime().freeMemory());
int et = (int) (System.currentTimeMillis() - st);
try {
if (et < 80) {
Thread.sleep(80 - et);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (isExit) {
System.out.println("is hear!!!!!!");
isRun = false;
Main.planeRun.exitApp();
}
}
}
public void reset() {
wheelFrame = 0;
frameCount = 0;
loadCount = 0;
}
// public void setMax() {
//
// }
public void showProgress(Graphics graphics) {
int loadingFrontPosX = (GameConstant.iSCREEN_WIDTH - imageLoading.getWidth()) >> 1;
int loadingPosY = (GameConstant.iSCREEN_HEIGHT - imageLoading.getHeight()) >> 1;
int loadingBackPosX = loadingFrontPosX + imageLoading.getWidth();
int loadWidth = imageLoad.getWidth() >> 2;
int loadHeight = imageLoad.getHeight();
Tool.fillScreen(graphics,0);
graphics.drawImage(imageLoading, loadingFrontPosX, loadingPosY,
GameConstant.TOPLEFT);
// 显示进度亮框的个数
for (int i = 0; i <= frameCount; i++) {
graphics.setColor(255, 84, 118);
graphics.fillRect(loadingFrontPosX + 17 + i * 15, loadingPosY + 19,
11, 5);
}
//画左边的加载轮子
graphics.setClip(loadingFrontPosX, loadingPosY, loadWidth, loadHeight);
graphics.drawImage(imageLoad, loadingFrontPosX - loadWidth
* (wheelFrame % 2), loadingPosY, GameConstant.TOPLEFT);
//画右边的加载轮子
graphics.setClip(loadingBackPosX - loadWidth, loadingPosY, loadWidth,
loadHeight);
graphics.drawImage(imageLoad, loadingBackPosX - loadWidth - loadWidth
* (wheelFrame % 2 + 2), loadingPosY, GameConstant.TOPLEFT);
}
//更新加载参数
public void updateProgress() {
if(loadCount == 100){
this.reset();
}
wheelFrame++;
loadCount += 5;
if (loadCount % 15 == 0) {
frameCount++;
}
}
//获得加载记数
public int getLoadCount() {
return loadCount;
}
//获得选择飞机的类型
public byte getPlaneType() {
return planeType;
}
private void whichEng(byte engNum){
switch(engNum){
case 0:
strPlayId.append('A');
break;
case 1:
strPlayId.append('B');
break;
case 2:
strPlayId.append('C');
break;
case 3:
strPlayId.append('D');
break;
case 4:
strPlayId.append('E');
break;
case 5:
strPlayId.append('F');
break;
case 6:
strPlayId.append('G');
break;
case 7:
strPlayId.append('H');
break;
case 8:
strPlayId.append('I');
break;
case 9:
strPlayId.append('J');
break;
case 10:
strPlayId.append('K');
break;
case 11:
strPlayId.append('L');
break;
case 12:
strPlayId.append('M');
break;
case 13:
strPlayId.append('N');
break;
case 14:
strPlayId.append('O');
break;
case 15:
strPlayId.append('P');
break;
case 16:
strPlayId.append('Q');
break;
case 17:
strPlayId.append('R');
break;
case 18:
strPlayId.append('S');
break;
case 19:
strPlayId.append('T');
break;
case 20:
strPlayId.append('U');
break;
case 21:
strPlayId.append('V');
break;
case 22:
strPlayId.append('W');
break;
case 23:
strPlayId.append('X');
break;
case 24:
strPlayId.append('Y');
break;
case 25:
strPlayId.append('Z');
break;
}
}
private void engToNum(String[] palyId) {
egNums = new byte[palyId.length][5];
for (int i = 0; i < palyId.length; i++) {
for (int j = 0; j < palyId[i].length(); j++) {
switch (palyId[i].charAt(j)) {
case 'A':
egNums[i][j] = 0;
break;
case 'B':
egNums[i][j] = 1;
break;
case 'C':
egNums[i][j] = 2;
break;
case 'D':
egNums[i][j] = 3;
break;
case 'E':
egNums[i][j] = 4;
break;
case 'F':
egNums[i][j] = 5;
break;
case 'G':
egNums[i][j] = 6;
break;
case 'H':
egNums[i][j] = 7;
break;
case 'I':
egNums[i][j] = 8;
break;
case 'J':
egNums[i][j] = 9;
break;
case 'K':
egNums[i][j] = 10;
break;
case 'L':
egNums[i][j] = 11;
break;
case 'M':
egNums[i][j] = 12;
break;
case 'N':
egNums[i][j] = 13;
break;
case 'O':
egNums[i][j] = 14;
break;
case 'P':
egNums[i][j] = 15;
break;
case 'Q':
egNums[i][j] = 16;
break;
case 'R':
egNums[i][j] = 17;
break;
case 'S':
egNums[i][j] = 18;
break;
case 'T':
egNums[i][j] = 19;
break;
case 'U':
egNums[i][j] = 20;
break;
case 'V':
egNums[i][j] = 21;
break;
case 'W':
egNums[i][j] = 22;
break;
case 'X':
egNums[i][j] = 23;
break;
case 'Y':
egNums[i][j] = 24;
break;
case 'Z':
egNums[i][j] = 25;
break;
}
}
}
}
public void playSound(int currentSound) {
if (isPlaySound) {
switch (currentSound) {
case GameConstant.MUSIC_GAME_TITLE:
PlaySound("/music/main.mid", true);
break;
case GameConstant.MUSIC_GAME_MENU:
PlaySound("/music/weapon.mid", true);
break;
case GameConstant.MUSIC_GAME_RUN:
PlaySound("/music/soundGame.mid", true);
break;
case GameConstant.MUSIC_GAME_BOSS:
PlaySound("/music/soundBoss.mid", true);
break;
}
}
}
private void PlaySound(String soundPath, boolean isLoop) {
try {
InputStream inputStream = this.getClass().getResourceAsStream(
soundPath);
player = Manager.createPlayer(inputStream, "audio/midi");
if (isLoop) {
player.setLoopCount(-1);
} else {
player.setLoopCount(1);
}
player.realize();
player.prefetch();
player.start();
inputStream.close();
} catch (Exception e) {
System.out.println("music!!!!!!!!");
e.printStackTrace();
}
}
public void StopSound() {
try {
if (player != null) {
player.stop();
player.close();
player = null;
}
} catch (Exception e) {
System.out.println("stopSound!!!!!!!");
e.printStackTrace();
}
}
/* 线程参数 */
private boolean isRun = true;
private boolean isShow = true;
private boolean isExit = false;
// GameControl
public static int gameState;
private static int stateCount;
// 按键的状态
private static int key;
private static int pressedKey;
private static int releasedKey;
// 是否需要声音
private boolean isPlaySound = true;
private Player player;
// 菜单参数
private GameMenu gameMenu = GameMenu.getInstance();
private int menuShowTimes = 0;
private int menu2ShowTimes = 0;
private int lightChangeTimes = 0;
private int selectCount;
private byte setCount = 0;
private int maxSelectNum = 4;
private byte helpCount = 0; //帮助记数
//private byte helpRows = 0; //帮助文字的行数
private byte gameMenuCount = 0; //子菜单记数
// 选择飞机参数
private byte planeType = 1;
// 选择武器参数
private byte[] weaponType = new byte[4];
// 进度条参数
private Image imageLoad;
private Image imageLoading;
private int wheelFrame; // 轮子的桢数
private int frameCount; // 框子个数
private int loadCount; // 进度记数
// 存储参数
private byte [] egNum = {0,0,0,0,0}; //英文数字
private byte [][] egNums;
private byte egNumIdx = 0; //第几个英文字母的下标
private StringBuffer strPlayId = new StringBuffer();
private RmsMobile rmsMobile = RmsMobile.getInstance();
// 世界类
private World world;
//自己的实例
private static GameScreen gameScreen;
private BattlePlaneActor planeActor;
//private int dieCount;
//private Image offScreenBuffer; //缓冲
private int fps = 0;
private int cyclesThisSecond = 0;
private long lastFPSTimes = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -