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

📄 goods.java

📁 经典FC游戏《超惑星战记》的J2ME版本!!功能基本上都实现了
💻 JAVA
字号:
/**
 * <p>Title: Transpanzer</p>
 * <p>Description:
 * You cannot remove this copyright and notice.
 * You cannot use this file any part without the express permission of the author.
 * All Rights Reserved</p>
 * @author Jjyo
 * @email jjyo@163.com
 * @version 1.0.0
 */

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class Goods extends FSprite{
	
	GameManage gm;
	public int goodsType;
	public static final int POW=1;
	public static final int SUPERPOW=2;
	public static final int HOV=3;
	public static final int SUPERHOV=4;
	public static final int GUN=5;
	public static final int SUPERGUN=6;
	public static final int MISSILE=7;
	public static final int HBALL=8;
	public static final int BOLT=9;
	
	
	boolean running;
	public Goods(GameManage gm) {
		this.gm=gm;
		isHidden=true;
		pow=1;
	}
	
	public void init(int x,int y,int goodsType){
		this.x=x;
		this.y=y;
		this.goodsType=goodsType;
		isHidden=false;
		timeCnt=300;
		running=true;
	}
	
	public void action(){
		if(!isHidden&&running){
			switch(goodsType){
			case POW:
				pow=2;
				frameCnt=3;
				if(checkTankColision()){
					addPow(pow);
				}
				break;
				
			case HOV:
				frameCnt=13;
				if(checkTankColision()){
					addHov(pow);
				}
				break;
				
			case GUN:
				pow=1;
				frameCnt=8;
				if(checkTankColision()){
					addGun(pow);
				}
				break;
				
			
				
				default :
					break;
			}
			if(timeCnt<40){
				if(timeCnt%2==0)
					frameCnt=-2;
			}
			if(timeCnt<0){
				isHidden=true;
			}
			timeCnt--;
		}
	}
	
	public void addPow(int num){
		if(TankSprite.spriteState==TankSprite.TANK){
			TankSprite.tankPow+=num;
			if(TankSprite.tankPow>16)
				TankSprite.tankPow=16;
		}else{
			TankSprite.tanePow+=num;
			if(TankSprite.tanePow>16)
				TankSprite.tanePow=16;
		}
	}
	
	public void addHov(int num){
		TankSprite.tankHov+=num;
		if(TankSprite.tankHov>8)
			TankSprite.tankHov=8;
		
	}
	
	public void addGun(int num){
		TankSprite.kaneGun+=num;
		if(TankSprite.kaneGun>8)
			TankSprite.kaneGun=8;
		
	}
	
	public boolean checkTankColision(){
		if(TankSprite.spriteState==TankSprite.TANE){
			rect1.x=gm.lgr.tankSprite.x;
			rect1.y=gm.lgr.tankSprite.y;
			rect1.dx=16;
			rect1.dy=16;
		}else{
			rect1.x=gm.lgr.tankSprite.x+4;
			rect1.y=gm.lgr.tankSprite.y+16;
			rect1.dx=16;
			rect1.dy=24;
		}
		rect2.x=x;
		rect2.y=y;
		rect2.dx=16;
		rect2.dy=16;
		if(Rect.IntersectRect(rect1, rect2)){
			isHidden=true;
			return true;
		}
		return false;
	}
	
	public void readData(DataInputStream dis) throws IOException{
		super.readData(dis);
		goodsType=dis.readInt();
	}
	
	public void writeData(DataOutputStream dos) throws IOException{
		super.writeData(dos);
		dos.writeInt(goodsType);
	}
}

/***
 * 静态物品
 * @author Administrator
 *
 */
class StaticGoods extends Goods{
	
	private int index;
	private int frame[]={0,1,2,3};
	
	public StaticGoods(GameManage gm,int x,int y,int goodsType){
		super(gm);
		this.gm=gm;
		this.x=x;
		this.y=y;
		isHidden=false;
		timeCnt=300;
		running=false;
		this.goodsType=goodsType;
	}

	public void action(){
		if (x < TankGameCanvas.width + 16 && x > -16 && y > -16
				&& y < TankGameCanvas.height + 16) {
			running=true;
		}
		if(!isHidden&&running){
			switch(goodsType){
			case POW:
				frameCnt=3;
				if(checkTankColision()){
					addPow(2);
				}
				break;
			case SUPERPOW:
				nextFrame(4,3);
				if(checkTankColision()){
					addPow(8);
				}
				break;
			case HOV:
				frameCnt=13;
				if(checkTankColision()){
					addHov(1);
				}
				break;
			case SUPERHOV:
				nextFrame(4,13);
				if(checkTankColision()){
					addHov(4);
				}
				break;
			case GUN:
				frameCnt=8;
				if(checkTankColision()){
					addGun(1);
				}
				break;
			case SUPERGUN:
				nextFrame(4,8);
				if(checkTankColision()){
					addGun(4);
				}
				break;
			case MISSILE:
				frameCnt=2;
				if(checkTankColision()){
					addMissile();
				}
				break;
			case HBALL:
				frameCnt=0;
				if(checkTankColision()){
					addHball();
				}
				break;
			case BOLT:
				frameCnt=1;
				if(checkTankColision()){
					addBolt();
				}
				break;
				default :
					
					break;
			}
			checkTileValue();
			if(frameCnt!=-1)
				timeCnt--;
			if(timeCnt<40){
				if(timeCnt%2==0)
					frameCnt=-2;
			}
			if(timeCnt<0){
				isHidden=true;
			}
		}
	}
	
	public void checkTileValue(){
		char value;
		rect1.y = this.y + Maps.y+8;
		rect1.x = x + Maps.x + 8;
		
		int xTile = rect1.x / Maps.tileSize;
		int yTile = rect1.y / Maps.tileSize;
		
		value=(char)(Maps.mapArray[yTile][xTile] >> 8);
		switch(value){
		case 0x01:	//隐身
		case 0x0f:
			frameCnt=-1;
			break;
		case 0x04:	//水
			break;
		}
	}
	
	public void addMissile(){
		TankSprite.tankMissile+=20;
		if(TankSprite.tankMissile>99){
			TankSprite.tankMissile=99;
		}
	}
	
	public void addHball(){
		TankSprite.tankHball+=20;
		if(TankSprite.tankHball>99)
			TankSprite.tankHball=99;
	}
	
	public void addBolt(){
		TankSprite.tankBolt+=20;
		if(TankSprite.tankBolt>99)
			TankSprite.tankBolt=99;
	}
	
	private void nextFrame(int frameNum,int frameIndex){
		if(index>=frameNum||index<0)
			index=0;
		frameCnt=frame[index]+frameIndex;
			index++;
	}
	
}

/**
 * ----------------TANK BEAM-----------------------
 */

class Beam extends FSprite{
	
	private GameManage gm;
	public byte beamType;
	public static final byte HYPER_BEAM=1;
	public static final byte CRUSHER_BEAM=2;
	public static final byte HOVER_BEAM=3;
	public static final byte KEY_BEAM=4;
	public static final byte DIVE_BEAM=5;
	public static final byte WALL1_BEAM=6;
	public static final byte WALL2_BEAM=7;
	
	public Beam(GameManage gm) {
		this.gm=gm;
		// TODO Auto-generated constructor stub
		isHidden=true;
	}
	
	public void init(int x,int y,byte beamType){
		this.x=x;
		this.y=y;
		this.beamType=beamType;
		isHidden=false;
	}
	
	public void action(){
		if(!isHidden){
			switch(beamType){
			case HYPER_BEAM:
				frameCnt=0;
				if(checkTankColision()){
					TankSprite.HYPER_BEAM=true;
					TankSprite.isChangeScreen=true;
					LoadGameResource.data=0x01;	//切换地图
					
				}
				break;
				
			case CRUSHER_BEAM:
				frameCnt=1;
				if(checkTankColision()){
					
				}
				break;
				
			case HOVER_BEAM:
				frameCnt=2;
				if(checkTankColision()){
					
				}
				break;
				
			case KEY_BEAM:
				frameCnt=3;
				if(checkTankColision()){
					
				}
				break;
				
			case DIVE_BEAM:
				frameCnt=4;
				if(checkTankColision()){
					
				}
				break;
				
			case WALL1_BEAM:
				frameCnt=5;
				if(checkTankColision()){
					
				}
				break;
				
			case WALL2_BEAM:
				frameCnt=6;
				if(checkTankColision()){
					
				}
				break;
			}
		}
	}
	
	private boolean checkTankColision(){
		rect1.x=gm.lgr.tankSprite.x+4;
		rect1.y=gm.lgr.tankSprite.y+16;
		rect1.dx=16;
		rect1.dy=24;
		rect2.x=x;
		rect2.y=y;
		rect2.dx=24;
		rect2.dy=14;
		if(Rect.IntersectRect(rect1, rect2)){
			isHidden=true;
			return true;
		}
		return false;
	}
}

⌨️ 快捷键说明

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