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

📄 sprite.java

📁 这是j2me里MIDP2.0中game包的源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	int xIncr1, yIncr1;	// .. for image 2	int startY2;	int xIncr2, yIncr2;	int numPixels = height * width;	int[] argbData1 = new int[numPixels];	int[] argbData2 = new int[numPixels];	if (0x0 != (transform1 & INVERTED_AXES)) {	    // inverted axes	    // scanlength = height	    if (0x0 != (transform1 & Y_FLIP)) {		xIncr1 = -(height); // - scanlength		startY1 = numPixels - height; // numPixels - scanlength	    } else {		xIncr1 = height; // + scanlength				startY1 = 0;	    }	    if (0x0 != (transform1 &  X_FLIP)) {		yIncr1 = -1;		startY1 += (height - 1);	    } else {		yIncr1 = +1;	    }	    image1.getRGB(argbData1, 0, height, // scanlength = height			  image1XOffset, image1YOffset, height, width);	} else {	    // scanlength = width	    if (0x0 != (transform1 & Y_FLIP)) {		startY1 = numPixels - width; // numPixels - scanlength		yIncr1  = -(width); // - scanlength	    } else {		startY1 = 0;		yIncr1  = width; // + scanlength	    }	    if (0x0 != (transform1 &  X_FLIP)) {		xIncr1  = -1;		startY1 += (width - 1);	    } else {		xIncr1  = +1;	    }	    image1.getRGB(argbData1, 0, width, // scanlength = width			  image1XOffset, image1YOffset, width, height);	}	if (0x0 != (transform2 & INVERTED_AXES)) {	    // inverted axes	    if (0x0 != (transform2 & Y_FLIP)) {		xIncr2 = -(height);		startY2 = numPixels - height;	    } else {		xIncr2 = height;		startY2 = 0;	    }	    if (0x0 != (transform2 &  X_FLIP)) {		yIncr2 = -1;				startY2 += height - 1;	    } else {		yIncr2 = +1;	    }	    image2.getRGB(argbData2, 0, height,			  image2XOffset, image2YOffset, height, width);	} else {	    if (0x0 != (transform2 & Y_FLIP)) {		startY2 = numPixels - width;		yIncr2  = -(width);	    } else {		startY2 = 0;		yIncr2  = +width;	    }	    if (0x0 != (transform2 &  X_FLIP)) {		xIncr2  = -1;		startY2 += (width - 1);	    } else {		xIncr2  = +1;	    }	    image2.getRGB(argbData2, 0, width,			  image2XOffset, image2YOffset, width, height);	}	int x1, x2;	int xLocalBegin1, xLocalBegin2;	// the loop counters	int numIterRows;	int numIterColumns;	for (numIterRows = 0, xLocalBegin1 = startY1, xLocalBegin2 = startY2;	    numIterRows < height;	    xLocalBegin1 += yIncr1, xLocalBegin2 += yIncr2, numIterRows++) {	    for (numIterColumns = 0, x1 = xLocalBegin1, x2 = xLocalBegin2;		 numIterColumns < width;		 x1 += xIncr1, x2 += xIncr2, numIterColumns++) {		if (((argbData1[x1] & ALPHA_BITMASK) != 0) && 		    ((argbData2[x2] & ALPHA_BITMASK) != 0)) {		    return true;		}			    } // end for x		    	} // end for y		// worst case!  couldn't find a single colliding pixel!	return false;    }    /**     * Given a rectangle that lies within the sprite      * in the painter's coordinates,     * find the X coordinate of the top left corner      * in the source image of the sprite     *     * @param x1 the x coordinate of the top left of the rectangle     * @param y1 the y coordinate of the top left of the rectangle     * @param x2 the x coordinate of the bottom right of the rectangle     * @param y2 the y coordinate of the bottom right of the rectangle     *      * @return the X coordinate in the source image     *      */    private int getImageTopLeftX(int x1, int y1, int x2, int y2) {	int retX = 0;	// left = this.x	// right = this.x + this.width	// top = this.y	// bottom = this.y + this.height	switch (this.t_currentTransformation) {	case TRANS_NONE:	case TRANS_MIRROR_ROT180:	    retX = x1 - this.x;	    break;	case TRANS_MIRROR:	case TRANS_ROT180:	    retX = (this.x + this.width) - x2;	    break;	case TRANS_ROT90:	case TRANS_MIRROR_ROT270:	    retX = y1 - this.y;	    break;	case TRANS_ROT270:	case TRANS_MIRROR_ROT90:	    retX = (this.y + this.height) - y2;	    break;	}	retX += frameCoordsX[frameSequence[sequenceIndex]];	return retX;    }    /**     * Given a rectangle that lies within the sprite      * in the painter's coordinates,     * find the Y coordinate of the top left corner      * in the source image of the sprite     *     * @param x1 the x coordinate of the top left of the rectangle     * @param y1 the y coordinate of the top left of the rectangle     * @param x2 the x coordinate of the bottom right of the rectangle     * @param y2 the y coordinate of the bottom right of the rectangle     *      * @return the Y coordinate in the source image     *      */    private int getImageTopLeftY(int x1, int y1, int x2, int y2) {	int retY = 0;	// left = this.x	// right = this.x + this.width	// top = this.y	// bottom = this.y + this.height	switch (this.t_currentTransformation) {	case TRANS_NONE:	case TRANS_MIRROR:	    retY = y1 - this.y;	    break;	case TRANS_ROT180:	case TRANS_MIRROR_ROT180:	    retY = (this.y + this.height) - y2;	    break;	case TRANS_ROT270:	case TRANS_MIRROR_ROT270:	    retY = x1 - this.x;	    break;	case TRANS_ROT90:	case TRANS_MIRROR_ROT90:	    retY = (this.x + this.width) - x2;	    break;	}	retY += frameCoordsY[frameSequence[sequenceIndex]];	return retY;    }    /**     * Sets the transform for this Sprite     *     * @param transform the desired transform for this Sprite     */    private void setTransformImpl(int transform) {	// ---	// setTransform sets up all transformation related data structures	// except transforming the current frame's bitmap.		// x, y, width, height, dRefX, dRefY, 	// collisionRectX, collisionRectY, collisionRectWidth,	// collisionRectHeight, t_currentTransformation,	// t_bufferImage	// The actual tranformed frame is drawn at paint time.	// ---	// update top-left corner position	this.x = this.x + 	    getTransformedPtX(dRefX, dRefY, this.t_currentTransformation) -	    getTransformedPtX(dRefX, dRefY, transform);	this.y = this.y +	    getTransformedPtY(dRefX, dRefY, this.t_currentTransformation) -	    getTransformedPtY(dRefX, dRefY, transform);	// Calculate transformed sprites collision rectangle	// and transformed width and height	computeTransformedBounds(transform);	// set the current transform to be the one requested	t_currentTransformation = transform;    }    /**     * Calculate transformed sprites collision rectangle     * and transformed width and height     * @param transform the desired transform for this <code>Sprite</code>     */    private void computeTransformedBounds(int transform) {	switch (transform) {	case TRANS_NONE:	    t_collisionRectX = collisionRectX;	    t_collisionRectY = collisionRectY;	    t_collisionRectWidth = collisionRectWidth;	    t_collisionRectHeight = collisionRectHeight;  	    this.width = srcFrameWidth;  	    this.height = srcFrameHeight;	    break;	case TRANS_MIRROR:	    // flip across vertical	    // NOTE: top left x and y coordinate must reflect the transformation	    // performed around the reference point	    // the X-offset of the reference point from the top left corner	    // changes.	    t_collisionRectX = srcFrameWidth - 		               (collisionRectX + collisionRectWidth);	    t_collisionRectY = collisionRectY;	    t_collisionRectWidth = collisionRectWidth;	    t_collisionRectHeight = collisionRectHeight;	    // the Y-offset of the reference point from the top left corner	    // remains the same,	    // top left X-co-ordinate changes  	    this.width = srcFrameWidth;  	    this.height = srcFrameHeight;	    break;	case TRANS_MIRROR_ROT180:	    // flip across horizontal	    // NOTE: top left x and y coordinate must reflect the transformation	    // performed around the reference point	    // the Y-offset of the reference point from the top left corner	    // changes	    t_collisionRectY = srcFrameHeight -                                (collisionRectY + collisionRectHeight);	    t_collisionRectX = collisionRectX;	    t_collisionRectWidth = collisionRectWidth;	    t_collisionRectHeight = collisionRectHeight;	    // width and height are as before  	    this.width = srcFrameWidth;  	    this.height = srcFrameHeight;    	    // the X-offset of the reference point from the top left corner	    // remains the same.	    // top left Y-co-ordinate changes	    	    break;	case TRANS_ROT90:	    // NOTE: top left x and y coordinate must reflect the transformation	    // performed around the reference point	    // the bottom-left corner of the rectangle becomes the 	    // top-left when rotated 90.	    // both X- and Y-offset to the top left corner may change	    // update the position information for the collision rectangle	    t_collisionRectX = srcFrameHeight -                                (collisionRectHeight + collisionRectY);	    t_collisionRectY = collisionRectX;	    t_collisionRectHeight = collisionRectWidth;	    t_collisionRectWidth 

⌨️ 快捷键说明

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