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

📄 mycanvas.java

📁 是男人就下100层的游戏的移植到手机上的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			case 53:
			case -5://开火
				powerstart = true;
				break;
			}

		}
		
		if (GameState == 3) {
			if(keyCode == -7)GameState = 1;
		}
		
		if (GameState == 4) {
//			if(keyCode == -6)rms.deleteRS();
			if(keyCode == -7)GameState = 1;
		}

		
		if (GameState != 2) {
			System.gc();
			repaint();
		}

	}

	protected void keyReleased(int keyCode) {//抬起按键

		switch (keyCode) {
		case 52:
		case -3:
			man.MoveAction(0);
		    man.imgX = 9*2;
		    man.imgY = 13;
			break;

		case 54:
		case -4:
			man.MoveAction(0);
		    man.imgX = 9*2;
		    man.imgY = 0;
//			man.face = 0;
			break;
		case 53:
		case -5://开火
			powerstart =false;
			break;
		}

	}

	protected void DrawMan() {//锚点下中
		
		DownCheck();
		bg.setClip(man.manX-4,man.manY-13,9,13);
		
		bg.drawImage(img_man, man.manX-4-man.imgX, man.manY-13-man.imgY, Graphics.TOP
				| Graphics.LEFT);
		
		
	}
	
	protected void DrawEnemy() {//锚点上中
		for(int i=0;i<enemy.EnemyVector.size();i++){
			int a[] = (int[]) enemy.EnemyVector.elementAt(i);
			a[5]++;
			if(HitCheck(man.manX-12,man.manY-20,25,25,a[0]-4,a[1],8,10) && powerstart){
				enemy.EnemyVector.removeElementAt(i);
				Score+=1;
				if(enemy.EnemyVector.size()>0){

					i-=1;
				}
				
			}
			if(HitCheck(man.manX-4,man.manY-13,9,13,a[0]-4,a[1]-2,8,8) && a[5]>15 && !powerstart){
				lift.Lift-=3;
//				hit.play(1);
//				DeviceControl.startVibra(100,500);
				a[5]=0;
				bg.setClip(0,0,width,height);
				bg.setColor(255,0,0);
				bg.fillRect(0,0,width,height);
			}
			bg.setClip(a[0]-4,a[1],8,10);
			bg.drawImage(img_enemy,a[0]-4-a[4],a[1],Graphics.LEFT | Graphics.TOP);
		}
	}
	
	protected void DrawPowerStart() {//锚点中心
		if(powerstart && add > 30 && energy.energy>=0){
			bg.setClip(man.manX-12,man.manY-13-6,25,25);
			bg.drawImage(img_powerC[add%2],man.manX, man.manY-6, Graphics.HCENTER
					| Graphics.VCENTER);
			bg.drawImage(img_power,man.manX, man.manY-6, Graphics.HCENTER
					| Graphics.VCENTER);
		}
	}

	protected void Drawback() {//锚点上中
		for (int i = 0; i < back.BackVector.size(); i++) {
			int a[] = (int[]) back.BackVector.elementAt(i);
			bg.setClip(a[0]-20,a[1],40,6);
			bg.drawImage(img_back, a[0], a[1], Graphics.HCENTER | Graphics.TOP);
			//			System.out.println(i+" aaaa " + a[1]);
		}
	}

	protected void Drawwall() {//画墙和钻头
		
		for (int i = 0; i < 3; i++) {
			bg.setClip(0,i * 48 - add % 4*1,9,48);
			bg.drawImage(img_wall, 0, i * 48 - add % 4*1, 0);
			bg.setClip(119,i * 48 - add % 4*1,9,48);
			bg.drawImage(img_wall, width, i * 48 - add % 4*1, Graphics.TOP
					| Graphics.RIGHT);
		}
//		bg.setClip(119,0,9,height);
		for (int i = 0; i < 11; i++) {
			bg.setClip(i * 10 + 9,10,11,8);
			bg.drawImage(img_sharp, i * 10 + 9 -add%2*11, 10, Graphics.TOP
					| Graphics.LEFT);
		}
	}

	protected void DrawScore() {//画成绩
		bg.setColor(0, 0, 0);
		bg.drawString(string_char[8] + Score, width, 0, Graphics.TOP
				| Graphics.RIGHT);
	}
	
	protected void DrawLift() {
//		System.out.println(" aaaa " + lift.Lift);
		bg.setClip(0,0,35,10);
		bg.setColor(255, 0, 0);
		bg.fillRect(10,3,lift.Lift,4);
		bg.setColor(0, 0, 0);
		bg.drawString("L:",10,0,Graphics.TOP|Graphics.RIGHT);
		if(lift.alive){
			if(lift.Lift_Y <= 18){
				lift.alive = false;
				OutSreen(lift.Lift_X,lift.Lift_Y);
			}
			if(HitCheck(man.manX-4,man.manY-13,9,13,lift.Lift_X,lift.Lift_Y,9,9)){
				lift.alive = false;
				OutSreen(lift.Lift_X,lift.Lift_Y);
				lift.Lift+=5;
				if(lift.Lift>=22)lift.Lift=22;
			}
			bg.setClip(lift.Lift_X,lift.Lift_Y,9,9);
			bg.drawImage(img_lift,lift.Lift_X,lift.Lift_Y,0);
		}
	}
	
	protected void DrawPower() {//画保护膜
		bg.setClip(35,0,35,10);
		bg.setColor(0, 255, 0);
		bg.fillRect(50,3,energy.energy,4);
		bg.setColor(0, 0, 0);
		bg.drawString("P:",50,0,Graphics.TOP|Graphics.RIGHT);
		if(energy.alive){
			if(energy.energy_Y <= 18){
				energy.alive = false;
				OutSreen(energy.energy_X,energy.energy_Y);
			}
			if(HitCheck(man.manX-4,man.manY-13,9,13,energy.energy_X,energy.energy_Y,9,9)){
				energy.alive = false;
				OutSreen(energy.energy_X,energy.energy_Y);
				energy.energy+=5;
				if(energy.energy>=22)energy.energy=22;
			}
			bg.setClip(energy.energy_X,energy.energy_Y,9,9);
			bg.drawImage(img_energy,energy.energy_X,energy.energy_Y,0);
		}
	}
	
	protected void OutSreen(int x,int y){
		x=130;
		y=130;
	}

	protected void NewState() {//初始化状态
		powerstart = false;
		over = false;
		Score = 0;
		lift.Lift  = 22;
		lift.time  = 10;
		lift.alive = false;
		energy.energy = 22;
		energy.time   = 15;
		energy.alive  = false;
//		man.face     = 0;
		man.down     = true;
		man.manY_add = 0;
		man.manX     = 70;
		man.manY     = 30;
		man.manY_0   = man.manY;
		man.imgX     = 9*2;
		man.width_min = 14;
		man.width_max = 114;
		enemy.time = 5;
		back.speed = enemy.speed = lift.speed = energy.speed = man.speed = 1;
		add = 0;
		back.add_time = 36;
		over_add = 0;
		overtime = 30;
//		image_i  = 0;
		back.BackVector.removeAllElements();
		enemy.EnemyVector.removeAllElements();

	}
	
	protected void ChangeState() {//难度控制
		if(Score>90)     {enemy.time = 1;lift.time  = 4;energy.time   = 5;}
		else if(Score>60){enemy.time = 2;lift.time  = 6;energy.time   = 9;}
		else if(Score>30){enemy.time = 3;lift.time  = 8;energy.time   = 13;}
		else if(Score>15){enemy.time = 4;}
	}
	
	protected void DeathCheck() {
		if(lift.Lift<=0 || man.manY > height + 10) {
			over=true;//over控制
//			man.imgY = 0;
		}
		
	}
	
	
	
	public void DownCheck()
	{
		for (int i = 0; i < back.BackVector.size(); i++) {
			int a[] = (int[]) back.BackVector.elementAt(i);
			
			if (a[2] == 2) {
				if(man.manY <= 28){
					man.down = true;
					a[2] = 0;
					lift.Lift -= 10;
//					hit.play(1);
//					DeviceControl.startVibra(100,500);
					bg.setClip(0,0,width,height);
					bg.setColor(255,0,0);
					bg.fillRect(0,0,width,height);
				
				}
				if (a[0] - 20 > man.manX + 1 || a[0] + 20 < man.manX) {
					man.down = true;
					a[2] = 0;
				}
			}
			if (a[2] == 1 && man.down) {
				if (a[0] - 20 > man.manX + 1 || a[0] + 20 < man.manX) {
					a[2] = 0;
				} else if (man.manY > a[1]) {
					man.manY = a[1];
//					stopdown.play(1);
					man.down = false;
					a[2] = 2;
				}
			}
			if (a[0] - 20 < man.manX + 5 && a[0] + 20 > man.manX - 5
					&& man.manY < a[1] && a[2] == 0) {
				a[2] = 1;
			}

		}
	}
	
//	碰撞检测方法
	public boolean HitCheck//锚点都为左上
	(int x1, int y1, int w1, int h1, int x2, int y2, int w2,	int h2)	
	//人  x ,     y ,     宽,      高, 物或怪x,     y,      宽,     高
	{
		int a = 0, b = 0;
        if (x2 <= x1 + w1 && x2 + w2 >= x1)
			a++;
		if (y2 <= y1 + h1 && y2 + h2 >= y1)
			b++;
		return (a > 0 && b > 0);
	}

	public void run() {
		while (true) {
//			ss = System.currentTimeMillis();
			if (GameState == 0) {
				logo_add++;
				if (logo_add >= logotime) {
					GameState = 1;
				}
			}

			if (GameState == 2 && running) {
				ChangeState();
				if (add % back.add_time == 0) {
					back.Add();
					Number++;
					if(Number % lift.time == 0 && !lift.alive){
						lift.Add(back.add_back_X,height,35);
						lift.alive = true;
					}
					if(Number % energy.time == 0 && !energy.alive){
						energy.Add(back.add_back_X,height,35);
						energy.alive = true;
					}
					if(Number % enemy.time == 0){
						enemy.Add(back.add_back_X,height-1);
					}
					
				}
//				image_i = add % 8;
				add++;
				if (add >= back.add_time * 5 + 36) {
					Score++;
//					System.out.println("111111"+man.face);
					add = 36;
				}
				if (add > 25 && !over) {
					man.ManMove();
				}
				if(powerstart  && energy.energy>0){
					energy.energy -= 2;
				}
				if(lift.alive){
					lift.Move();
				}
				if(energy.alive){
					energy.Move();
				}
				
				if(over){
					over_add++;
					if(over_add>=overtime ){
						if(rms.inTop(Score)){
//							rms.writeScore("Good",bScore);

                            inForm = false;
							downman.display.setCurrent(downman.f);

							GameState = 4;

						}else{
							GameState = 1;
						}
						
					}
				}
				
				enemy.Move();
				back.Move();

			}
			ee = System.currentTimeMillis();
//			long Time = ee-ss;
//			if(Time<20L)Time=20L;

			try {
				Thread.sleep(40);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			repaint();
		}

	}

}

⌨️ 快捷键说明

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