📄 bullet.java
字号:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
public class Bullet {
short mx,my;//map x,y
short x,y; //screen x,y
byte width,height;
short vy,vx;//定义速度
byte maxSpeed,frame,stateSpeed;
byte count;
boolean dir;
boolean dead;
private short[][] shot = new short[][]{
{3,168,35,171,0,0,0,0},
{43,169,75,172,0,0,0,0},
{82,168,113,173,0,0,0,0},
{116,168,149,173,0,0,0,0},
{159,167,190,174,0,0,0,0},
{194,166,226,175,0,0,0,0},
{232,165,263,176,0,0,0,0},
{268,164,299,177,0,0,0,0}
};
public Bullet(boolean d,short mx,short my)
{
maxSpeed = 3;
dir = d;
if(dir)
{
this.mx = (short)(mx+20);
this.my = (short)(my+5);
}
else
{
this.mx = (short)(mx-20);
this.my = (short)(my+5);
}
tickcCoord();
}
private void tickcCoord()//修正坐标
{
x = (short)(mx-CastleCanvas.map.getPosX()+vx);
y = (short)(my-CastleCanvas.map.getPosY()+vy);
}
private void tickSpeed()
{
byte s = 7;
if(dir)
{
vx += s;
count++;
}
else
{
vx -= s;
count++;
}
if(count<5)
vy -= 2;
else if(count>=4 && count<=7)
vy--;
else if(count>10)
vy += 3;
}
public void paint(Graphics g)
{
drawBullet(g);
}
private void drawBullet(Graphics g)
{
tickcCoord();
tickSpeed();
if(dir)
{
tickArgment(shot,g);
}
else
{
tickArgmentMirror(shot,g);
}
}
public boolean isDead()
{
return dead;
}
public void tickArgment(short[][] action,Graphics g) //设置修正的参数
{
short offx = action[frame][0];
short offy = action[frame][1];
short imgW = (short)(action[frame][2]-offx);
short imgH = (short)(action[frame][3]-offy);
byte ox = (byte)(action[frame][4]);
byte oy = (byte)(action[frame][5]);
stateSpeed++;
stateSpeed %= maxSpeed;
if(stateSpeed == 0)
{
frame++;
if(frame == action.length-1)
dead = true;
frame %= action.length;
}
g.setClip(x+ox,y+oy,imgW,imgH);
g.drawImage(Enemy.enemy,x-offx+ox,y-offy+oy,CastleCanvas.imgLT);
}
public void tickArgmentMirror(short[][] action,Graphics g) //设置修正的参数
{
short offx = action[frame][0];
short offy = action[frame][1];
short imgW = (short)(action[frame][2]-offx);
short imgH = (short)(action[frame][3]-offy);
byte mirx = (byte)(action[frame][6]);
byte miry = (byte)(action[frame][7]);
stateSpeed++;
stateSpeed %= maxSpeed;
if(stateSpeed == 0)
{
frame++;
if(frame == action.length-1)
dead = true;
frame %= action.length;
}
g.setClip(x+mirx,y+miry,imgW,imgH);
g.drawRegion(Enemy.enemy,offx,offy,imgW,imgH,Sprite.TRANS_MIRROR,x+mirx,y+miry,CastleCanvas.imgLT);
}
public boolean attEnemy(Enemy e)
{
if(isHit(e,shot))
return true;
return false;
}
public boolean isHit(Enemy e,short[][] pos)
{
short weaWidth = (short)(pos[frame][2]-pos[frame][0]);
short weaHeight = (short)(pos[frame][3]-pos[frame][1]);
if(dir)
{
short weaponX = (short)(x);
short weaponY = (short)(y);
if(e.x+e.ox+e.imgW-10>weaponX && weaponX+weaWidth>e.x+e.ox && e.y+e.oy+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.oy-5 )
{
if(e.brState() && !e.isDead())
{
return true;
}
}
}
else
{
short weaponX = (short)(x);
short weaponY = (short)(y);
if(e.x+e.mirx+e.imgW-10>weaponX && weaponX+weaWidth>e.x+e.mirx+4 && e.y+e.miry+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.miry-5)
{
if(e.brState() && !e.isDead())
{
return true;
}
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -