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

📄 corpse.java

📁 恶魔城-晓月圆舞曲 JAVA手機遊戲
💻 JAVA
字号:
import java.util.Random;

import javax.microedition.lcdui.*;
//equip
//BrawnMan
public class Corpse extends Enemy{
	static final byte LEFT_MOVE = 0; //向左移动
	static final byte RIGHT_MOVE = 1;//向右移动
	static final byte LEFT_BRON = 2; //左出生
	static final byte RIGHT_BRON = 3;//右出生
	static final byte DEAD = 4; //左死亡
	private static final byte DELETE = 5;//右死亡
	static final byte LEFT_LEAVE = 6;//左离开
	static final byte RIGHT_LEAVE = 7;//右离开
	static final byte NONE = 8;
	private byte distance = 127;//Corpse移动的距离
	byte att,def;
	byte hp;

	private short[][] mode;
	
	protected boolean isDead()
	{
		if(enemyState == DEAD || enemyState == NONE || enemyState == DELETE )
		{
			return true;
		}
		return false;
	}

	private static short[][] bron = new short[][]{
			{3,12,23,44,0,0,0,0},
			{29,13,49,44,0,0,0,0},
			{58,12,80,44,0,0,0,0}
	};
	private static short[][] leave = new short[][]{
			{58,12,80,44,0,0,0,0},
			{29,13,49,44,0,0,0,0},
			{3,12,23,44,0,0,0,0}
	};
	private static short[][] walk_mode1 = new short[][]{
			{80,12,112,44,-12,-1,2,-1},
			{156,11,187,44,-12,-2,2,-2},
			{279,12,312,44,-10,-1,-4,-1}
	};
	private static short[][] walk_mode2 = new short[][]{
			{118,10,156,44,-17,-3,0,-3},
			{197,8,242,44,-23,-5,0,-5},
			{242,8,274,44,-10,-5,0,-5}
	};

	public Corpse()
	{
		initAction();// must be first
		initBase();	
	}
	private void initBase()
	{
		random += 5;
		setRoleY((short)173);
		Random r = new Random(random);
		int n = Math.abs(r.nextInt()%100);
		if(n>50)
			mode = walk_mode1;
		else 
			mode = walk_mode2;
		n = Math.abs(r.nextInt()%100);
		if(n>50)
		{
			n = Math.abs(r.nextInt()%60);
			short dis = (short)(CastleCanvas.soma.roleX+n);
			if(dis>(52*16-90))
				dis = 52*16-120;
			if(dis<70)
				dis = 70;
			setRoleX(dis);
			changState(LEFT_BRON);
		}
		else
		{
			n = Math.abs(r.nextInt()%60);
			short dis = (short)(CastleCanvas.soma.roleX-n);
			if(dis<70)
				dis = 80;
			if(dis>(52*16-90))
				dis = 52*16-120;
			setRoleX(dis);
			changState(RIGHT_BRON);
		}
		speed = 1;	
		brTime = 400;
		hp = 18;
		att = 16;
		def = 4;
		exp = 9;
	}
	public void initAction()
	{
		actionFrame = new byte[]{
				(byte)walk_mode1.length,//向左移动
				(byte)walk_mode1.length,//向右移动
				(byte)bron.length,//左出生
				(byte)bron.length,//右出生
				(byte)dead.length,//左死亡
				(byte)dead.length,//右死亡
				(byte)leave.length,//左离开
				(byte)leave.length,//右离开
				0,//NULL
		};
	}
	protected void dead()
	{
		if(enemyState!=DEAD)
		{
			changState(DEAD);
		}			
	}
	public void paint(Graphics g)
	{
		tickEnemyXY();
		boolean run = false;
		if(enemyState == LEFT_LEAVE || enemyState == RIGHT_LEAVE ||
				enemyState == NONE || enemyState == DELETE || enemyState == DEAD)
			run = true;
		if(x<190 && x>-20 && y>-20 && y<240  || run)
		switch(enemyState)
		{
		case LEFT_MOVE:
			drawLeftWalk(g);
			setDir(false);
			move();
			break;
		case RIGHT_MOVE:
			drawRihgtWalk(g);
			setDir(true);
			move();
			break;
		case LEFT_BRON:
			drawLeftBron(g);
			changWaitState(Corpse.LEFT_MOVE);
			drop();
			break;
		case RIGHT_BRON:
			drawRightBron(g);
			changWaitState(Corpse.RIGHT_MOVE);
			drop();
			break;
		case DEAD:
			drawLeftDead(g);
			changWaitState(DELETE);
			break;
		case DELETE:
			CastleCanvas.enemy.removeElement(this);
			break;
		case LEFT_LEAVE:
			drawLeftLeave(g);
			if(isOneTimes())
				changState(Corpse.NONE);
			break;
		case RIGHT_LEAVE:
			drawRightLeave(g);
			if(isOneTimes())
				changState(Corpse.NONE);
			break;
		case NONE:
			CastleCanvas.enemy.removeElement(this);
			break;
		}
		if(enemyState == LEFT_MOVE || enemyState == RIGHT_MOVE)
			tickDistance();
	}
	private void tickDistance()
	{
		distance -= speed;
		if(distance<=0)
		{
			if(dir)
			{
				changState(Corpse.RIGHT_LEAVE);
			}
			else
			{
				changState(Corpse.LEFT_LEAVE);
			}
		}
		if(isTouchBack())
		{
			if(dir)
			{
				changState(Corpse.RIGHT_LEAVE);
			}
			else
			{
				changState(Corpse.LEFT_LEAVE);
			}
		}
	}
	private void drawLeftDead(Graphics g)
	{
		tickArgmentMirror(dead);
		drawLeftRole(g,enemy);
	}
	private void drawLeftWalk(Graphics g)
	{
		tickArgmentMirror(mode,(byte)8);
		drawLeftRole(g,enemy);	
	}
	private void drawRihgtWalk(Graphics g)
	{
		tickArgment(mode,(byte)8);
		drawRightRole(g,enemy);
	}
	private void drawLeftBron(Graphics g)
	{
		tickArgmentMirror(bron,(byte)5);
		drawLeftRole(g,enemy);	
	}
	private void drawRightBron(Graphics g)
	{
		tickArgment(bron,(byte)5);
		drawRightRole(g,enemy);
	}
	private void drawLeftLeave(Graphics g)
	{
		tickArgmentMirror(leave,(byte)8);
		drawLeftRole(g,enemy);
	}
	private void drawRightLeave(Graphics g)
	{
		tickArgment(leave,(byte)8);
		drawRightRole(g,enemy);
	}
	public boolean hit(RoleBase r)
	{
		if(dir)
		{								//17 RoleMan.imgW 定值			
			if(x+ox+imgW>=r.x+r.ox && r.x+17+r.ox>=x+ox+23 && y+oy+imgH-5>=r.y+r.oy && r.y+r.imgH-5+r.oy>=y+oy)
			{
				if(enemyState !=RIGHT_BRON && enemyState !=LEFT_BRON 
						&& enemyState !=LEFT_LEAVE && enemyState !=RIGHT_LEAVE)
					return true;
			}
			return false;
		}
		else
		{
			if(x+mirx+imgW-25>=r.x+r.mirx+5 && r.x+17+r.mirx>=x+mirx+9 && y+miry+imgH-5>=r.y+r.miry && r.y+r.imgH-5+r.miry>=y+miry)
			{
				if(enemyState !=RIGHT_BRON && enemyState !=LEFT_BRON 
						&& enemyState !=LEFT_LEAVE && enemyState !=RIGHT_LEAVE)
					return true;
			}
			return false;
		}
	}
}

⌨️ 快捷键说明

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