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

📄 enemywalk.java

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

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


public class EnemyWalk extends ZonSprite {

	public EnemyWalk(int scrWidth, int scrHeight) {
		super(scrWidth, scrHeight);
		setRealSize(24, 24);
	}

	public static final int SPEED = 3;
	
	
	public static final int FROZEN_TIME = 40;
	
	public static final int WARNNING_TIME = 32;
	
	public static final int SPRITETYPE_SPRING = 0;
	
	public static final int SPRITETYPE_BLUEFOOT = 1;
	
	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 = 0xFFFF;
	
	
	
	public boolean saveData(DataOutputStream dos){
		if(!super.saveData(dos))
			return false;
		try {
			dos.writeBoolean(isCaptured);
			dos.writeBoolean(isKicked);
			dos.writeInt(frameTimeCount);
			dos.writeInt(captureTimer);
			dos.writeByte(spriteType);
		}
		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();
			spriteType = dis.readByte();
		}
		
		catch(Exception e) {
			return false;
		}
		
		return true;
	}
	
	void mainAction() {
		
		if(isKicked){
			if(moveDirection == MOVEDIRECTION_RIGHT)
				move(6 * SPEED, -6 * SPEED);
			else
				move(-6 * SPEED, -6 * 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 == SPRITETYPE_SPRING){
				frameIndex = 8;
			} else if (spriteType == SPRITETYPE_BLUEFOOT){
				frameIndex = 4;
			}
			
			return;
		}
		
		if(offsetX < scrWidth && offsetX + frameWidth > 0){
			isVisible = true;
		}else 
			isVisible = false;
	
		if(spriteType == SPRITETYPE_SPRING){
			if(moveDirection == MOVEDIRECTION_LEFT){
				if(frameIndex == 7)
					hVelocity = - SPEED;
				else
					hVelocity = 0;
			}else{
				if(frameIndex == 7)
					hVelocity = SPEED;
				else 
					hVelocity = 0;  
			}
		} else if (spriteType == SPRITETYPE_BLUEFOOT){
			if(moveDirection == MOVEDIRECTION_LEFT){
					hVelocity = - SPEED - 1;
			}else{
					hVelocity = SPEED + 1;
			}
		}

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

		
/*		int collidesWithMap = collidesWith(map, false);
		
		if((collidesWithMap & COLLIDES_VERTICAL) == COLLIDES_VERTICAL){
			vVelocity = 0;
		}*/
		
		
		if(frameTimeCount++ > 1){
			frameTimeCount = 0;
			nextFrame();
		}

		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 + -