📄 gamecanvas.java.bak
字号:
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.util.Random;
import java.io.*;
public class GameCanvas extends Canvas implements Runnable{
public int W = 176;//屏幕大小
public int H = 208;
public int threadSleepTime = 25;
public boolean gameRunning = true;
public boolean godMode = true;
public boolean gameInit = true;
public boolean musicCtrl = false;
public boolean loadMap = true;
public boolean keyState[] = { false,// 0 - up
false,// 1 - down
false,// 2 - left
false,// 3 - right
false,// 4 - fire
false,// 5 - rightSoft
false,// 6 - leftSoft
};
boolean worldS;
public final int stateLogo = 0;
public final int stateMenu = 1;
public final int stateGameing = 2;
public final int stateScene = 3;
public final int stateOther = 4;
public int gameState = stateMenu;
public int menuIndex = 0;
public int worldGravity = 2;
public int worldShakeX = 0;
public int worldShakeY = 0;
public int Add = 0;
public int winX = 0;
public int winY = 0;
public int mapX = 0;
public int mapY = 26;
public int mapWidth = 20;
public int mapHeight = 8;
public int currentMapID = 1;
public byte[] currentMap= {};
public final int playerStand_R = 0;
public final int playerRun_R = 1;
public final int playerHang_R = 2;
public final int playerClimb_R = 3;
public final int playerSquat_R = 4;
public final int playerCreep_R = 5;
public final int playerJump_R = 6;
public final int playerFall_R = 7;
public final int playerAttack_R = 8;
public final int playerAttack2_R = 9;
public final int playerKill_R = 10;
public final int playerFaint_R = 11;
public final int playerStand_L = 12;
public final int playerRun_L = 13;
public final int playerHang_L = 14;
public final int playerClimb_L = 15;
public final int playerSquat_L = 16;
public final int playerCreep_L = 17;
public final int playerJump_L = 18;
public final int playerFall_L = 19;
public final int playerAttack_L = 20;
public final int playerAttack2_L = 21;
public final int playerKill_L = 22;
public final int playerFaint_L = 23;
public final int playerSpeed = 6;
public int playerHealth = 100;
public int playerPower = 100;
public int playerSprite = 0;
public int playerX = 35;
public int playerY = 75;
//public int playerActionFrameSpeed = 3;
//public int playerPosX = 0;
//public int playerPosY = 0;
public int playerRadiiX = 16;
public int playerHeight = 40;
public int playerAction = playerFall_R;
public int playerActionClip = 0;
public int playerActionIndex = 0;
public int playerFallValue = 0;
public boolean playerBulleting = false;
public int playerBulletX = 0;
public int playerBulletY = 0;
public int playerBulletStyle = 0;
public int playerBulletAdd = 0;
public int playerBulletWidth = 76;
public int playerBulletHeight = 32;
public int playerBulletStepX = 0;
//---------------------------------------------------------------------
public int[][] playerActionList = {
//================向右===================
/*站立 0*/{0},
/*跑动 1*/{2,playerSpeed,0, 1,playerSpeed,0, 2,playerSpeed,0, 3,playerSpeed,0 },
/*悬挂 2*/{7},
/*攀爬 3*/{4,3,-8, 5,3,-6, 6,3,-1, 5,1,-2 , },
/*蹲伏 4*/{8},
/*蹲爬 5*/{8},
/*跳跃 6*/{4,playerSpeed,0, },
/*跌落 7*/{8},
/*普攻 8*/{8,-2,0, 9,-1,0, 10,2,0, },
/*普攻 9*/{9,1,-5, 6,5,-5, 5,5,-5, },
/*必杀 10*/{8},
/*被打 11*/{11,-3,0 , 11,-2,0 , 11, -1,0},
//================向左===================
/*站立 12*/{0},
/*跑动 13*/{14,-playerSpeed,0, 13,-playerSpeed,0, 14,-playerSpeed,0, 15,-playerSpeed,0 },
/*悬挂 14*/{19},
/*攀爬 15*/{16,-3,-8, 17,-3,-6, 18,-3,-1, 17,-1,-2 },
/*蹲伏 16*/{8},
/*蹲爬 17*/{8},
/*跳跃 18*/{8},
/*跌落 19*/{8},
/*普攻 20*/{20,2,0, 21,1,0, 22,-2,0},
/*普攻 21*/{9,-1,-5},
/*必杀 22*/{8},
/*被打 23*/{23, 3,0 , 23,2,0 , 23, 1,0}
};
public int[][] playerActionData = {
//位置偏移x 位置偏移y 窗口width 窗口height 实际位置x 实际位置y
/* 0 右 站立*/{-8,-48,21,48,-179,0 /**/},//ok!!!!!!
/* 1 右 跑动*/{-15,-47,28,48,-10,0 /**/},//ok!!!!!!
/* 2 右 跑动*/{-4,-48,18,49,-38,0 /**/},//ok!!!!!!
/* 3 右 跑动*/{-13,-47,30,48,-56,0 /**/},//ok!!!!!!
/* 4 右 跳跃*/{-6,-43,21,43,-28,-64 /**/},//ok!!!!!!
/* 5 右 跳跃*/{-7,-42,25,42,-50,-64 /**/},//ok!!!!!!
/* 6 右 蹲 */{-10,-40,28,40,0,-67 /**/},//ok!!!!!!
/* 7 右 悬挂*/{-17,-5,20,55,-75,-52 /**/},//ok!!!!!!
/* 8 右 攻击*/{-14,-47,42,48,-200,-1 /**/},//baoQin1
/* 9 右 攻击*/{-22,-49,46,49,-242,0 /**/},//baoQin2
/* 10 右 发射*/{-22,-47,35,47,-127,-60/**/},
/* 11 右 被打*/{-21,-44,30,44,-97,-63 /**/},//OK
/* 12 左 站立*/{-11,-47,21,48,-404,0},//ok!!!!!!
/* 13 左 跑动*/{-13,-47,28,48,-566,0},//ok!!!!!!
/* 14 左 跑动*/{-13,-48,18,49,-548,0},//ok!!!!!!
/* 15 左 跑动*/{-15,-47,30,48,-518,0},//ok!!!!!!
/* 16 左 跳跃*/{-12,-43,21,43,-555,-64},//ok!!!!!!
/* 17 左 跳跃*/{-8,-42,25,42,-529,-64},//ok!!!!!!
/* 18 左 蹲 */{-17,-40,28,40,-576,-67},//ok!!!!!!
/* 19 左 悬挂*/{7,-21,20,55,-509,-52},
/* 20 左 攻击*/{-28,-47,42,47,-362,-1, /**/},
/* 21 左 攻击*/{-21,-49,46,49,-316,0 /**/},
/* 22 左 发射*/{-9,-47,34,48,-443,-60 /**/},
/* 23 左 被打*/{-8,-44,30,44,-477,-63, /**/},//OK
/* 24 右胳膊*/ {-8,-44,30,44,-477,-63, /**/},
/* 25 右胳膊*/ {-8,-44,30,44,-477,-63, /**/},
/* 26 右胳膊*/ {-8,-44,30,44,-477,-63, /**/},
/* 27 左胳膊*/ {-8,-44,30,44,-477,-63, /**/},
/* 28 左胳膊*/ {-8,-44,30,44,-477,-63, /**/},
/* 29 右胳膊*/ {-8,-44,30,44,-477,-63, /**/},
};
//---------------------------------------------------------------------
public int [][] specialArea = {
//x , y , w , h , nextMap , winX , winY,direction
{15 , 5 , 5 , 3 , 2, 0 , 0, 1},//map1
{3 , 13 , 5 , 3 , 3, 0 , 0, 1},//jieda0
{1 , 1 , 5 , 7 , 4, 60 , 0, -1},//peidianshi
{65 , 5 , 1 , 7 , 5, 0 , 0, 1},//tingchechang
{65 , 5 , 1 , 7 , 6, 0 , 0, 1},//huanqiuyule
{65 , 5 , 1 , 7 , 6, 0 , 0, 1}//tt
};
public Player musicPlayer;
public Image gamePlayer1;
public Image mapImage;
public Image UIbackGround;
public Image UImenuText;
public Image UIbutton;
public Image UItop;
public Image dk;
//public Image c;
//public Image h;
//---------------------------------------------------------------------
Random r=new Random();
Thread t=new Thread(this);
musicActive musicACTIVE;
Enemy[] enemy;// = new Enemy[4];
public GameCanvas(musicActive musicACTIVE) {//构造函数
//---------------------------------------------------------------------
gamePlayer1 = loadImage("man");
UIbackGround = loadImage("UIbackGround");
UImenuText = loadImage("UImenuText");
UIbutton = loadImage("UIbutton");
UItop = loadImage("UItop");
//dk = loadImage("dk");
//c = loadImage("c");
//h = loadImage("h");
//winX = 40;
musicInit();
//---------------------------------------------------------------------
this.musicACTIVE=musicACTIVE;
setFullScreenMode(true);
t.start();
}
public void run() {//主循环
while(gameRunning){
Add++;
if( Add%50 ==0 ){
for( int i =0; i<90 ; i++){
System.out.println("");
}
System.out.println("#$%^&*( =" + r.nextInt()%100);
}
switch(gameState){
case stateLogo:
break;
case stateMenu:
//System.out.println("a");
gameMenu();
//System.out.println("b");
musicCtrl();
//System.out.println("c");
break;
case stateGameing:
//System.out.println("1");
if( loadMap ){
// System.out.println("loadMap");
load(currentMapID);
}
//System.out.println("loadMap finish");
checkKey();
worldShake();
gravity();
playerMove();
cameraCtrl();
enemyCtrl();
//System.out.println("playerY"+playerY);
break;
case stateScene:
gameScene();
//System.out.println(Add);
break;
case stateOther:
//switch(menuSlt) to paintOther()
break;
}
repaint();
System.gc();
try{
t.sleep(threadSleepTime);
}catch(Exception Ex){}
}
try{
musicACTIVE.notifyDestroyed();
}catch(Exception Ex){}
}
//**************************************** paint ************************************************************************************
public void paint(Graphics g){
switch(gameState){
case stateLogo:
break;
case stateMenu:
paintMenu(g);
break;
case stateGameing:
if( !loadMap && Add > 28){
paintMap(g);
for (int i = 0; i< enemyMaxAmountInScreen+1;i++ ){
if( enemy[i].enemyHealth > 0 && (enemy[i].enemyX <W+200 || enemy[i].enemyX > -200) && (enemy[i].enemyY <H+200 || enemy[i].enemyY > -200)){
enemy[i].paintEnemy(g);
}
}
}else if( Add%7 == 0){
g.setColor(0,0,0);
g.fillRect(0,0,W,H);
}
paintNoize(g);
paintUI(g);
paintMan(g);
break;
case stateScene:
paintScene(g);
break;
}
}
int lineX =0;
int lineY =0;
public void paintNoize(Graphics g){
g.setColor(11,11,11);
if( r.nextInt()%100>80){
lineX = r.nextInt()%(W+100);
g.drawLine(lineX,r.nextInt()%H,lineX,r.nextInt()%H);
}
for ( int i = 0; i<7;i++){
lineX = r.nextInt()%(W+100);
lineY = r.nextInt()%H;
g.drawLine(lineX,lineY,lineX,lineY +r.nextInt()%3);
}
}
public void paintUI(Graphics g){
g.setColor(0,0,0);
g.fillRect(0,0,W,29);
g.fillRect(0,H-40,W,41);
g.setColor(190,190,190);
g.drawLine(0,27,W,27);
g.drawLine(0,H-39,W,H-39);
//g.fillRect(W-20,H-30,15,15);
g.drawImage(UItop,1,1,0);
//g.drawImage(dk,4,3,0);
}
public void checkKey(){
if(keyState[2] ){
if( playerAction == playerStand_L || playerAction == playerStand_R)playerAction = playerRun_L;
}else if(keyState[3] ){
if( playerAction == playerStand_L || playerAction == playerStand_R)playerAction = playerRun_R;
}else if( playerAction == playerRun_L){
playerAction = playerStand_L;
}else if( playerAction == playerRun_R){
playerAction = playerStand_R;
}
if(keyState[0]){
keyState[0] = false;
switch( playerAction){
case playerStand_L://------------------------------------------
if( !moveAble(playerX-playerRadiiX,playerY-5) && moveAble(playerX-playerRadiiX,playerY-40)){
playerAction = playerClimb_L;
playerActionIndex = 0;
}else{
playerAction = playerJump_L;
playerFallValue = -17;
}
break;
case playerStand_R://-------------------------------
if( !moveAble(playerX+playerRadiiX,playerY-5) && moveAble(playerX+playerRadiiX,playerY-40)){
playerAction = playerClimb_R;
playerActionIndex = 0;
}else{
playerAction = playerJump_R;
playerFallValue = -17;
}
break;
case playerHang_L:
playerAction = playerClimb_L;
playerActionIndex = 0;
break;
case playerHang_R:
playerAction = playerClimb_R;
playerActionIndex = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -