MySprite 2.0

xiaoxiao2021-03-05  23

/ **

Upgrade version of the Sprite class written for MIDP1.0 *

Title: Elf class * *

description: * *

Copyright: CopyRight (C) 2004 * *

Company: * * @author not attributable * @version 1.0 * / import javax.microedition.lcdui *; public class MySprite {final public static int ByCollideXY = 0; final public static int ByCollideArea =. 1; final public static int ByCollideRadius = 2; public Image image; public int positionX; public int positionY; public int numFrames; public int currentFrame; public int [] [] framesInfo; // size of each frame of the present version of it to an array of memory In, not like 1.0 medium public boolean visible = true; public int dx; public int Dy; public int colLiDex = 0; // When two role cross lateral distances exceed Collidex, it is considered to collide with public int collidey = 0; / / When two roles cross longitudinal distances exceeding Collidey, it is considered that it has collided into public int collidearea = 0; // While two roles are more than CollideArea, they think that they have collisted (Note: Invasion area here! = Cross-area) Public int collideradius = 0; // Collision radius public int stat;

public MySprite (Image image, int numFrames) throws Exception {this.image = image; this.numFrames = numFrames; // set frameInfo framesInfo = new int [numFrames] [4]; for (int i = 0; i this.positionX this.framesinfo [currentframe] [2] - Sprite.positionX? this.positionX this.framesinfo [currentframe] [2] -sprite.positionX: sprite.positionX sprite.framesinfo [sprite.currentframe] [2] -this.positionX; int iny = sprite.positiony

Sprite.currentframe] [3] -tis.positiony> this.positiony this.framesinfo [currentframe] [3] -sprite.positiony? this.positiony this.framesinfo [currentframe] [3] -sprite. Positiony: sprite.positiony sprite.currentframe] [3] -this.positiony; if (Inx> 0 && iny> 0 && Inx * iny> this.collidearea sprite.collidearea) {Return True;} else {return false;}} else if (CheckType == ByCollideXY) {if (sprite.positionX sprite.framesInfo [sprite.currentFrame] [2] -sprite.collideX> this.positionX this.collideX && this.positionX this .framesInfo [currentFrame] [2] -this.collideX> sprite.positionX sprite.collideX && sprite.positionY sprite.framesInfo [sprite.currentFrame] [3] -sprite.collideY> this.positionY this.collideY && this .positiony this.framesinfo [currentframe] [3] -this.collide> sprite.positiony sprite.collidey) {Return True;} else { Return false;}}} else // if (checktype == bycollideradius) {int inx = math.abs (this.positionX this.framesinfo [currentframe] [2] /2-sprite.positionX- (sprite.framesinfo [sprite.) CurrentFrame] [2] 1) / 2); int iny = math.abs (this.positiony this.framesinfo [currentframe] [3] / 2-sprite.positiony- (sprite.framesinfo [sprite.currentframe] [3 ] 1) / 2); IF (Inx * Inx Iny * iny <(CollideRadius Sprite.collideRadius) * (Sprite.CollideRadius Sprite.collideRadius)) {Return True;} else {return false;

}}} Public boolean collidesWith (Image image, int x, int y) {return this.collidesWith (image, x, y, ByCollideArea);} public boolean collidesWith (Image image, int x, int y, int CheckType) {if (! Visible) {Return False;}

转载请注明原文地址:https://www.9cbs.com/read-38266.html

New Post(0)