class ImageSprite2 extends SuperSprite
{
int vx,vy;
Image SpriteImage;
Applet Game;
Boolean showPig;
public ImageSprite2(Image SpriteImage,Applet Game,int vx)
{
this.SpriteImage = SpriteImage;
this.Game = Game;
this.vx = vx;
showPig = false;
setLocation(0,0);
setVisible(true);
setMove(true);
}
public void updateState()
{
if(active)
{
X += vx;
//Y += vy;
}
//System.out.println(X);
//System.out.println(Y);
//if((X>640 || Y>480) || (X<0 || Y < 0))
if((X>800 || Y>600) || (X<0 || Y < 0))
{
//showPig = false;
showPig = false;
vx=-vx;
//vy=-vy;
}else{
//showPig = true;
showPig = true;
}
}
public void paintSprite(Graphics g)
{
if(visible)
{
g.drawImage(SpriteImage,X,Y,Game);
}
}
public boolean hit(int X,//对方现在X的坐标
int Y,//对方现在Y的坐标
int P_Width,//自己图片的长度
int P_Height,//自己图片的高度
int H_Width,//对方图片的长度
int H_Height//对方图片的高度
)
{
if(
(this.X + P_Width >= X) &&
//(this.X + 40 >= X) &&
(this.Y + P_Height >= Y) &&
//(this.Y + 40 >= Y) &&
(X + H_Width >= this.X) &&
//(X + 40 >= this.X) &&
(Y + H_Height >= this.Y) &&
//(Y + 40 >= this.Y) &&
//showPig
showPig
)
{
//showPig = false;
showPig = false;
//setVisible(false);
//setMove(false);
return true;
}else
return false;
}
public boolean hit2(int DiX,
int DiY,
int Di_Width,
int Di_Height)
{
if(
(this.X + this.width >= DiX) &&
(this.Y + this.height >= DiY) &&
(DiX + Di_Width >= this.X) &&
(DiY + Di_Height >= this.Y) &&
showPig
){
/*System.out.println(DiX);
System.out.println(DiY);
System.out.println(Di_Width);
System.out.println(Di_Height);
System.out.println(showPig);
System.out.println();
System.out.println(this.X);
System.out.println(this.Y);
System.out.println(this.width);
System.out.println(this.height);*/
showPig = false;
return true;
}else
return false;
}
}
class BulletSprite2 extends ImageSprite2
{
int AppletWidth,AppletHeight;
boolean bullet = true;
public BulletSprite2(Image bullet,Applet Game,int AppletWidth,int AppletHeight)
{
super(bullet,Game,0);
this.AppletWidth = AppletWidth;
this.AppletHeight = AppletHeight;
setVisible(false);
setMove(false);
//System.out.println(showPig);
showPig = true;
}
public void updateState()
{
if(active)
{
if(X>AppletWidth)
{
setVisible(false);
setMove(false);
showPig = false;
}else if(bullet == false){
setVisible(false);
setMove(false);
//System.out.println("bullet = "+bullet);
bullet = true;
//System.out.println("bullet = "+bullet);
showPig = false;
}else{
showPig = true;
X = X+10;
}
}
}
public void paintSprite(Graphics g)
{
if(visible)
{
g.drawImage(SpriteImage,X,Y,Game);
}
}
public boolean getBullet()
{
return bullet;
}
public void setBullet(boolean v)
{
this.bullet = v;
}
}