pardata.java

来自「是男人就撑过20秒,我写到了手机上,算法什么的都还未完工,但已能运行.加了个简单」· Java 代码 · 共 63 行

JAVA
63
字号
import javax.microedition.lcdui.*;

public class pardata {
		private int x_pos,y_pos;
		private int x_vel,y_vel;
		private int screenWidth;
		private int screenHeight;

		private Image parti;
		
		pardata(int drawX,int drawY,int xVel,int yVel,int width,int height){
			this.x_pos = drawX;
			this.y_pos = drawY;
			this.x_vel = xVel;
			this.y_vel = yVel;
			this.screenWidth = width;
			this.screenHeight = height;
		}
		
		void updateParticle(int timedel){
			
		this.x_pos += this.x_vel*(timedel/20);
		this.y_pos += this.y_vel*(timedel/20);
		
		if(this.x_pos<0)
		this.x_pos=screenWidth;
		
		if(this.x_pos>screenWidth)
		this.x_pos=0;
		
		if(this.y_pos>screenHeight)
		this.y_pos=0;
		
		if(this.y_pos<0)
		this.y_pos=screenHeight;
		}
		
		void drawParticle(Graphics g,Image img){
			try{
			if(parti==null)
			parti=img;

			g.drawImage(img,this.x_pos,this.y_pos,Graphics.TOP|Graphics.LEFT);
			}catch(Exception e){}
		}


		/*int getX(){
			return this.x_pos;
		}
		int getY(){
			return this.y_pos;
		}*/


		boolean isHit(Image img,int x,int y){
		     if((x<=this.x_pos && x+img.getWidth()>=this.x_pos) || (x>this.x_pos && x<this.x_pos+this.parti.getWidth())){
			if((y<=this.y_pos && y+img.getHeight()>=this.y_pos) || (y>this.y_pos && y<this.y_pos+this.parti.getHeight()))
				return true;
		     }
			return false;
		}
}

⌨️ 快捷键说明

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