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

📄 gamecanvas.java

📁 一个以音乐为主题的杀怪手机游戏
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		     break;
	     }
	 }else if(keyState[1]){
			//worldShakeY = -1; 
		 switch( playerAction){
		 		case playerHang_R:
		 			playerX -= 15;
		 			playerY += 41;
		 			playerAction = playerFall_R;
		 			//System.out.println(" down");
		 		break;
		 		case playerHang_L:
		 			playerX += 15;
		 			playerY += 41;
		 			playerAction = playerFall_L;
		 			//System.out.println(" down");
		 		break;
		 		case playerStand_R:
		 		 
		 		case playerStand_L:
		 			 basePointY = 80;
		 		break;
		 
		 }
		 playerFallValue = 3;
	 }else{
	 	basePointY = 138;//10203820
	 }
	//if( worldS )worldShakeY = -1;
	//if( r.nextInt()%100>50){ worldS = !worldS;}
	if( keyState[4] ){
		switch(playerAction){
			case playerStand_R:
			case playerRun_R:
				playerAction = playerAttack_R;//or Attack2_R
				if( !playerBulleting /* 能量充足?*/){
					playerBulleting = true;
					playerBulletAdd = 0;
					playerBulletX = playerX- playerBulletWidth;
					playerBulletY = playerY - 50;
					playerBulletStyle = 1;//处理子弹的种类
					playerBulletStepX = 12;//右
				}
				playerActionIndex = 0;
			break;
			case playerStand_L:
			case playerRun_L:
				playerAction = playerAttack_L;//or Attack2_L
				if( !playerBulleting /* 能量充足?*/){
					playerBulleting = true;
					playerBulletAdd = 0;
					playerBulletX = playerX;
					playerBulletY = playerY - 50;
					playerBulletStyle = 1;//处理子弹的种类
					playerBulletStepX = -12;//左
				}
				playerActionIndex = 0;
			break;
		}
	}
	
	
	if(keyState[5])gameState = stateMenu;
	 
	
}

public void paintMap(Graphics g){
	g.setColor(0,0,0);
	g.fillRect(0,0,W,H+12);
	 
	for(int i = 0; i < 6/*mapHeight*/; i++){
		  for(int j = 0; j < W/32+2; j++){
				g.setClip(mapX+worldShakeX+j*32,mapY+worldShakeY+i*32,32,32);
				g.drawImage(mapImage,mapX+worldShakeX+j*32,mapY+worldShakeY+(i-Math.abs(currentMap[winX+(winY+i)*mapWidth+j])+1)*32,0);
		  }
	}
	g.setClip(0,0,W,H);
	
}

public void paintMan(Graphics g){
 	//	System.out.println( "playerX ="+playerX+"  |   playerY ="+playerY);
		drawAction(gamePlayer1, playerX+worldShakeX,playerY+worldShakeY,playerActionClip,g);
		if( playerBulleting )drawBullet(g);
		g.setColor(0,100,255);
		//g.drawRect(playerX- playerRadiiX/2 , playerY - 50 , playerRadiiX , 50);
		//g.drawString("winX"+winX,10,30,0);
		//g.drawString("winY"+winY,10,60,0);
		//g.setColor(255,0,0);
		//g.fillRect(playerX,playerY,2,2);
		//g.setColor(200,0,0);// 内存测试
		//long t = Runtime.getRuntime().freeMemory();// 内存测试  // 133 132  132 552
		//String ss = String.valueOf(t);
		//g.drawString("剩余"+ss, 0 , 90 , 20);// 内存测试
		//g.setColor(200,200,0);
		//if( !godMode )g.drawString("God Mode", 100 , 30 , 20);
		 
		
	 
}

public void playerMove(){
	/*if(getValue(getPosX(playerX),getPosY(playerY-playerHeight)) == 2){
		switch(playerAction){
			case playerStand_L:
				playerAction = playerCreep_L;
			break;
			case playerStand_R:
				playerAction = playerCreep_R;
			break;
		}
	}*/
	
	if (getPosX(playerX) >= specialArea[currentMapID-1][0] && getPosX(playerX) <= specialArea[currentMapID-1][0] + specialArea[currentMapID-1][2] && getPosY(playerY) >= specialArea[currentMapID-1][1] && getPosY(playerY) <= specialArea[currentMapID-1][1] + specialArea[currentMapID-1][3] ){
	     Add = 0;
	     loadMap = true;
	     currentMapID = specialArea[currentMapID-1][4];
	     winX = specialArea[currentMapID-1][5];
	     winY = specialArea[currentMapID-1][6];
	     mapY = 26;
	     if(specialArea[currentMapID-1][7] >0 ){
	          playerAction = playerStand_R;
	     }else {
	          playerAction = playerStand_L;
	     }
	}
	
	
	switch(playerAction){
		 case playerStand_R:
		 	playerActionClip = 0;
		 	//System.out.println("Stand");
		 break;
		 case playerStand_L:
		 	playerActionClip = 12;
		 break;
		 case playerFall_R:
		 	playerActionClip = 5;
		 	if( !moveAble(playerX+playerRadiiX,playerY-35) && playerY - 40-mapY - (getPosY(playerY)-winY-1)*32 < playerRadiiX/2 && playerFallValue >= 0 && moveAble(playerX-playerRadiiX,playerY - 40)){/////*
		 		playerY = mapY + (getPosY(playerY)-winY-1)*32;
		 		playerX = mapX + (getPosX(playerX+playerRadiiX)-winX)*32 -2;
		 		playerAction = playerHang_R;
		 		playerActionClip = 7;
		 	}
		 	cameraFollow(0,playerFallValue);
		 break;
		 case playerFall_L:
		 	playerActionClip = 17;
		 	if( !moveAble(playerX-playerRadiiX,playerY-35) && playerY - 40-mapY - (getPosY(playerY)-winY-1)*32 < playerRadiiX/2 && playerFallValue >= 0 && moveAble(playerX+playerRadiiX,playerY - 40)){/////*
		 		playerY = mapY + (getPosY(playerY)-winY-1)*32+28;
		 		playerX = mapX + (getPosX(playerX-playerRadiiX)-winX)*32 + 20 +3 ; // winX += 1
		 		playerAction = playerHang_L;
		 		playerActionClip = 19;
		 	}
		 	cameraFollow(0,playerFallValue);
		 break;
		 case playerRun_R://..............................
		 	 
		 	
		 	if( moveAble(playerX+playerRadiiX,playerY-5)){
				cameraFollow(playerActionList[playerAction][playerActionIndex+1],playerActionList[playerAction][playerActionIndex+2]);
		 	}
		
		 	playerActionClip = playerActionList[playerAction][playerActionIndex];
		 	//playerActionFrameSpeed --;
		 	if( Add%2 == 0)playerActionIndex += 3;
		 	if(playerActionIndex > playerActionList[playerAction].length-3){
		 		playerActionIndex = 0;
		 	//	playerActionFrameSpeed = 3;
		 		playerAction = playerStand_R;
		 	}
		 
		break; 
		 
		case playerRun_L://..............................
		
			
		 	if( moveAble(playerX-playerRadiiX,playerY-5)){
				cameraFollow(playerActionList[playerAction][playerActionIndex+1],playerActionList[playerAction][playerActionIndex+2]);
		 	}
		
		 	playerActionClip = playerActionList[playerAction][playerActionIndex];
		 	//playerActionFrameSpeed --;
		 	if( Add%2 == 0)playerActionIndex += 3;
		 	if(playerActionIndex > playerActionList[playerAction].length-3){
		 		playerActionIndex = 0;
		 		//playerActionFrameSpeed = 3;
		 		playerAction = playerStand_R;
		 	}
		break;
		case playerJump_R://..............................
			// System.out.println("Jumping");
			if( !moveAble(playerX+playerRadiiX,playerY-5)){
				playerAction = playerFall_R;
				//playerFallValue = 0;
				break;
				
			}
			if( !moveAble(playerX,playerY-35)){
			     playerFallValue = Math.abs( playerFallValue/2 );
			}
			if(playerFallValue<=0){
				playerActionClip = 4;
			}else{
				playerActionClip = 5;
			}
			cameraFollow( playerSpeed,playerFallValue);
		break;
		case playerJump_L://..............................
			
			if( !moveAble(playerX-playerRadiiX,playerY-5)){
				playerAction = playerFall_L;
				//playerFallValue = 0;
				break;
				 
			}
			if( !moveAble(playerX,playerY-35)){
			     playerFallValue = Math.abs( playerFallValue/2 );
			}
			if(playerFallValue<=0){
				playerActionClip = 16;
			}else{
				playerActionClip = 17;
			}
			cameraFollow(-playerSpeed,playerFallValue);
		break;
		case playerCreep_R://.............................*
			System.out.println(" this  is Null !");
		break;
		case playerCreep_L://.............................*
			System.out.println(" this  is  Null !");
		break;
		case playerHang_R://..............................*
		break;
		case playerHang_L://..............................*
		break;
		/*case playerAttack_R://............................*
			
			if( moveAble(playerX+playerRadiiX,playerY-5)){
				cameraFollow(playerActionList[playerAction][playerActionIndex+1],playerActionList[playerAction][playerActionIndex+2]);
		 	}
		 	playerActionIndex += 3;
		 	if(playerActionIndex > playerActionList[playerAction].length-3){
		 		playerActionIndex = 0;
		 		playerAction = playerStand_R;
		 	}
		 	
		 	
		break;
		case playerAttack_L://............................*
			
			if( moveAble(playerX-playerRadiiX,playerY-5)){
				cameraFollow(playerActionList[playerAction][playerActionIndex+1],playerActionList[playerAction][playerActionIndex+2]);
		 	}
		 	playerActionIndex += 3;
		 	if(playerActionIndex > playerActionList[playerAction].length-3){
		 		playerActionIndex = 0;
		 		playerAction = playerStand_L;
		 	}
		 	 
		break;*/
		case playerKill_R://..............................*
		break;
		case playerKill_L://..............................*
		break;
 
		default:
			//System.out.println("a");
			//System.out.println("Climbing");
		 	//System.out.println("b");
			cameraFollow(playerActionList[playerAction][playerActionIndex+1],playerActionList[playerAction][playerActionIndex+2]);
			//System.out.println("c");
			playerActionClip = playerActionList[playerAction][playerActionIndex];
		 	//playerActionFrameSpeed --;
		 	if( Add%2 == 0)playerActionIndex += 3;
		 	if(playerActionIndex > playerActionList[playerAction].length-3){
		 		playerActionIndex = 0;
		 		//playerActionFrameSpeed = 3;
		 		if( playerAction <= 11){
		 		      playerAction = playerStand_R;
		 		}else{
		 		      playerAction = playerStand_L;
		 		}
		 	}
		 	 
				//System.out.println("E");
		 		 
		 		
		 	 
		 	//System.out.println(playerActionIndex);
		 break;
		
	}
 
/*	if( !moveAble(playerX+playerRadiiX/2,playerY-5) && playerAction == playerFall_R){
		cameraFollow(-playerRadiiX/2,playerFallValue);
		playerFallValue = 0;
	}else if( !moveAble(playerX-playerRadiiX/2,playerY-5) && playerAction == playerFall_L){
		cameraFollow(playerRadiiX/2,playerFallValue);
		playerFallValue = 0;
	}*/
 
	if(playerX<playerRadiiX){
	 	playerX = playerRadiiX;
	 }else if(playerX>W-playerRadiiX){
	 	playerX = W-playerRadiiX;
	 }
 
	 if(playerFallValue>=0 &&   !moveAble(playerX,playerY) && playerAction != playerClimb_R && playerAction != playerClimb_L  ){
	 	//System.out.println("* "+playerAction);
					switch(playerAction){
						case playerJump_L:
						case playerFall_L:
							playerAction = playerStand_L;
						break;
						case playerFall_R:
						case playerJump_R:
							playerAction = playerStand_R;
						break;
					}
					playerY = mapY+(getPosY(playerY)-winY)*32;
					
					playerFallValue = 0; 
	}
 
	 if( moveAble(playerX,playerY) && (playerAction == playerStand_R || playerAction == playerStand_L || playerAction == playerRun_R || playerAction == playerRun_L )){
	 	//System.out.println(" ->now Action is "+playerAction);
	 	switch(playerAction){
						case playerStand_L:
						case playerRun_L:
						case playerJump_L:
							playerAction = playerFall_L;
							//System.out.println("3");
						break;
						case playerJump_R:
						case playerRun_R:
						case playerStand_R:
							playerAction = playerFall_R;
							//System.out.println("2");
						break;

					}
		playerFallValue = 0;
		//System.out.println("goto Fall ->now Action is "+playerAction);
	 }
	 //System.out.println(playerAction);
	 if( playerBulleting )playerBulletUpdate();
}


public void playerBulletUpdate(){
	//System.out.println(" updateBullet");
	//switch(playerBulletStyle){}
	playerBulletX += playerBulletStepX;
	if ( enemyNormX != 0 ){
		playerBulletX += enemyNormX;
	}
	if ( enemyNormY != 0 ){
		playerBulletY += enemyNormY;
	}
	if( playerBulletX > W+100 || playerBulletX < -100){
		playerBulleting = false;
	}

}
public void drawBullet(Graphics g){
	//System.out.println(" drawBullet");
	//switch(playerBulletStyle){
	//}
	if( playerBulletStepX > 0){
	     if( Add%3 ==0){
               g.setClip(playerBulletX , playerBulletY ,42,35);
	          g.drawImage( gamePlayer1 , playerBulletX ,playerBulletY -113,0);
          }else if( Add%3 ==1){
               g.setClip(playerBulletX , playerBulletY ,76,32);
	          g.drawImage( gamePlayer1 , playerBulletX -42,playerBulletY -113,0);
          }else{
               g.setClip(playerBulletX , playerBulletY ,82,43);
	          g.drawImage( gamePlayer1 , playerBulletX -118,playerBulletY -113,0);
          }
     }else{
          if( Add%3 ==0){
               g.setClip(playerBulletX- 42 , playerBulletY ,42,35);
	          g.drawImage( gamePlayer1 , playerBulletX -357 ,playerBulletY -113,0);
          }else if( Add%3 ==1){
               g.setClip(playerBulletX - 76 , playerBulletY ,76,32);
	          g.drawImage( gamePlayer1 , playerBulletX -282 ,playerBulletY  -113,0);

⌨️ 快捷键说明

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