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

📄 player.java

📁 自己写的一个手机游戏
💻 JAVA
字号:

import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class player {
	final short ScreenWidth = 240;

	final short ScreenHeight = 310;
	final short Width = 1820;
	final short height=70;

	Image juese,jueseL;

	int x = 0;

	int y = 165;

//	boolean down = false;
//
//	boolean up = false;
//
//	boolean right = false;//没有按下右
//
//	boolean left = false;

	int index = 3;

	int indexy = 0;
	short speed=5;
//	人物状态
	final byte Stand=0;
	final byte Run=1;
	
	final byte JumpUP=2;
	final byte JumpDOWN=3;
	
	final byte QKJumpUP=4;
	final byte QKJumpDOWN=5;

	final byte HKJumpUP=6;
	final byte HKJumpDOWN=7;
	
	final byte GongjiQ=8;
	final byte GongjiJ=9;
	
	final byte StandL=10;
	final byte RunL=11;
	
	final byte JumpUPL=12;
	final byte JumpDOWNL=13;
	
	final byte QKJumpUPL=14;
	final byte QKJumpDOWNL=15;

	final byte HKJumpUPL=16;
	final byte HKJumpDOWNL=17;
	
	final byte GongjiQL=18;
	final byte GongjiJL=19;
	
	final byte RunS=20;
	final byte RunX=21;
	final byte RunSL=22;
	final byte RunXL=23;
	byte RWZT=Stand;
	//37,4
	int RWdate[][]={{0,0,30,70},
			{30,0,30,70},
			{60,0,30,70},//走路(0,2)
			{90,0,52,70},
			{142,0,51,70},
			{193,0,53,70},
			{246,0,51,70},//预备(3,6)
			{297,0,30,70},
			{327,0,54,70},
			{381,0,34,70},
			{415,0,39,70},
			{454,0,43,70},
			{497,0,54,70},//前空翻(7,12)
			{551,0,29,70},
			{580,0,42,70},
			{622,0,33,70},
			{655,0,43,70},
			{698,0,52,70},// 上跳(13,17)
			{750,0,53,70},
			{803,0,67,70},
			{870,0,54,70},// 出拳(18,20)
			{924,0,48,70},
			{972,0,74,70},
			{1046,0,42,70},
			{1088,0,77,70},
			{1165,0,42,70},
			{1207,0,74,70},
			{1281,0,42,70},// 三脚(21,27)
			{1323,0,51,70},
			{1374,0,98,70},
			{1472,0,55,70},
			{1527,0,32,70},
			{1559,0,59,70},
			{1618,0,55,70},
			{1673,0,39,70},
			{1712,0,54,70},
			{1766,0,54,70}// 绝招(28,36)
			};

	public  player() {
		try {
			juese = Image.createImage("/long.png");
			jueseL = Image.createImage(juese, 0, 0, juese.getWidth(), juese.getHeight(), Sprite.TRANS_MIRROR);
		} catch (IOException e) {
			System.out.println("角色图片错误");
		}
	}

	public void Hua(Graphics g) {

		switch(RWZT)
		{
		case Stand:
		case Run:
		case RunS:
		case RunX:
		case GongjiQ:
		case GongjiJ:
		case JumpUP:
		case JumpDOWN:
			g.setClip(x,y,RWdate[index][2],RWdate[index][3]);
			g.drawImage(juese,x-RWdate[index][0],y-RWdate[index][1],0);
			break;
		case StandL:
		case RunL:
		case RunSL:
		case RunXL:
		case GongjiQL:
		case GongjiJL:
		case JumpUPL:
		case HKJumpDOWNL:
			g.setClip(x,y,RWdate[index][2],RWdate[index][3]);
			g.drawImage(jueseL,
					x-jueseL.getWidth()+RWdate[index][0]+RWdate[index][2],
					y-RWdate[index][1],0);
			break;
		}
		zhuangtai();
		move();
	}
	public void move(){
		switch(RWZT)
		{
		case RunS:
		case RunSL:
			y-=speed;
			break;
		case RunX:
		case RunXL:
			y+=speed;
			break;
		}
	}
	public void zhuangtai() {
		switch(RWZT)
		{
		case StandL:
		case Stand:
			zhen(3,6);
			break;
		case Run:
		case RunS:
		case RunX:
			zhen(0,2);
			break;
		case RunL:
		case RunSL:
		case RunXL:
			zhen(-1,1);
		case GongjiQ:
		case GongjiQL:
			zhen(18,20);
			break;
		case GongjiJ:
		case GongjiJL:
			zhen(21,27);
			break;
	
	}
	}
	public void keypressed(int key) {
		switch (key) {
		case -4:
		case 54:
			index=0;
			RWZT=Run;
			indexy = 0;
			break;
		case -3:
			index=0;
			RWZT=RunL;
			indexy = 0;
			break;
		case -2:
			if(RWZT==Stand){
				RWZT=RunX;
			}
			if(RWZT==StandL){
				RWZT=RunXL;
			}
			indexy = 0;
			break;
		case -1:
			index=0;
			if(RWZT==Stand){
				RWZT=RunS;
			}
			if(RWZT==StandL){
				RWZT=RunSL;
			}
			indexy = 0;
			break;
		case 51:
			index=18;
			if(RWZT==Stand||RWZT==Run||RWZT==RunS||RWZT==RunX){
				RWZT=GongjiQ;
			}
			if(RWZT==StandL||RWZT==RunL||RWZT==RunSL||RWZT==RunXL){
				RWZT=GongjiQL;
			}
			break;
		case 49:
			index=21;
			if(RWZT==Stand||RWZT==Run||RWZT==RunS||RWZT==RunX){
				RWZT=GongjiJ;
			}
			if(RWZT==StandL||RWZT==RunL||RWZT==RunSL||RWZT==RunXL){
				RWZT=GongjiJL;
			}
			break;
		}
	}

	protected void keyreleased(int key) {
		switch (key) {
		case 54:
		case -3:
			RWZT=StandL;
			break;
		case -4:
			RWZT=Stand;
			break;
		case -1:
			if(RWZT==RunS){
				RWZT=Stand;
			}
			if(RWZT==RunSL){
				RWZT=StandL;
			}
			break;
		case -2:
			if(RWZT==RunX){
				RWZT=Stand;
			}
			if(RWZT==RunXL){
				RWZT=StandL;
			}
			break;
		case 51:
			if(RWZT==GongjiQ){
				RWZT=Stand;
			}
			if(RWZT==GongjiQL){
				RWZT=StandL;
			}
			break;
		case 49:
			if(RWZT==GongjiJ){
				RWZT=Stand;
			}
			if(RWZT==GongjiJL){
				RWZT=StandL;
			}
			break;
		}
	}
	public void zhen(int a,int b)
	{
		index++;
		if(index>b)
		{
			index=a;
		}
	}

}

⌨️ 快捷键说明

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