public class ReShoot implements ActionListener { public void actionPerformed(ActionEvent e){ ArrowShoot shoot = new ArrowShoot(); shoot.ReShoot(); } } public class ArrowShoot implements ActionListener { public Timer T = new Timer(5, this); Arrow A = new Arrow(); public void ReShoot(){ T.start(); arrow_x=0; arrow_y=200; A.setBounds(0,200,10,10); } // MAIN: y=-16t^2 + Vy * t + h //Vy = v * sin(a) //Vx = v * cos(a) //a = arctan( (200-mouse_y)/v //v = Mouse_x - Arrow_x //t = x / Vx public void actionPerformed(ActionEvent e) {//arrow_y = 0.0025 * Math.pow((mouse_x-arrow_x), 2)+ mouse_y; Container container_arrow = getContentPane(); container_arrow.setLayout(null); container_arrow.add(A); A.setBounds(0,200,10,10); arrow_x++; double v = mouse_x/2; //height change double a = 50* Math.atan((200-mouse_y) / (v)); double Vy = v * Math.sin(a); double Vx = v * Math.cos(a); double t = arrow_x/Vx; double h = 200; arrow_y = (16) * Math.pow(t, 2) + (Vy * t) + h; int x = (int)Math.round(arrow_x); int y = (int)Math.round(arrow_y); A.setBounds(x, y,10,10); if (arrow_y>=500) T.stop(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)