Java实战之---旅行钓鱼游戏( 二 )

<= 0 && speed < 0){x = 0;}//判断钩子是否超出范围if(hookY > 500 ){speedY = -speedY;}if(hookY < 120){speedY = 0;isHitHook = false;}//相撞就把钩子设为反方向让它返回if(isHitHook){speedY = -10;}x += speed;//判断图片和画布的相对位置当放到最后一张图片的时候再返回来if(armX == -1080){armX = 0;}//钩子在动的时候,鱼线就动if(speedY != 0){armX-= 180;}}//钩子位置的方法public void hookPos(Graphics g){BufferedImage hookbuf = new BufferedImage(30,50,BufferedImage.TYPE_INT_ARGB);ImageIcon hook = new ImageIcon("boat/hook.png");hookbuf.getGraphics().drawImage(hook.getImage(), 0, 0, null);g.drawImage(hookbuf, x+160, hookY, null);//System.out.println(x+160+"佛山热"+ hookY);g.setColor(Color.black);g.drawLine(x+178, 120, x+178, hookY+10);//System.out.println(x+160+""+ hookY);g.setColor(Color.black);//if(isHit(null)){//speedY = -speedY;//}elsehookY += speedY;}//是否碰到鱼public void isHit(Fish fish){int[] fx = fish.getChangeXLocation(),fy = fish.getChangeYLocation();for(int i = 0;i < 10;++i){if((fx[i] >= x+178 && fx[i] <= x+238 && fy[i] >= hookY + 4 && fy[i] <= hookY +50)){isHitHook = true;//System.out.println("isHitHook");}}}
剩下的就是在主frame类里面启动线程和添加键盘监听器了,那些代码我就不拿出来了,键盘监听器类可以继承类就好
素材 以及原版游戏 百度网盘地址: