📄 gamecanvas.java.bak
字号:
}else{
g.setClip(playerBulletX - 82 , playerBulletY ,82,43);
g.drawImage( gamePlayer1 , playerBulletX -200 ,playerBulletY -113 ,0);
}
}
g.setClip(0,0,W,H);
}
//------------------------------- 画动作 -------------------------------------------
public void drawAction(Image clipImage,int playerX , int playerY ,int action ,Graphics g){
for(int i =0; i<= playerActionData[action].length-6; i+=6){
g.setClip(playerX+playerActionData[action][i] , playerY+playerActionData[action][i+1] , playerActionData[action][i+2] , playerActionData[action][i+3]);
g.drawImage(clipImage ,playerX+playerActionData[action][i]+playerActionData[action][i+4] , playerY+playerActionData[action][i+1] + playerActionData[action][i+5],0);
}
g.setClip(0,0,W,H);
}
//------------------------------- 重力运算 -----------------------------------------
public void gravity(){
if(moveAble(playerX,playerY) ||playerAction == playerFall_R || playerAction == playerFall_L || playerAction == playerJump_R || playerAction == playerJump_L){
playerFallValue += worldGravity;
if( playerFallValue > 32 )playerFallValue = 32;
if( !moveAble(playerX,playerY) && playerY > mapY+(getPosY(playerY)-winY)*32 ){
playerY = mapY+(getPosY(playerY)-winY)*32;
//playerActionClip = 0;
if( playerAction <= 11){
playerAction = playerStand_R;
}else{
playerAction = playerStand_L;
}
}
}else{
playerFallValue = 0;
}
}
//------------------------------- 判断地图上某点的可通行性 (封装了getValue()方法)-------------------------------------------
/*public boolean moveAble(int pointX ,int pointY){
if(getValue(getPosX(pointX),getPosY(pointY)) < 0){
return false;
}
return true;
}*/
public boolean moveAble(int pointX ,int pointY){
if(getValue(getPosX(pointX),getPosY(pointY)) < 0 && godMode){
return false;
}else if(getValue(getPosX(pointX),getPosY(pointY)) == -8){
return false;
}
return true;
}
//------------------------------- 摄象机控制-------------------------------------------
public int basePointX = W/2;
public int basePointY = 138;
public int adjustPoint_L = W - 50;
public int adjustPoint_R = 50;
public void cameraCtrl(){
if( ((playerAction == playerStand_R || playerAction == playerFall_R) /*&& !keyState[2] && !keyState[3]*/) ||playerAction == playerHang_R ){
//System.out.println(" adjust!");
if( playerX != adjustPoint_R){
cameraFollow((playerX - adjustPoint_R)/14 ,(playerY - basePointY)/10);
playerX += (adjustPoint_R - playerX)/14;
playerY += (basePointY - playerY)/10;
}
}else if( ((playerAction == playerStand_L|| playerAction == playerFall_L) /* && !keyState[2] && !keyState[3]*/) || playerAction == playerHang_L ){
//System.out.println(" adjust!");
if( playerX != adjustPoint_L){
cameraFollow((playerX - adjustPoint_L)/14 ,(playerY - basePointY)/10);
playerX += (adjustPoint_L - playerX)/14;
playerY += (basePointY - playerY)/10;
}
}
}
//------------------------------- 摄象机跟随 -------------------------------------------
public void cameraFollow( int cameraStepX ,int cameraStepY){
if(cameraStepX<0){
if(playerX >adjustPoint_L){
playerX+=cameraStepX;
}else if( winX >0){
mapX-=cameraStepX;
enemyNormX = -cameraStepX;
if(mapX>=0){
mapX -= 32;
winX--;
}
}else{
playerX+=cameraStepX;
}
}else if(cameraStepX>=0){
if(playerX <=adjustPoint_R){
playerX+=cameraStepX;
}else if( winX <mapWidth-W/32-2){
mapX-=cameraStepX;
enemyNormX = -cameraStepX;
if(mapX<=-32){
mapX += 32;
winX++;
}
}else{
playerX+=cameraStepX;
}
}
if(cameraStepY<0){///////////////////
if(playerY >basePointY){
playerY+=cameraStepY;
}else if( winY >0){
//System.out.println("stepY<0");
mapY-=cameraStepY;
enemyNormY = -cameraStepY;
if(mapY>= 26){
mapY -= 32;
winY--;
}
}else{
playerY+=cameraStepY;
}
}else if(cameraStepY>=0){
if(playerY <=basePointY){
//System.out.println("stepY>0");
playerY+=cameraStepY;
}else if( winY <mapHeight-6){
//System.out.println("stepY>0");
mapY-=cameraStepY;
enemyNormY = -cameraStepY;
if(mapY<=-6){
mapY += 32;
winY++;
}
}else{
playerY+=cameraStepY;
}
}
//System.out.println(" winX = " + winX +" | winY="+winY);
}
//************************************** 敌人 ************************************************ 敌人
//************************************** 敌人 ************************************************ 敌人
public int enemyMaxAmountInScreen = 2;
public boolean haveBoss = false;
public int enemyNormX = 0;
public int enemyNormY = 0;
public final int enemyRun_R = 0;
public final int enemyEscape_R = 1;
public final int enemyJump_R = 2;
public final int enemyAttack_R = 3;
public final int enemyFaint_R = 4;
public final int enemyDeath_R = 5;
public final int enemyRun_L = 6;
public final int enemyEscape_L = 7;
public final int enemyJump_L = 8;
public final int enemyAttack_L = 9;
public final int enemyFaint_L = 10;
public final int enemyDeath_L = 11;
public void enemyCtrl(){
for (int i = 0; i< enemyMaxAmountInScreen;i++ ){
//System.out.println(" in");
if(r.nextInt()%100>90 && enemy[i].enemyHealth <= 0 /*&& enemy[i].enemyAction < 0*/){
switch(enemy[i].enemyStyle){
case 1://红
enemy[i].enemyHealth = 100;
enemy[i].enemySpeed = 1+ Math.abs(r.nextInt()%2);
//System.out.println("enemy["+i+"] Born!");
break;
case 2://蓝
enemy[i].enemyHealth = 200;
enemy[i].enemySpeed = 1+ Math.abs(r.nextInt()%2);
//System.out.println("enemy["+i+"] Born!");
break;
case 3://黑
enemy[i].enemyHealth = 200;
enemy[i].enemySpeed = 1+ Math.abs(r.nextInt()%2);
//System.out.println("enemy["+i+"] Born!");
break;
case 4://忍者
enemy[i].enemyHealth = 200;
enemy[i].enemySpeed = 2+ Math.abs(r.nextInt()%2);
//System.out.println("enemy["+i+"] Born!");
break;
}
if(r.nextInt()%10 < 5){
enemy[i].enemyX = -100;
}else{
enemy[i].enemyX = W+100;
}
enemy[i].enemyY = mapY+10;
//System.out.println("enemy["+i+"] Born!");
}else if ( enemyMaxAmountInScreen > 0 ){
//System.out.println("in2");
enemy[i].enemyMove();
//if( i == 3) System.out.println(enemy[i].enemyAction);
if( playerBulleting && enemy[i].enemyAction != 4 && enemy[i].enemyAction != 5 && enemy[i].enemyAction != 10 && enemy[i].enemyAction != 11 && enemy[i].enemyX > playerBulletX && enemy[i].enemyX < playerBulletX + playerBulletWidth && enemy[i].enemyY-20 > playerBulletY && enemy[i].enemyY-20 < playerBulletY + playerBulletHeight ){
if(enemy[i].enemyAction<=3){
enemy[i].enemyAction = 4;
}else if( enemy[i].enemyAction<=9 && enemy[i].enemyAction>=6){
enemy[i].enemyAction = 10;
}
enemy[i].enemyFallValue = -6;
enemy[i].enemyY -= 8;
enemy[i].enemyHealth-=40+r.nextInt()%10;
}
if( (enemy[i].enemyX > W+110 || enemy[i].enemyX < -110 || enemy[i].enemyY > H+120 || enemy[i].enemyY < -120 ) && !enemy[i].enemyBulleting){
enemy[i].enemyHealth = 0;
}
}
}
if( haveBoss){
//System.out.println("2");
enemy[2].enemyMove();
if( enemy[2].enemyHealth <=0){
//触发剧情
System.out.println(" sceneStart!");
}
}
enemyNormX = 0;
enemyNormY = 0;
}
/////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//------------- 红衣匕首 -------------------
public int[][] enemyActionData_1 = {
/*右 0 */{-8,-35,29,35,0, 0}, //走
/*右 1 */{-8,-35,27,35,-29, 0}, //走
/*右 2 */{-10,-35,33,35,-56, 0}, //走
/*右 3 */{-5,-35,27,35,-89, 0}, //走
/*右 4 */{-10,-35,33,35,-116,0},//走
/*右 5 */{0,-38,20,38,-149, 0}, //攻击(0.5)
/*右 6 */{-12,-34,38,34,-169,0},//攻击(1)
/*右 7 */{-11,-39,25,39,-207,0},//被打
/*右 8 */{-11,-39,25,39,-232,0},//死亡瞬间
/*左 9 */{-21,-35,29,35,-228,-39},//走
/*左10 */{-19,-35,27,35,-201,-39},
/*左11 */{-24,-35,33,35,-168,-39},
/*左12 */{-24,-35,27,35,-141,-39},
/*左13 */{-22,-35,33,35,-108,-39},
/*左14 */{-21,-38,20,38,-88, -39}, //攻击(0.5)
/*左15 */{-28,-34,38,34,-50, -39}, //攻击(1)
/*左16 */{-15,-39,25,39,-25, -39}, //被打
/*左17 */{-15,-39,25,39,0, -39} //死亡瞬间
};
//------------- 蓝衣匕首 -------------------
public int[][] enemyActionData_2 = {
/*右 0 */{-8,-35,29,35,0, 0}, //走
/*右 1 */{-8,-35,27,35,-29, 0}, //走
/*右 2 */{-10,-35,33,35,-58, 0}, //走
/*右 3 */{-5,-35,29,35,-91, 0}, //走
/*右 4 */{-10,-35,33,37,-120,0},//走
/*右 5 */{0,-38,21,38,-154, 0}, //攻击(0.5)
/*右 6 */{-12,-34,41,38,-175,0},//攻击(1)
/*右 7 */{-11,-39,25,39,-216,0},//被打
/*右 8 */{-11,-39,25,39,-241,0},//死亡瞬间
/*左 9 */{-21,-35,29,39,-237,-39},//走
/*左10 */{-19,-35,27,39,-201,-39},
/*左11 */{-24,-35,34,40,-175,-39},
/*左12 */{-24,-35,29,39,-146,-39},
/*左13 */{-22,-35,33,41,-113,-39},
/*左14 */{-21,-38,20,40,-91, -39}, //攻击(0.5)
/*左15 */{-28,-34,41,40,-50, -39}, //攻击(1)
/*左16 */{-15,-39,25,40,-25, -39}, //被打
/*左17 */{-15,-39,25,43, 0, -39} //死亡瞬间
};
//------------- 黑衣人 -------------------
public int[][] enemyActionData_3 = {
/*右 0 */{-12,-41,24,41,0, 0}, //走
/*右 1 */{-17,-41,29,41,-24, 0}, //走
/*右 2 */{-7,-43,21,43,-53, 0}, //走
/*右 3 */{-10,-42,26,42,-74, 0}, //走
/*右 4 */{-16,-41,29,41,-100, 0},//走
/*右 5 */{-10,-40,24,40,-128, 0}, //攻击(0.5)
/*右 6 */{-7,-40,26,40,-152, 0},//攻击(1)
/*右 7 */{-19,-36,29,38,-178, 0},//被打
/*右 8 */{-19,-36,28,38,-207, 0}, //死亡瞬间
/*左 9 */{-14,-41,24,43,-211,-43},//走
/*左10 */{-13,-41,29,43,-182,-43},
/*左11 */{-13,-43,21,43,-161,-43},
/*左12 */{-16,-42,26,43,-135,-43},
/*左13 */{-12,-41,28,43,-107,-43},
/*左14 */{-14,-40,24,43,-83, -43}, //攻击(0.5)
/*左15 */{-17,-40,26,43,-57, -43}, //攻击(1)
/*左16 */{-9,-36,28,41,-28, -45}, //被打
/*左17 */{-9,-36,28,41, 0, -45} //死亡瞬间
};
//------------- 忍者 -------------------
public int[][] enemyActionData_4 = {
/*右 0 */{-11,-41,24,41,0, 0}, //走
/*右 1 */{-18,-41,29,42,-24, 0}, //走
/*右 2 */{-7,-43,21,43,-53, 0}, //走
/*右 3 */{-10,-42,25,44,-74, 0}, //走
/*右 4 */{-17,-41,29,44,-99, 0},//走
/*右 5 */{-10,-40,24,43,-128, 0}, //攻击(0.5)
/*右 6 */{-9,-40,26,43,-152, 0},//攻击(1)
/*右 7 */{-18,-36,27,36,-178,-7},//被打
/*右 8 */{-18,-36,27,36,-205,-7}, //死亡瞬间
/*左 9 */{-12,-41,24,44,-209,-44},//走
/*左10 */{-12,-41,29,43,-180,-45},
/*左11 */{-12,-43,21,44,-159,-44},
/*左12 */{-15,-42,25,42,-134,-46},
/*左13 */{-13,-41,29,41,-105,-47},
/*左14 */{-13,-40,24,41,-81, -47}, //攻击(0.5)
/*左15 */{-15,-40,26,41,-54, -47}, //攻击(1)
/*左16 */{-10,-36,27,38,-28, -50}, //被打
/*左17 */{-10,-36,27,38, 0, -50} //死亡瞬间
};
//------------- 老鼠 -------------------
public int[][] enemyActionData_5 = {
/*右 0 */{-25,-27,44,27,0, 0}, //走
/*右 1 */{-26,-30,44,30,-44, 0}, //走
/*右 2 */{-19,-30,35,30,-88, 0}, //走
/*右 3 */{-10,-42,25,44,-74, 0}, //走*
/*右 4 */{-17,-41,29,44,-99, 0},//走*
/*右 5 */{-12,-27,44,27,-123, 0}, //攻击(0.5)
/*右 6 */{-9,-40,26,43,-152, 0},//攻击(1)*
/*右 7 */{-28,-28,35,28,-167, 0},//被打
/*右 8 */{-28,-28,35,28,-202, 0}, //死亡瞬间
/*左 9 */{-19,-27,44,30,-193,-30},//走
/*左10 */{-18,-30,44,30,-149,-30},
/*左11 */{-17,-30,35,30,-114,-30},
/*左12 */{-15,-42,25,42,-134,-46},//*
/*左13 */{-13,-41,29,41,-105,-47},//*
/*左14 */{-29,-27,44,30,-70, -30}, //攻击(0.5)
/*左15 */{-15,-40,26,41,-54, -47}, //攻击(1)
/*左16 */{-10,-28,35,30,-35, -30}, //被打
/*左17 */{-10,-28,35,30, 0, -30} //死亡瞬间
};
//------------- 心魔 -------------------
public int[][] enemyActionData_13 = {
/*右 0 */{-14,-47,31,50,-214,-53},//走
/*右 1 */{-7,-48,19,50,-195, -53},
/*右 2 */{-14,-47,29,51,-166,-53},
/*右 3 */{-15,-42,25,42,-134,-46},//*
/*右 4 */{-13,-41,29,41,-105,-47},//*
/*右 5 */{-13,-50,37,50,-107,-53}, //攻击(0.5)
/*右 6 */{-11,-41,43,43,-64, -61}, //攻击(1)*
/*右 7 */{-23,-45,32,46,-32, -57}, //被打
/*右 8 */{-23,-45,32,46, 0, -57}, //死亡瞬间
/*左 9 */{-15,-47,30,47,0, 0}, //走
/*左10 */{-13,-48,19,48,-30, 0}, //走
/*左11 */{-14,-47,29,47,-49, 0}, //走
/*左12 */{-10,-42,25,44,-74, 0}, //走*
/*左13 */{-17,-41,29,44,-99, 0},//走*
/*左14 */{-23,-50,37,50,-100, 0}, //攻击(0.5)
/*左15 */{-31,-40,43,50,-137, 0},//攻击(1)*
/*左16 */{-10,-45,32,49,-180, 0},//被打
/*左17 */{-10,-45,32,49,-212, 0} //死亡瞬间
};
//------------- 青蛙 -------------------
public int[][] enemyActionData_11 = {
/*右 0 */{-31,-50,64,50,0, 0},//走
/*右 1 */{-32,-45,72,49,-64, 0},
/*右 2 */{-26,-54,60,54,-136, 0},//*跳1
/*右 3 */{-26,-50,63,50,-196, 0},//*跳2
/*右 4 */{-31,-50,64,50,0, 0},//*
/*右 5 */{-25,-50,65,50,-259, 0}, //攻击(0.5)
/*右 6 */{-25,-50,65,50,-259, 0}, //攻击(1)*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -