📄 bullet.java
字号:
import javax.microedition.lcdui.*;
public class Bullet
{
Image[] imageFrames;
Image image;
int imageWidth;
int imageHeight;
int canvasWidth;
int canvasHeight;
protected static final String IMAGE_NAME="bullet";
protected static final int RAW_FRAMES=1;
protected int xPos;
protected int yPos;
private static VaderManager layerManager;
private static VaderCanvas gameCanvas;
public Bullet(Player player)
{
imageFrames=VaderManager.getFrames(IMAGE_NAME, RAW_FRAMES);
imageWidth=imageFrames[0].getWidth();
imageHeight=imageFrames[0].getHeight();
xPos=player.getX()+(int)player.getWidth()/2;
yPos=player.getY()-getHeight();
setPosition(xPos, yPos);
//gameCanvas=layerManager.getGameCanvas();
createImage();
setSpriteImage();
}
public int getHeight() {return imageHeight;}
public int getWidth() {return imageWidth;}
public int getCanvasHeight() {return canvasHeight;}
public int getCanvasWidth() {return canvasWidth;}
public Image getImage() {return image;}
private void setX(int x) {xPos=x;}
private void setY(int y) {yPos=y;}
public int getX() {return xPos;}
public int getY() {return yPos;}
public static void setLayerManager(VaderManager manager) {layerManager=manager;}
//public void setY(int y) {this.setPosition(this.getX(), this.getY()+y);}
private void setPosition(int x, int y)
{
setX(x);
setY(y);
}
private void move(int x, int y)
{
setX(getX()+x);
setY(getY()+y);
}
private void up()
{
move(0,-5);
if(this.getY()<0)
{
layerManager.removeLayer(this);
}
}
public void tick()
{
up();
}
private void createImage()
{
// allocate memory to store the onscreen background image.
// assuming all tiles are the same size, make the buffer
// the screen size plus one row and column.
image=Image.createImage(getWidth(), getHeight());
}
private void setSpriteImage()
{
Graphics g = image.getGraphics();
g.drawImage(imageFrames[0],0,0,g.LEFT | g.TOP);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -