offScreen.drawImage(image1f,fishpos[0][0],fishpos[0][1],this);
//省略其他小鱼显示代码
…
//吃到小鱼1,计算得分及生命值
if(showfish1==1)
if(mousex+70>=fishpos[0][0]&&mousex+70<=fishpos[0][0]+104&&
mousey+32>=fishpos[0][1]&&mousey+32<=fishpos[0][1]+57)
{
life=life+6;
if(life>100)
life=100;
score=score+6;
fishpos[0][0]=0;
fishpos[0][1]=40;
showfish1=0;
}
//省略吃其他小鱼代码
…
/*根据大鲨鱼的坐标,决定是否显示小鱼*/
if(mousey>300)
showfish1=1;
//省略其他小鱼是否显示代码
…
//显示得分及时间
offScreen.setFont(new Font("Dialog",Font.PLAIN,28));
offScreen.setColor(Color.yellow);
offScreen.drawString("得分:"+score,20,20);
offScreen.drawString(
"时间:"+(System.currentTimeMillis()-starttime)/1000,250,20);
//显示气泡
offScreen.setColor(Color.white);
offScreen.fillOval(bubblepos[0][0],bubblepos[0][1],30,30);
offScreen.fillOval(bubblepos[1][0],bubblepos[1][1],30,30);
offScreen.fillOval(bubblepos[2][0],bubblepos[2][1],30,30);
/*吃到气泡,减少生命值,并重新计算气泡位置*/ if(bubblepos[0][0]+15>=mousex&&bubblepos[0][0]+15<=mousex+139&&
bubblepos[0][1]+15>=mousey&&bubblepos[0][1]+15<=mousey+64)
{
life=life-30;
bubblepos[0][0]=100;
bubblepos[0][1]=450;
} if(bubblepos[1][0]+15>=mousex&&bubblepos[1][0]+15<=mousex+139&&
bubblepos[1][1]+15>=mousey&&bubblepos[1][1]+15<=mousey+64)
{
|