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

📄 enemyjump.java

📁 基于J2ME 开发的冒险类手机游戏
💻 JAVA
字号:
package zonja;

import java.io.DataInputStream;
import java.io.DataOutputStream;


public class EnemyJump extends ZonSprite {

	public EnemyJump(int scrWidth, int scrHeight) {
		super(scrWidth, scrHeight);
		setRealSize(32, 24);
		// TODO Auto-generated constructor stub
	}

//	public static final int SPEED = 6;
	public static final int SPEED = 6;
	
	public static final int FROZEN_TIME = 40;
	
	public static final int WARNNING_TIME = 32;
	
	private boolean isCaptured = false;
	
	private boolean isKicked = false;
	
	private int captureTimer = 0;


	private int startX = 0;

	private int endX = 0;

	private int frameTimeCount = 0;
	
	private int spriteType = 0;
	
	public static final int JUMPTYPE_TOP = 0;
	
	public static final int JUMPTYPE_MUSHROOM = 1;
	
	public boolean saveData(DataOutputStream dos){
		if(!super.saveData(dos))
			return false;
		try {
			dos.writeBoolean(isCaptured);
			dos.writeBoolean(isKicked);
			dos.writeInt(frameTimeCount);
			dos.writeInt(captureTimer);
		}
		catch(Exception e) {
			return false;
		}
		
		return true;
	}
	
	public boolean loadData(DataInputStream dis){
		if(!super.loadData(dis))
			return false;
		try {
			isCaptured = dis.readBoolean();
			isKicked = dis.readBoolean();
			frameTimeCount = dis.readInt();
			captureTimer = dis.readInt();
		}
		
		catch(Exception e) {
			return false;
		}
		
		return true;
	}

	void mainAction() {

		hVelocity = 0;
		vVelocity = 0;
	
		if(isKicked){
			if(moveDirection == MOVEDIRECTION_RIGHT)
				move(3 * SPEED, -3 * SPEED);
			else 
				move(-3 * SPEED, -3 * SPEED);
			return;
		}
		if(isCaptured){
			if(captureTimer++ > FROZEN_TIME){
				isCaptured = false;
				captureTimer = 0;
			}
			if(captureTimer > WARNNING_TIME){
				if(captureTimer % 4 == 0)
					isVisible = false;
				else
					isVisible = true;
			}
			
			if(spriteType == JUMPTYPE_TOP)
				frameIndex = 6;
			else if(spriteType == JUMPTYPE_MUSHROOM)
				frameIndex = 5;
			return;
		}
		
		if(offsetX < scrWidth && offsetX + frameWidth > 0){
			isVisible = true;
		}else 
			isVisible = false;
		
		if(spriteType == JUMPTYPE_TOP){
			switch (frameTimeCount) {
			case 1:
			case 5:
				setFrameSequence(3, 3);
				break;
			case 2:
			case 6:
				setFrameSequence(4, 4);
				break;
			case 3:
			case 7:
				setFrameSequence(5, 5);
				break;
			case 4:
				setFrameSequence(2, 2);
				if (moveDirection == MOVEDIRECTION_RIGHT) {
					hVelocity += EnemyJump.SPEED;
				} else {
					hVelocity -= EnemyJump.SPEED;
				}
				break;
			case 8:
				setFrameSequence(2, 2);
				break;
			case 9:
				setFrameSequence(1, 1);
				vVelocity = -18;
				break;
			case 10:
				setFrameSequence(1, 1);
				vVelocity = -12;
				break;
			case 11:
				setFrameSequence(1, 1);
				vVelocity = -6;
				break;
			case 12:
				setFrameSequence(1, 1);
				vVelocity = -4;
				break;
			case 13:
				setFrameSequence(1, 1);
				vVelocity = 4;
				break;
			case 14:
				setFrameSequence(1, 1);
				vVelocity = 6;
				break;
			case 15:
				setFrameSequence(1, 1);
				vVelocity = 12;
				break;
			case 16:
				setFrameSequence(1, 1);
				vVelocity = 18;
				break;
			}
			if (frameTimeCount++ > 16)
				frameTimeCount = 0;
		} else if (spriteType == JUMPTYPE_MUSHROOM){
			switch(frameTimeCount){
			case 1:
			case 2:
			case 3:
			case 4:
				frameIndex = 3;
				vVelocity -= 12;
				if (moveDirection == MOVEDIRECTION_RIGHT) {
					hVelocity += EnemyJump.SPEED;
				} else {
					hVelocity -= EnemyJump.SPEED;
				}

				  break;
			case 5:
			case 6:
			case 7:
			case 8:
				frameIndex = 4;
				vVelocity += 12;
				if (moveDirection == MOVEDIRECTION_RIGHT) {
					hVelocity += EnemyJump.SPEED;
				} else {
					hVelocity -= EnemyJump.SPEED;
				}

				break;
			case 9:
			case 10:
			case 11:
			case 12:
				frameIndex = 2;
				break;
			}
			if (frameTimeCount++ > 12)
				frameTimeCount = 0;
		}


		
		if (worldOffsetX + hVelocity <= startX) {
			hVelocity = startX - worldOffsetX;
			moveDirection = MOVEDIRECTION_RIGHT;
		}

		if (worldOffsetX + hVelocity >= endX) {
			hVelocity = endX - worldOffsetX;
			moveDirection = MOVEDIRECTION_LEFT;
		}

		move(hVelocity, vVelocity);
		changeWorldOffset(hVelocity, vVelocity);
	}

	public void setStartOffset(int x, int y) {
		startX = x;
		endX = y;
	}
	
	public void setCaptured(boolean b){
		isCaptured = b;
	}
	
	public boolean getCaptured(){
		return isCaptured;
	}
	
	public void setKicked(boolean b){
		isKicked = b;
	}

	public boolean isKicked(){
		return isKicked;
	}
	
	public int getSpriteType() {
		return spriteType;
	}

	public void setSpriteType(int spriteType) {
		this.spriteType = spriteType;
	}
}

⌨️ 快捷键说明

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