package com.zte; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import javax.swing.ImageIcon; public class Bullet { public int x;// 横坐标 public int y;// 纵坐标 static int xxx = 0; static int yyy = 0; Point p; public ImageIcon img;// 子弹代表的图片 public double roate;// 子弹移动的角度 public FishPanel panel; boolean isLive = true; public Bullet(FishPanel panel) { this.panel = panel; } public void move() throws InterruptedException { y -= 20; // 转换x和y坐标 int yy = Math.round((float) Math.cos(roate) * (p.y - 17 - y)); yyy = p.y - 17 - Math.abs(yy); System.out.println(yyy); int xx = Math.round((float) Math.sin(roate) * (p.y - 17 - y)); xxx = p.x - 10 + xx; System.out.println(xxx); if (yyy<=-10 || xxx <= -10) { isLive = false; panel.bullets.remove(this); } hint(); panel.repaint(); } // 处理击中某条鱼 撒网 public void hint() throws InterruptedException{ for(int i=0;i<panel.fishs.size();i++){ Fish f = panel.fishs.get(i); if(xxx>f.x-img.getIconWidth() && xxx<f.x +f.imgs[f.imgNum].getIconWidth() && y<f.y +f.imgs[f.imgNum].getIconHeight()){ FishNet net = new FishNet(xxx-30, yyy-50, new ImageIcon("images/web.png"),panel); panel.bullets.remove(this);//子弹消失 panel.nets.add(net);//子弹消失后撒网 isLive = false; net.caFish(); /*******************/ Thread.sleep(500);//等2秒之后让网消失 panel.nets.remove(net); } } } public void drawBullet(Graphics g) { Graphics2D gp = (Graphics2D) g.create(); gp.rotate(roate, p.x, p.y); gp.drawImage(this.img.getImage(), x, y, panel); } }
最近下载更多
你说捕鱼王子请上车 LV1
2023年11月17日
lyws1986 LV17
2023年11月14日
wangjialiang1 LV17
2023年8月24日
yerwiu LV10
2023年8月13日
周华贵 LV3
2023年8月2日
yaojingjedaren LV1
2023年4月18日
最代码-宋家辉 LV61
2023年2月28日
hkxyyz LV6
2023年2月28日
hrbylw LV8
2022年9月16日
微信网友_5852742079762432 LV6
2022年4月11日