📄 moveobject.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
public class MoveObject extends NormalObject
{
public Image moveObject;
public int type;
public MoveObject(String path, int x, int y, float vx, float vy, int type)
{
super();
try
{
moveObject = Image.createImage(path);
this.x = x;
this.y = y;
this.cx = moveObject.getWidth();
this.cy = moveObject.getHeight();
this.vx = vx;
this.vy = vy;
this.type = type;
}
catch (Exception e)
{
}
}
public MoveObject(String path, int width,int height,int x, int y, float vx, float vy, int type)
{
super();
try
{
moveObject = scale(Image.createImage(path), width, height);
this.x = x;
this.y = y;
this.cx = moveObject.getWidth();
this.cy = moveObject.getHeight();
this.vx = vx;
this.vy = vy;
this.type = type;
}
catch (Exception e)
{
}
}
public static Image scale(Image src, int width, int height)
{
long start = System.currentTimeMillis();
int scanline = src.getWidth();
int srcw = src.getWidth();
int srch = src.getHeight();
int buf[] = new int[srcw*srch];
src.getRGB(buf, 0, scanline, 0, 0, srcw, srch);
int buf2[] = new int[width*height];
for (int y = 0; y < height; y++)
{
int c1 = y * width;
int c2 = (y * srch / height) * scanline;
for (int x = 0; x < width; x++)
{
buf2[c1 + x] = buf[c2 + x * srcw / width];
}
}
Image img = Image.createRGBImage(buf2, width, height, true);
long end = System.currentTimeMillis();
return img;
}
public void move()
{
}
public void setPos(int x, int y)
{
this.x = x;
this.y = y;
}
public void paint(Graphics graphics)
{
graphics.drawImage(moveObject, x, y, Graphics.TOP | Graphics.LEFT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -