//WRITTEN BY GUS KRISTIANSEN import import import import [Link].*; [Link].*; [Link]; [Link].
*;
public class Marbles extends JFrame implements ActionListener { int w, h, ga1; Timer timer; public ArrayList marbles, walls; public Shooter shooter, goal; public Item boom = new Item("boom", 650, 100); public Marbles() { walls=new ArrayList(); marbles=new ArrayList(); w=700; h=700; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addKeyListener(new keyf()); setSize(w, h); setVisible(true); setResizable(false); [Link](new Wall(0, 200, 450, 50)); shooter=new Shooter(100, 100, 0, [Link]); goal = new Shooter(500, 500, [Link]); //[Link](new Marble(300, 50, 5, 5, 25, 25)); //[Link](new Marble(300, 50, -3, 2, 25, 25)); timer=new Timer(10, this); [Link](); } public static void main(String args[]){ new Marbles(); } public void paint(Graphics g){ [Link]([Link]); [Link](0,0,w,h); [Link]([Link]); [Link](shooter.x, shooter.y, shooter.w, shooter.h); [Link]([Link]); [Link](shooter.x+shooter.w/2, shooter.y+shooter.h/2, (int)(shooter.x +shooter.w/2+[Link]([Link])*[Link]), (int)(shooter.y+shooter.h/2+ [Link]([Link])*[Link])); [Link]([Link]); [Link](goal.x, goal.y, goal.w, goal.h); [Link]([Link]); if([Link]){[Link](boom.x, boom.y, 25, 25);} if(![Link]()){
for(int j = 0; j < [Link](); j++){ Marble m = (Marble)[Link](j); [Link]([Link]); [Link]((int)m.x, (int)m.y, m.w, m.h); } } [Link]([Link]); if(![Link]()){ for(int j = 0; j < [Link](); j++){ Wall w = (Wall)[Link](j); [Link](w.x, w.y, w.w, w.h); } } [Link](""+ga1, 100, 500); } public void actionPerformed(ActionEvent e){ step(); repaint(); } public void step(){ if(![Link]()){ for(int j = 0; j < [Link](); j++){ Marble m = (Marble)[Link](j); [Link](); } } checkCol(); } public void checkCol(){ if(![Link]()){ for(int j = 0; j < [Link](); j++){ Marble m = (Marble)[Link](j); for(int i = 0; i < [Link](); i++){ Marble n = (Marble)[Link](i); if(j!=i&&[Link]().intersects([Link]())){ //marble2marble collision if((int)[Link]==(int)[Link]&&(int)[Link]==(int)[Link]&&[Link] ().intersects([Link]())){ [Link](j); [Link](i-1); return; } int c = 0; while([Link]().intersects([Link]())){ [Link](.01, 1); [Link](.01, 1); c++; ga1=c; } double ang = Math.atan2(m.y-n.y, m.x-n.x); double pang = Math.atan2([Link], [Link]); double qang = Math.atan2([Link], [Link]);
double double double double double double double double [Link] = +[Link]/2)*fpys); [Link]/2)*fpys);
pxs = [Link]()*[Link](pang-ang); pys = [Link]()*[Link](pang-ang); qxs = [Link]()*[Link](qang-ang); qys = [Link]()*[Link](qang-ang); fpxs = qxs; fqxs = pxs; fpys = pys; fqys = qys; (int) ([Link](ang)*fpxs+[Link](ang
[Link] = (int)([Link](ang)*fpxs+[Link](ang+ [Link] = (int)([Link](ang)*fqxs+[Link](ang+ [Link]/2)*fqys); [Link] = (int)([Link](ang)*fqxs+[Link](ang+ [Link]/2)*fqys); //m.x+=c*.01*[Link]; //m.y+=c*.01*[Link]; [Link](.01, c); [Link](.01, c); //n.x+=c*.01*[Link]; //n.y+=c*.01*[Link]; } } for(int i = 0; i < [Link](); i++){ Wall w = (Wall)[Link](i); if([Link]().intersects([Link]())){ double double double double vert_ptop=[Link](m.x-(w.x+w.w)); vert_pbot=[Link]((m.x+m.w)-w.x); hor_pright=[Link]((m.y+m.h)-w.y); hor_pleft=[Link](m.y-(w.y+w.h));
double low=vert_ptop; if(vert_pbot<low){low=vert_pbot;} if(hor_pleft<low){low=hor_pleft;} if(hor_pright<low){low=hor_pright;} if(low==vert_pbot){ [Link]*=-1; m.x=w.x-m.w; }else if(low==vert_ptop){ [Link]*=-1; m.x=w.y+w.w; }else if(low==hor_pright){ [Link]*=-1; [Link]-=((w.y-m.h)-m.y)*.0001; m.y=w.y-m.h; }else if(low==hor_pleft){ [Link]*=-1; [Link]-=((w.y+w.h)-m.y)*.0001; m.y=w.y+w.h; } }
} if([Link]().intersects([Link]())){ [Link]=[Link]; } if([Link]().intersects([Link]())&&[Link]){ [Link]=false; for(double z = 0; z < 2*[Link]; z+=[Link]/4){ [Link](new Marble(boom.x+[Link](z)*25, boom.y+[Link] n(z)*25, [Link](z)*[Link](), [Link](z)*[Link](), 25, 25)); } } }
} }//collision
private class keyf extends KeyAdapter { public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { int key = [Link](); if (key == KeyEvent.VK_UP) { [Link]++; } if (key == KeyEvent.VK_DOWN) { [Link]--; } if (key == KeyEvent.VK_LEFT) { [Link]+=[Link]/10; } if (key == KeyEvent.VK_RIGHT) { [Link]-=[Link]/20; } if (key == KeyEvent.VK_SPACE) { [Link](marbles); } if (key == KeyEvent.VK_P) { //step(); [Link]=true; } }
} public class Level{ public ArrayList marbles, walls; public Shooter shooter; public Shooter goal; public Level(Shooter shooter, Shooter goal, Wall w){ [Link]=shooter; [Link]=goal; [Link](w); }
} public class Marble{ public int w, h; public double x, y, vx, vy; public Color color; public Marble(double x, double y, double vx, double vy, int w, int h){ this.x=x; this.y=y; this.w=w; this.h=h; [Link]=vx; [Link]=vy; int c = (int)([Link]()*4); switch(c){ case 0: color=[Link];break; case 1: color=[Link];break; case 2: color=[Link];break; case 3: color=[Link];break; } } public Marble(double x, double y, double vx, double vy, int w, int h, Co lor color){ this.x=x; this.y=y; [Link]=vx; [Link]=vy; this.w=w; this.h=h; [Link]=color; } public double getSpeed(){ return ([Link](vx*vx+vy*vy)); } public Rectangle getRect(){ return new Rectangle((int)x, (int)y, w, h); } public void move(){ vy+=.2; x+=vx; y+=vy;
} public void move(double f, int c){ vy+=.2*f*c; x+=vx*f*c; y+=vy*f*c; } public void unmove(double f, int c){ vy-=.2*f*c; x-=vx*f*c; y-=vy*f*c; } } public class Wall{ public int x, y, w, h; public Wall(int a, int b, int c, int d){ x=a; y=b; w=c; h=d; } public Rectangle getRect(){ return new Rectangle(x, y, w, h); } } public class Item{ public String id; public int x, y; public boolean active; public Item(String id, int x, int y){ [Link]=id; this.x=x; this.y=y; active = true; } public Rectangle getRect(){ return new Rectangle(x, y, 25, 25); } } public class Shooter{ public int x, y, w, h; public double rads, power; public Color color; public Shooter(int a, int b, double rads, Color c){ x=a; y=b; w=25; h=25; [Link]=rads; power = 5; color = c;
} public void shoot(ArrayList marbles){ [Link](new Marble(x, y, (int)([Link](rads)*power), (int)(Math .sin(rads)*power), 25, 25)); } public Shooter(int a, int b, Color c){ x=a; y=b; w=25; h=25; color = c; } public Rectangle getRect(){ return new Rectangle(x, y, w, h); } } }