sprite.java

来自「用J2ME实现的战棋类小游戏DEMO,寻路用A星算法,因为时间关系物品使用功能请」· Java 代码 · 共 209 行

JAVA
209
字号
package midp20;

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

public class Sprite extends Layer {
	
	public boolean alive=true;
	public String name;
	public int  HMAD[]=new int[4] ;
	
	

	public int[] down = { 0, 1, 2, 3 };

	public int[] left = { 4, 5, 6, 7 };

	public int[] right = { 8, 9, 10, 11 };

	public int[] up = { 12, 13, 14, 15 };
	
	public int[] getup(){
		return up;
	}
	public int[] getdown(){
		return down;
	}
	public int[] getleft(){
		return left;
	}
	public int[] getright(){
		return right;
	}
	

	public static final int d_up = 0;

	public static final int d_down = 1;

	public static final int d_left = 2;

	public static final int d_right = 3;



	//hp  mp  ap  def
	public int shuXing[]=new int[4];
	
	public void setShuXing(int hp,int mp,int ap,int def){
		shuXing[0]=hp;
		shuXing[1]=mp;
		shuXing[2]=ap;
		shuXing[3]=def;
	}

	// 精灵的方向
	int direct = 0;

	// 地图切片的尺寸
	int maptilesize = 16;

	// 当前的帧序列
	int[] currentFrames;

	int currentFrame = 0;

	// 精灵的移动频率
	int aa = 0;
	int cc=0;

	// 精灵的移动速度
	int speed = 6;

	// 精灵移动的周期
	int LOP = 4;

	public Sprite(Image img, int width, int height) {
		super(img, width, height);
	}

	public void setCurrentFrames(int[] current) {
		currentFrames = current;
		currentFrame = 0;
	}

	public void setCurrentFrame(int frame) {
		currentFrame = frame;
		tileIndex = currentFrames[currentFrame];
	}

	public void prevFrame() {
		tileIndex = currentFrames[(--currentFrame + currentFrames.length)
				% currentFrames.length];
	}

	public void nextFrame() {

		tileIndex = currentFrames[(++currentFrame) % currentFrames.length];

	}

	public void moveSprite(int keycode) {
		if (aa < 4) {
			aa++;
		} else {

			aa = 0;

			switch (keycode) {
			case -1:
//				if (direct != d_up) {
//					this.setCurrentFrames(up);
//					direct = d_up;
//				} else {
					nextFrame();
					move(0, -speed);
//			}
				break;
			case -2:

//				if (direct != d_down) {
//					this.setCurrentFrames(down);
//					direct = d_down;
//				} else {
					nextFrame();
					move(0, speed);
//				}
				break;
			case -3:
//				if (direct != d_left) {
//					this.setCurrentFrames(left);
//					direct = d_left;
//				} else {
					nextFrame();
					move(-speed, 0);
//				}
				break;
			case -4:
//				if (direct != d_right) {
//					this.setCurrentFrames(right);
//					direct = d_right;
//				} else {
					nextFrame();
					move(speed, 0);
//				}
				break;

			}

		}
	}
	
	public void moveSpritePWLA() {
		//System.out.println("cc="+cc);
	
		if (cc < 2) {
			cc++;
		} else {

			cc = 0;
			nextFrame();
		}
		
		
	}
           
	
	





	public boolean collidesWith(int keycode, TiledLayer t) {

		return false;
	}

	public void paint(Graphics g) {
	
		// System.out.println(tileIndex);
		int x_des = tileIndex % column * width;
		//System.out.println("x_des==" + x_des);
		int y_des = tileIndex / column * height;
		//System.out.println("y_des==" + y_des);
	
		g.setClip(x - TiledLayer.x_window, y -24
				- TiledLayer.y_window, width, height);
		g.drawImage(resouce, x - x_des-TiledLayer.x_window, y - y_des-24-TiledLayer.y_window,
				0);
	}
	public void paintPWLA(Graphics g) {
		
		// System.out.println(tileIndex);
		int x_des = tileIndex % column * width;
		//System.out.println("x_des==" + x_des);
		int y_des = tileIndex / column * height;
		//System.out.println("y_des==" + y_des);
	
		g.setClip(x - 12- TiledLayer.x_window, y -12
				- TiledLayer.y_window, width, height);
		g.drawImage(resouce, x -12- x_des-TiledLayer.x_window, y - y_des-12-TiledLayer.y_window,
				0);
	}
	
	 

}

⌨️ 快捷键说明

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