📄 stagecanvas.java
字号:
if (spriteArray[0].Y >= 13) {
spriteArray[0].Y -= xx;
}
break;
case 2:
for (int i = 1; i < 6; i++) {
spriteArray[i].X -= midhighSpeed;
}
if (spriteArray[0].Y >= 13) { //xx==3 10+3
spriteArray[0].Y -= xx;
}
break;
case 3:
for (int i = 1; i < 6; i++) {
spriteArray[i].X -= highSpeed;
}
break;
case 4:
for (int i = 1; i < 6; i++) {
spriteArray[i].X -= midhighSpeed;
}
if (spriteArray[0].Y <= 140) { //96 93+3
spriteArray[0].Y += xx;
}
break;
case 5:
for (int i = 1; i < 6; i++) {
spriteArray[i].X -= midSpeed;
}
if (spriteArray[0].Y <= 140) {
spriteArray[0].Y += xx;
}
break;
}
break;
}
this.canKey = 0;
this.fps = 0;
// }else{
// this.fps++;}
}
///********************************************************************************************************
// 按键响应
protected void keyPressed(int key_code) {
// System.out.println(" You has pressed Keycode :" + key_code);
// System.out.println(" You has pressed GameAction :" +
// this.getGameAction(key_code));
this.eng.keyController(key_code); //, this.getGameAction(key_code));
}
/*
绘制进度条
*/
public void loadSound(){
try{
//psound=new Sound(playSound("bubble4.wav",7592),5);
psound=new Sound(playSound("1.wav",4778),5);
System.out.println("loadSound ok");
}catch(Exception e){
System.out.println("loadSound err: "+e.getMessage());
}
}
public byte [] playSound(String s,int i){
byte [] sbytearray;
try{
InputStream is=getClass().getResourceAsStream(sndPath+s);
sbytearray=new byte[i];
is.read(sbytearray,0,i);
is.close();
}catch(Exception e){
sbytearray=null;
System.out.println("playSound err: "+e.getMessage());
}
return sbytearray;
}
private boolean drawLoadingScreen(Graphics g) {
while (tempStatus <= 100) {
try {
//bbmfLogo = Image.createImage("/res/d1.png");
//logo=Image.createImage("/res/logo.png");
}
catch (Exception e) {
System.out.println(e);
}
//tempStatus加载图片
// g.drawRect(15, this.stage_CenterY + 39, 100, 10);
//g.setColor(this.COLOR_WHITE);
// g.fillRect(this.stage_CenterX - 10, this.stage_CenterY + 20, 20, 15); //clear area
// g.setColor(this.COLOR_BLUE);
// g.fillRect(16, this.stage_CenterY + 40, tempStatus, 9);
// g.drawString(String.valueOf(tempStatus) + "%", this.stage_CenterX - 10,
// this.stage_CenterY + 20, ANCHOR0_LT);
/* try { //加载图片资源
if (tempStatus < 20) {
for (int n = 1; n < 5; n++) { //1 2 3 4
images[n] = Image.createImage("/res/images/" + imgFileName[n] +
".png");
}
} /////images[5]=gameOver.png别的地方加载
if (tempStatus > 20 && tempStatus < 40) {
for (int n = 6; n < 9; n++) { //6 7 8
images[n] = Image.createImage("/res/images/" + imgFileName[n] +
".png");
}
}
}
/* */
/* try{
if((tempStatus+10)!=50 || (tempStatus+10)<90){
images[(tempStatus+10)%10]=Image.createImage("/res/images/"+imgFileName[(tempStatus+10)%10]+".png");
}
}
catch (Exception e) {
e.printStackTrace();*/
// }
this.tempStatus += 10;
this.isRepaint = true;
if (tempStatus == 100) {
return true;
}
break;
}
return false;
//return true;
}
/*
设置剪辑图片
*/
private void setClipImage(Graphics g, int i, int j, Image image, int k, int l,
int i1, int j1, int k1) {
g.setClip(i, j, i1, j1);
g.drawImage(image, i - k, j - l, k1);
g.setClip(0, 0, this.stage_Width, this.stage_Height);
}
//急流中出现的运动物体图片
// imgType:0,人 1,鳄鱼 2,树 3,激流 4,漩涡 5,小石头 6,中石头 7,大石头
private void drawTypeImages(Graphics g, int imgType,
int placedX, int placedY, int boatDir) {
switch (imgType) {
case 0:
//boatDir船的方向 0 1 2 3 4 5 6 (left-right )
this.setClipImage(g, placedX, placedY, images[2], 22 * boatDir, 0,
22, 22,
this.ANCHOR0_LT);
break;
case 1: //crocodile 第一个crocodile
this.drawEffectCrocodile(g, placedX, placedY, 0);
break;
case 2: //树庄
this.setClipImage(g, placedX, placedY, images[7], 49, 0,
20, 15,
this.ANCHOR0_LT);
break;
case 3: //spray急流
this.setClipImage(g, placedX, placedY, images[7], 49 + 21, 0,
25, 23,
this.ANCHOR0_LT);
break;
case 4: //4,漩涡
this.setClipImage(g, placedX, placedY, images[7], 0, 23,
23, 20, //25 22
this.ANCHOR0_LT);
break;
case 5: //5,小石头
this.setClipImage(g, placedX, placedY, images[7], 0, 0,
11, 18, //11 18
this.ANCHOR0_LT);
break;
case 6: ////6,中石头
this.setClipImage(g, placedX, placedY, images[7], 12, 0, //12
12, 18,
this.ANCHOR0_LT);
break;
case 7: //7,大石头
this.setClipImage(g, placedX, placedY, images[7], 25, 0, //25
23, 22,
this.ANCHOR0_LT);
break;
}
}
//5个crocodile图 num:0 1 2 3 4 (left-right )
private void drawEffectCrocodile(Graphics g, int placedX, int placedY,
int num) {
if (num == 0) {
this.setClipImage(g, placedX, placedY, images[3], 39 * num + 2, 15, 30,
10, // 35, 20,
this.ANCHOR0_LT);
}
else {
this.setClipImage(g, placedX, placedY, images[3], 39 * num, 0, 39, 39,
this.ANCHOR0_LT);
}
}
//7个被咬的boat图 num:0 1 2 3 4 (left-right )
private void drawBiteBoat(Graphics g, int placedX, int placedY, int num) { //
if (num < 3) {
this.setClipImage(g, placedX, placedY, images[8], 39 * num, 0, 39, 39,
this.ANCHOR0_LT);
}
if (num == 3) {
this.setClipImage(g, placedX, placedY, images[8], 39 * num, 0, 78, 39,
this.ANCHOR0_LT);
}
if (num == 4) {
this.setClipImage(g, placedX, placedY, images[8], 39 * (num + 1), 0, 78,
39,
this.ANCHOR0_LT);
}
}
private int BiteCount = 0;
// int effectCount=0;
//咬船的动画
private void drawBiteBoatEffect(Graphics g, int x, int y) {
this.drawClearScreen(g, this.COLOR_BLUE); //.COLOR_BLACK);
//闪屏
for (int j = 0; j < 5; j++) {
for (int i = 0; i <= 100; i += 10) {
DeviceControl.setLights(0, i);
}
}
switch (BiteCount) {
case 0:
this.drawBiteBoat(g, x - 15, y, 0);
BiteCount++;
break;
case 1:
this.drawBiteBoat(g, x - 15, y, 1);
drawEffectCrocodile(g, x, y, 4);
BiteCount++;
break;
case 2:
this.drawBiteBoat(g, x - 15, y, 2);
drawEffectCrocodile(g, x, y, 3);
BiteCount++;
break;
case 3:
this.drawBiteBoat(g, x - 25, y, 3);
drawEffectCrocodile(g, x, y, 2);
BiteCount++;
break;
case 4:
this.drawBiteBoat(g, x - 25, y, 4);
drawEffectCrocodile(g, x, y, 1);
BiteCount++;
break;
case 5:
this.drawBiteBoat(g, x - 25, y, 3);
drawEffectCrocodile(g, x, y, 2);
BiteCount++;
break;
case 6:
this.drawBiteBoat(g, x - 25, y, 4);
drawEffectCrocodile(g, x, y, 1);
BiteCount = 7;
break;
}
if (this.BiteCount == 7) {
this.isRepaint = false;
this.lifeValue = 0;
this.saveData();
this.eng.gameState = eng.STATE_GAMEOVER;
// this.eng.gameState = this.eng.STATE_LOSE;
this.BiteCount = 0;
}
this.isRepaint = true;
}
//船在漩涡中运动时改变方向
private void drawSwirlBoat(Graphics g, int placedX, int placedY) {
//this.drawClearScreen(g,this.COLOR_RED);
int temp = Math.abs(this.randomDir.nextInt() % 8); //7个方向
this.setClipImage(g, placedX, placedY, images[2], 22 * temp, 0,
22, 22,
this.ANCHOR0_LT);
this.spriteArray[0].direction = temp;
this.isRepaint = true;
}
int splash = 0;
//船碰到 石头,树桩, 物体时的动态效果 石头,树桩,
int tempHitLife = 0;
private void drawHitEffect(Graphics g, int placedX, int placedY) {
if(isSound){
try{
psound.play(1);
}
catch (Exception e) {
System.out.println(e);
}
}
int dir = this.spriteArray[0].direction;
// System.out.println("dir:" + dir);
switch (splash) {
case 0:
splash++;
break;
case 1:
this.drawTypeImages(g, 0, placedX, placedY, dir);
splash++;
break;
case 2:
splash++;
break;
case 3:
this.drawTypeImages(g, 0, placedX, placedY, dir);
splash++;
break;
case 4:
tempHitLife++;
if (tempHitLife == 1) {
// DeviceControl.startVibra(20, 500); //震动
this.lifeValue--;
}
splash = 0;
break;
}
this.isRepaint = true;
}
/*
logo画面
*/
private void drawLogoScreen(Graphics g) {
g.drawImage(images[0], 0, 0, this.ANCHOR0_LT);
}
/*
游戏介绍//游戏说明(游戏介绍,按键说明)
*/
private void drawIntroScreen(Graphics g) {
drawClearScreen(g, this.COLOR_BLUE);
g.setFont(FONT_SMALL);
g.setColor(this.COLOR_WHITE);
g.drawString("帮助", 60, 10, this.ANCHOR0_LT);
g.drawString("玩家操纵皮划艇在河中前进,左", 4, 10+16, this.ANCHOR0_LT);
g.drawString("右移动来绕开障碍物。要善于利", 4, 10 + 16*2, this.ANCHOR0_LT);
g.drawString("用皮划艇的不同姿态来控制方向", 4, 10 + 16 *3, this.ANCHOR0_LT);
g.drawString("和速度游戏时画面左上角显示生", 4, 12 + 16 * 4, this.ANCHOR0_LT);
g.drawString("命值,右上角显示分数。玩家每", 4, 12 + 16 * 5, this.ANCHOR0_LT);
g.drawString("绕过一个障碍物都会得分,其中", 4, 12 + 16 * 6, this.ANCHOR0_LT);
g.drawString("岩石,树桩是 5分,乱流是10分", 4, 12 + 16 * 7, this.ANCHOR0_LT);
g.drawString("激流是10分,鳄鱼是15分。游戏", 4, 12 + 16 * 8, this.ANCHOR0_LT);
g.drawString("会按照玩家得分自动补充生命值", 4, 12 + 16 * 9, this.ANCHOR0_LT);
/* g.setColor(this.COLOR_YELLOW_RED);
g.drawString("左软键:确定; 暂停:#", 8, 12 + 16 * 4, this.ANCHOR0_LT);
g.drawString("右软键: 游戏中菜单键", 8, 12 + 16 * 5, this.ANCHOR0_LT);
g.drawString("导航键:方向", 8, 12 + 16 * 6, this.ANCHOR0_LT);*/
g.setColor(this.COLOR_RED);
g.drawString("返回", stage_CenterX + 40, stage_CenterY + 75, this.ANCHOR0_LT);
}
/*
Score 得分记录
*/
private void drawScoreScreen(Graphics g) { //得分记录
this.getData();
drawClearScreen(g, this.COLOR_BLUE);
g.setFont(this.FONT_SMALL);
g.setColor(this.COLOR_ORG);
g.drawString("最高成绩记录", this.stage_CenterX - 35,
this.stage_CenterY - 50, this.ANCHOR0_LT);
g.setColor(this.COLOR_WHITE);
g.drawString("简单级别: " + scoreLow, this.stage_CenterX - 50,
this.stage_CenterY - 20, this.ANCHOR0_LT);
g.drawString("普通级别: " + scoreMid, this.stage_CenterX - 50,
this.stage_CenterY + 5,
this.ANCHOR0_LT);
g.drawString("困难级别: " + scoreHigh, this.stage_CenterX - 50,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -