bullet.java~10~
来自「这个是最早期的一个飞行射击游戏 简单实现了地图滚动 子弹碰撞 与 UI等」· JAVA~10~ 代码 · 共 98 行
JAVA~10~
98 行
package newgame;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class Bullet extends Base {
int speedx, speedy; //速度
Image img;
Image shadow;
int frameWidth, frameHeight;
Tools tool;
boolean visble; //可见不可见
int x, y; //坐标
int type; //类型
Canvas1 mc;
final int hero = 1;
final int enemy = 2;
final int boss = 3;
/**
switch (type) {
case hero:
break;
case enemy:
break;
case boss:
break;
}*/
public Bullet(Canvas1 mc, int type) {
tool = new Tools(this.mc);
this.mc = mc;
this.type = type;
switch (type) {
case hero:
img = tool.getImage("/ammo.png");
break;
case enemy:
break;
case boss:
break;
}
}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
switch (type) {
case hero:
speedy = -7;
break;
case enemy:
break;
case boss:
break;
}
this.setVisble(true);
}
public void move() {
switch (type) {
case hero:
this.x += speedx;
this.y += speedy;
break;
case enemy:
break;
case boss:
break;
}
}
public void paint(Graphics g) {
if (this.isVisble()) {
g.drawImage(img, x, y, g.LEFT | g.TOP);
}
}
public void setVisble(boolean flag) {
this.visble = flag;
}
public boolean isVisble() {
return this.visble;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?