📄 paddle.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
import java.lang.System;
public class Paddle extends MoveObject
{
private boolean left;
private boolean right;
public float restLimit = 0.1f;
public float stickykey = 1.0f;
public float attenuation = -0.7f;
public float resistance = 0.03f;
public float acceleration = 0.05f, antiAcceleration = 0.03f;
public Paddle(String path, int x, int y, float vx, float vy, int type)
{
super(path, x, y, vx, vy, type);
}
public Paddle(String path, int width, int height, int x, int y, float vx, float vy, int type)
{
super(path, width, height, x, y, vx, vy, type);
}
public void enlarge(String path, int width, int height)
{
try
{
moveObject = scale(Image.createImage(path), width, height);
}
catch (Exception e)
{
}
this.cx = moveObject.getWidth();
this.cy = moveObject.getHeight();
}
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(boolean left, boolean right)
{
this.left = left;
this.right = right;
}
public void generateMove()
{
if ((vx - (int)vx) > 0.5f)
x += ((int)vx + 1);
else
x += (int)vx;
}
public void getV()
{
if (left)
{
if (vx < restLimit && vx > -restLimit)
{
vx = -1.0f;
}
else if (vx < 0.0f)
{
vx -= antiAcceleration;
}
else if (vx > 0.0f)
{
vx -= acceleration;
}
}
if (right)
{
if (vx < restLimit && vx > -restLimit)
{
vx = 1.0f;
}
else if (vx > 0.0f)
{
vx += antiAcceleration;
}
else if (vx < 0.0f)
{
vx += acceleration;
}
}
if (!left && !right)
{
if ((vx < stickykey && vx > 0.0f) || (vx > -stickykey && vx < 0.0f))
vx = 0.0f;
else if (vx > 0.0f)
{
vx -= resistance;
}
else if (vx < 0.0f)
{
vx += resistance;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -