📄 myship.java
字号:
/*
* MyShip.java
*
* Copyright 2001 SkyArts. All Rights Reserved.
*/
import javax.microedition.lcdui.*;
/**
* Myship类
*
* @author Hideki Yonekawa
* @version 1.0
*/
class MyShip extends Sprite {
/** 储存自机图像的变量*/
private Image shipImg;
/** 储存自机爆炸图像的变量 */
private Image burstImg;
/** 构造函数 */
MyShip() {
// 取得图像
try {
shipImg = Image.createImage("/myship.png");
burstImg = Image.createImage("/burst.png");
}catch(Exception e) {}
//设定宽度与高度
width = shipImg.getWidth();
height = shipImg.getHeight();
}
/** 要移动Sprite时所调用的方法 */
void doMove() {
tickCount++;
if(isHit()) {
if(tickCount > 4) {
setHit(false);
}
}else {
if(tickCount > 4) {
tickCount = 0;
}
}
}
/** 要描绘Sprite时所调用的方法 */
void doDraw(Graphics g) {
if(isHit()) {
//Hit时描绘爆炸图像
g.drawImage(burstImg, x, y, Graphics.TOP|Graphics.LEFT);
}else {
g.drawImage(shipImg, x, y, Graphics.TOP|Graphics.LEFT);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -