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

📄 cutoffcanvas.java

📁 Source code for j2me game Capture
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		if (p!=n) if (polyBX[p]==lineX1-1) none=true;		}		x=lineX1+1;		y=lineY1+((lineY2-lineY1)/2);	if (contains(x,y,polyBX,polyBY,numPolyBPoints)!='i')	 x=lineX1-1;	if (x>lineX1) right=true;	if (x<lineX1) left=true;	}	else	{		if (lineX2-lineX1<=1) none=true;		for (p=0;p<numPolyBPoints;p++) {				if (p!=n) if (polyBY[p]==lineY1+1) none=true;				if (p!=n) if (polyBY[p]==lineY1-1) none=true;				}		y=lineY1+1;			x=lineX1+((lineX2-lineX1)/2);		if (contains(x,y,polyBX,polyBY,numPolyBPoints)!='i')		 y=lineY1-1;		 if (y>lineY1) down=true;		 if (y<lineY1) up=true;	}	if (up==true || down==true) {	x1=x1+1;	x2=x2-1;	}	if (right==true || left==true) {	y1=y1+1;	y2=y2-1;	}	while (found==false && none==false) {	for (p=0;p<numPolyBPoints;p++) {		i=p+1;		if (i>=numPolyBPoints) i=0;	if (polyBX[p]<=polyBX[i]) {			xx1=polyBX[p];			xx2=polyBX[i];		} else {		xx1=polyBX[i];		xx2=polyBX[p];		}		if (polyBY[p]<=polyBY[i]) {			yy1=polyBY[p];			yy2=polyBY[i];		} else {		yy1=polyBY[i];		yy2=polyBY[p];		}	if (p!=n) if (((xx1>=x1 && xx1<=x2) || (xx2>=x1 && xx2<=x2)) && ((yy1>=y1 && yy1<=y2) || (yy2>=y1 && yy2<=y2)) ) found=true;	if (p!=n) if (((x1>=xx1 && x1<=xx2) || (x2>=xx1 && x2<=xx2)) && ((y1>=yy1 && y1<=yy2) || (y2>=yy1 && y2<=yy2)) ) found=true;	}//p	if (found==false) {	if (up==true) {			y1--;			y2--;		}		if (down==true) {				y1++;				y2++;			}		if (right==true) {				x1++;				x2++;			}		if (left==true) {				x1--;				x2--;			}	}	}//while	/*	if (up==true || down==true) {		x1=x1-1;		x2=x2+1;		}		if (right==true || left==true) {		y1=y1-1;		y2=y2+1;		}		*/		if (none==false) {	if (right==true || down==true) {	fillerRectX[numFillerRects]=saveX;	fillerRectY[numFillerRects]=saveY;	fillerRectWidth[numFillerRects]=x2-saveX;	fillerRectHeight[numFillerRects]=y2-saveY+1;	}	if (left==true) {	fillerRectX[numFillerRects]=x2;	fillerRectY[numFillerRects]=saveY;	fillerRectWidth[numFillerRects]=saveX-x2;	fillerRectHeight[numFillerRects]=y2-saveY+1;	}	if (up==true) {		fillerRectX[numFillerRects]=saveX;		fillerRectY[numFillerRects]=y2;		fillerRectWidth[numFillerRects]=x2-saveX+1;		fillerRectHeight[numFillerRects]=saveY-y2;	}	if (down==true) {			fillerRectX[numFillerRects]=saveX;			fillerRectY[numFillerRects]=saveY;			fillerRectWidth[numFillerRects]=x2-saveX+1;			fillerRectHeight[numFillerRects]=y2-saveY;		}	for (p=0;p<numFillerRects;p++) {	if (fillerRectX[p]==fillerRectX[numFillerRects] && fillerRectY[p]==fillerRectY[numFillerRects] &&	    fillerRectWidth[p]==fillerRectWidth[numFillerRects] && fillerRectHeight[p]==fillerRectHeight[numFillerRects]) {			none=true;		//			System.out.println ("Take X "+fillerRectX[numFillerRects]+"   Y"+fillerRectY[numFillerRects]+"   width"+fillerRectWidth[numFillerRects]+"  height "+fillerRectHeight[numFillerRects]);		}	}	if (none==false) {		numFillerRects++;	//	System.out.println ("Give X "+fillerRectX[numFillerRects-1]+"   Y"+fillerRectY[numFillerRects-1]+"   width"+fillerRectWidth[numFillerRects-1]+"  height "+fillerRectHeight[numFillerRects-1]);	}	}   }//addREct   private final boolean lineTouches (int cutPointX,int cutPointY,int line1X1,int line1Y1,int line1X2,int line1Y2,int line2X1,int line2Y1,int line2X2,int line2Y2) {   boolean touches=false;   boolean line1X1T=false;   boolean line1X2T=false;   if (line1X1==line2X1 && line1Y1==line2Y1) {	   touches=true;	   line1X1T=true;   }   if (line1X1==line2X2 && line1Y1==line2Y2) {	   touches=true;	   line1X1T=true;   }   if (line1X2==line2X1 && line1Y2==line2Y1) {	   touches=true;	   line1X2T=true;   }   if (line1X2==line2X2 && line1Y2==line2Y2) {	   touches=true;	   line1X2T=true;   }   if (touches==true) {   touches=false;   if (line1X1T==true)   if (cutPointX==line1X1 && cutPointY==line1Y1) touches=true;   if (line1X2T==true)   if (cutPointX==line2X1 && cutPointY==line2Y1) touches=true;   }   return (touches);   }   private final void resetLine () {   int p=0;   arrowX=startCutPointX;   arrowY=startCutPointY;   for (p=0;p<=numCutPoints;p++) {	   cutPointsX[p]=0;	   cutPointsY[p]=0;   }   numCutPoints=0;   arrowMoveRight=false;arrowMoveLeft=false;arrowMoveUp=false;arrowMoveDown=false;   resting=true;	lives=lives-1;	if (lives<1) {		gameOver=true;		myMiniGames.setMyNewGameCommand();	}   }  public void keyReleased (int keyCode) {    	if (keyCode ==-4 || keyCode==RIGHT  || keyCode==KEY_NUM6) {			arrowMoveRight=false;  			//wasArrowRight=true;  	}    	if (keyCode==-3 || keyCode==LEFT || keyCode==KEY_NUM4)   {			arrowMoveLeft=false;			//wasArrowLeft=true;  	}        if(keyCode==-1 || keyCode==KEY_NUM2 || keyCode==UP) {			arrowMoveUp=false;			//wasArrowUp=true;  	 }  	   if(keyCode==-2 || keyCode==KEY_NUM8 || keyCode==DOWN) {		   arrowMoveDown=false;		   //wasArrowDown=true;  	 }  	 if(keyCode==-5 || keyCode==FIRE || keyCode==KEY_NUM5) {	 }// keycode5}//keyReleased  public void keyPressed (int keyCode) {	  int i,j;	  i=0;j=0;	  int p=0;	  if (gameOver==false && paused==false) {	if (keyCode ==-4 || keyCode==RIGHT  || keyCode==KEY_NUM6) {	if (arrowD!=2 || resting==true) {	arrowMoveRight=false;arrowMoveLeft=false;arrowMoveUp=false;arrowMoveDown=false;	if (arrowD==3) wasArrowRight=true;	arrowD=3;	arrowMoveRight=true;	if (resting==true) {	resting=false;	for (p=0;p<numBounderPoints;p++)	{	i=p;	j=i+1;	if (j>=numBounderPoints) j=0;	if (onLine (arrowX,arrowY,bounderPointsX[i],bounderPointsY[i],bounderPointsX[j],bounderPointsY[j])==true) resting=true;	}	/*if (resting==false) {		cutPointsX[numCutPoints]=startCutPointX;		cutPointsY[numCutPoints++]=startCutPointY;		//found=true;		}*/	}	if (resting==false && wasArrowRight==false) {	cutPointsX[numCutPoints]=arrowX;	cutPointsY[numCutPoints]=arrowY;	numCutPoints++;	}	}	}//keycode right	if (keyCode==-3 || keyCode==LEFT || keyCode==KEY_NUM4)   {	if (arrowD!=3 || resting==true) {	arrowMoveRight=false;arrowMoveLeft=false;arrowMoveUp=false;arrowMoveDown=false;	if (arrowD==2) wasArrowLeft=true;	arrowD=2;	arrowMoveLeft=true;if (resting==true) {	resting=false;	for (p=0;p<numBounderPoints;p++)	{	i=p;	j=i+1;	if (j>=numBounderPoints) j=0;	if (onLine (arrowX,arrowY,bounderPointsX[i],bounderPointsY[i],bounderPointsX[j],bounderPointsY[j])==true) resting=true;	}/*if (resting==false) {		cutPointsX[numCutPoints]=startCutPointX;		cutPointsY[numCutPoints++]=startCutPointY;		//found=true;		}*/	}	if (resting==false && wasArrowLeft==false) {	cutPointsX[numCutPoints]=arrowX;		cutPointsY[numCutPoints]=arrowY;		numCutPoints++;	}	}	}//keycode left	if(keyCode==-1 || keyCode==KEY_NUM2 || keyCode==UP) {	if (arrowD!=1 || resting==true) {	arrowMoveRight=false;arrowMoveLeft=false;arrowMoveUp=false;arrowMoveDown=false;		if (arrowD==0) wasArrowUp=true;		arrowD=0;		arrowMoveUp=true;if (resting==true) {	resting=false;	for (p=0;p<numBounderPoints;p++)	{	i=p;	j=i+1;	if (j>=numBounderPoints) j=0;	if (onLine (arrowX,arrowY,bounderPointsX[i],bounderPointsY[i],bounderPointsX[j],bounderPointsY[j])==true) resting=true;	}/*if (resting==false) {		cutPointsX[numCutPoints]=startCutPointX;		cutPointsY[numCutPoints++]=startCutPointY;		//found=true;		}*/	}	if (resting==false && wasArrowUp==false) {		cutPointsX[numCutPoints]=arrowX;		cutPointsY[numCutPoints]=arrowY;			numCutPoints++;	}	}	}//key code up	if(keyCode==-2 || keyCode==KEY_NUM8 || keyCode==DOWN) {	if (arrowD!=0 || resting==true) {	arrowMoveRight=false;arrowMoveLeft=false;arrowMoveUp=false;arrowMoveDown=false;		if (arrowD==1) wasArrowDown=true;		arrowD=1;		arrowMoveDown=true;if (resting==true) {	resting=false;	for (p=0;p<numBounderPoints;p++)	{	i=p;	j=i+1;	if (j>=numBounderPoints) j=0;	if (onLine (arrowX,arrowY,bounderPointsX[i],bounderPointsY[i],bounderPointsX[j],bounderPointsY[j])==true) resting=true;	}/*if (resting==false) {		cutPointsX[numCutPoints]=startCutPointX;		cutPointsY[numCutPoints++]=startCutPointY;		//found=true;		}*/	}	if (resting==false && wasArrowDown==false) {		cutPointsX[numCutPoints]=arrowX;			cutPointsY[numCutPoints]=arrowY;			numCutPoints++;	}	}	}//keycode down	wasArrowUp=false;	wasArrowDown=false;	wasArrowRight=false;	wasArrowLeft=false;}}private final boolean onLine (int x,int y,int lineX1,int lineY1,int lineX2,int lineY2) {boolean onLine=false;if (lineX1<=lineX2 && lineY1<=lineY2) if (x>=lineX1 && x<=lineX2 && y>=lineY1 && y<=lineY2) onLine=true;if (lineX1<=lineX2 && lineY1>lineY2) if (x>=lineX1 && x<=lineX2 && y>=lineY2 && y<=lineY1) onLine=true;if (lineX1>lineX2 && lineY1<=lineY2) if (x>=lineX2 && x<=lineX1 && y>=lineY1 && y<=lineY2) onLine=true;if (lineX1>lineX2 && lineY1>lineY2) if (x>=lineX2 && x<=lineX1 && y>=lineY2 && y<=lineY1) onLine=true;return (onLine);}  public final void newGame () {	int p;	ker=0;	  go=true;	  gameOver=false;	  paused=false;	  myMiniGames.setMyPauseCommand();	  arrowD=0;	  arrowX=width/2;	  arrowY=bottom;	  startCutPointX=arrowX;	  startCutPointY=arrowY;	  numBounderPoints=4;	  bounderPointsX[0]=0;	  bounderPointsY[0]=0;	  bounderPointsX[1]=width-1;	  bounderPointsY[1]=0;	  bounderPointsX[2]=width-1;	  bounderPointsY[2]=bottom;	  bounderPointsX[3]=0;	  bounderPointsY[3]=bottom;	  time1=System.currentTimeMillis();	  arrowMoveUp=false;	  arrowMoveDown=false;	  arrowMoveLeft=false;	  arrowMoveRight=false;	  numCutPoints=0;		numFillerRects=0;	for (p=0;p<150;p++) {	  cutPointsX[p]=0;	  cutPointsY[p]=0;	  }	lives=5;	score=0;	resting=true;	  level=1;	  startLevel ();  }  private final void startLevel () {  int p=0;  int i=0,j=0,k=0;  ker=0;  if (level>1) score=score+100;  arrowD=0;  	  arrowX=width/2;  	  arrowY=bottom;  	  startCutPointX=arrowX;  	  startCutPointY=arrowY;  	  numBounderPoints=4;  	  bounderPointsX[0]=0;  	  bounderPointsY[0]=0;  	  bounderPointsX[1]=width-1;  	  bounderPointsY[1]=0;  	  bounderPointsX[2]=width-1;  	  bounderPointsY[2]=bottom;  	  bounderPointsX[3]=0;  	  bounderPointsY[3]=bottom;	totalArea=0;	for (i=0;i<numBounderPoints;i++) {	  		j=i+1;	  		if (j>=numBounderPoints) j=0;	  		k=i-1;	  		if (k<0) k=numBounderPoints-1;	  		totalArea+=bounderPointsX[i]*(bounderPointsY[j]-bounderPointsY[k]);	  		}	  		totalArea=totalArea/2;	  		if (totalArea<0) totalArea=totalArea*-1;	  arrowMoveUp=false;		  arrowMoveDown=false;		  arrowMoveLeft=false;		  arrowMoveRight=false;		  numCutPoints=0;			numFillerRects=0;		for (p=0;p<150;p++) {		  cutPointsX[p]=0;		  cutPointsY[p]=0;		  }		  resting=true;		  numPolyAPoints=0;		  numPolyBPoints=0;  numBalls=level+1;  for (p=0;p<numBalls;p++) {  ballX[p]=getRandomInt (width-(ballWidth*2)-10)+ballWidth+5;  ballY[p]=getRandomInt (bottom-(ballHeight*2)-10)+ballHeight+5;  ballDX[p]=getRandomInt (2);  ballDY[p]=getRandomInt (2);  ballMX[p]=getRandomInt (5)+1;  ballMY[p]=getRandomInt (5)+1;  ballDM[p]=getRandomInt (2);  ballMA[p]=0;  dontRandom[p]=8;  ballRandom[p]=getRandomInt (12);  }  }//startlevel  private final int floatReg (int org, int div, int mul) {      int x=0;int oldX=0;      org=org<<8;      x=org/div;      x=x*mul;       x=x>>8;      return (x);      }private final char contains(int x,int y,int pointsX[],int pointsY[],int num_points)    {	int i=0, j=0;	int rcross = 0;	int lcross = 0;	boolean rstrad, lstrad;	int on= 0;	for(i = 0; i < num_points; i++)	{	    j++;	    if( j == num_points) j = 0;	    if (pointsX[i] == x && pointsY[i] == y)	    {		return 'v';	    }	    rstrad = ( pointsY[i] > y ) !=		( pointsY[j] > y );	    lstrad = ( pointsY[i] < y ) !=		( pointsY[j] < y );	    if ( rstrad || lstrad )	    {		on = y*(((pointsX[i] - pointsX[j])<<8)/(pointsY[i] - pointsY[j]))		- pointsY[i] *		(((pointsX[i] - pointsX[j])<<8)/(pointsY[i] - pointsY[j]))		+ (pointsX[i]<<8) ;		if (rstrad && (on > x<<8))		{		    rcross++;		}		if (lstrad && (on < x<<8))		{		    lcross++;		}	    }	}	if((rcross-((rcross / 2)*2)) != (lcross-((lcross / 2)*2)))	{	 return 'e';	}	if ((rcross-((rcross/2)*2)) == 1)	{	    return 'i';	}	else	{	    return 'o';	}    }private final int getRandomInt(int upper) {    int retVal = myRandom.nextInt() % upper;    if(retVal < 0) retVal += upper;    return(retVal);  }private void loadImages () { try {    ballImg1=Image.createImage ("/images/ball0.png"); 	ballImg1=resize2 (ballImg1,ballWidth,ballHeight);    ballImg2=Image.createImage ("/images/ball1.png"); 	ballImg2=resize2 (ballImg2,ballWidth,ballHeight);	} catch (Exception e) {System.out.println ("Error loading images: "+e);} } public static Image resize2(Image originalImage, int width, int height) {		              //if (height <= 0 || width <= 0)		              //throw new Exception("ERROR_INVALID_ARGUMENT");		              if (originalImage == null)		                    return Image.createImage(height, width);		              int orig_h = originalImage.getHeight();		              int orig_w = originalImage.getWidth();		              if (orig_w == width && orig_h == height)		                    return originalImage;		              //int index;		              //int loc, oldloc = 0;		              Image newImage = Image.createImage (width,height);		              Graphics newImageG=newImage.getGraphics();		              //long before = System.currentTimeMillis();		              for (int i = 0; i < height; i++) {		                    for (int j = 0; j < width; j++) {		                          //System.arraycopy(orig,index,newbuffer,loc,1);		                        //  newbuffer[loc] = orig[index];		                          newImageG.setClip (j,i,1,1);		                        // newImageG.drawRegion (originalImage,(int) (j*orig_w/width),(int) (i*orig_h/height),1,1,Sprite.TRANS_NONE,j,i,0);		                       newImageG.drawImage (originalImage,j-(int) (j*orig_w/width),i-(int) (i*orig_h/height),0);		                    }		              }		              //System.out.println("time:"+(System.currentTimeMillis()-before));		             //Image newImage = Image.createRGBImage(newbuffer, width, height, false);		             // orig = null;		             // newbuffer = null;		             originalImage=null;		             System.gc(); //		              return newImage;		        }}//class canvas

⌨️ 快捷键说明

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