e=new ArrayList<enemy>();
you.ang=atan2(mouseY-(height/2), mouseX-(width/2));
you.Sang=atan2(mouseY-(height/2), mouseX-(width/2));
for (int i=0; i<s.size(); i++) {
for (int i=0; i<e.size(); i++) {
line(mouseX,mouseY-mouseL,mouseX,mouseY+mouseL);
line(mouseX-mouseL,mouseY,mouseX+mouseL,mouseY);
if (mouseButton==RIGHT) {
s.add(new shot(degrees(you.ang), you.pos));
PVector pos=new PVector();
pos=new PVector(width/2, height/2);
base1=new PVector((width/2)+((Sd+5)*cos(Sang+radians(-Sd))), (height/2)+((Sd+5)*sin(Sang+radians(-Sd))));
base2=new PVector((width/2)+((Sd+5)*cos(Sang+radians(Sd))), (height/2)+((Sd+5)*sin(Sang+radians(Sd))));
line(base1.x, base1.y, base2.x, base2.y);
line(base1.x, base1.y, base2.x, base2.y);
translate((width/2), (height/2));
triangle(17.5, 0, -12.5, -12.5, -12.5, 12.5);
fill(0, 100, 255, 25+(sHP*25));
ellipse(width/2, height/2, 42, 42);
e=new ArrayList<enemy>();
PVector baseDelta = PVector.sub(base2, base1);
PVector normal = new PVector(-baseDelta.y, baseDelta.x);
for (int a=0; a<s.size(); a++) {
s.get(a).loc.add(s.get(a).vel);
for (int a=0; a<s.size(); a++) {
PVector incidence = PVector.mult(s.get(a).vel, -1);
for (int i=0; i<coords.length; i++) {
if (PVector.dist(s.get(a).loc, coords[i]) < s.get(a).S) {
float dot = incidence.dot(normal);
s.get(a).vel.set(2*normal.x*dot - incidence.x, 2*normal.y*dot - incidence.y, 0);
s.get(a).vel.mult(s.get(a).mult);
baseLength = PVector.dist(base1, base2);
coords = new PVector[ceil(baseLength)];
for (int i=0; i<coords.length; i++) {
coords[i] = new PVector();
coords[i].x = base1.x + ((base2.x-base1.x)/baseLength)*i;
coords[i].y = base1.y + ((base2.y-base1.y)/baseLength)*i;
PVector loc=new PVector(), vel=new PVector(0, 0);
float ang=0, mult=8, mxB=10, S=7;
shot(float a, PVector l) {
vel=new PVector(mult*cos(ang), mult*sin(ang));
loc=new PVector((width/2)+(16*cos(ang)), (height/2)+(16*sin(ang)));
if ((loc.x<2 || loc.x>(width-2))) {
if ((loc.y<2 || loc.y>(height-2))) {
if (abs(dist(loc.x, loc.y, width/2, height/2))<=15) {
ellipse(loc.x, loc.y, S, S);
PVector pos=new PVector(), vel=new PVector(),sPos;
pos=new PVector(S, random(S, height-S));
pos=new PVector(width-S, random(S, height-S));
pos=new PVector(random(S, width-S), S);
pos=new PVector(random(S, width-S), height-S);
vel=PVector.fromAngle(atan2((height/2)-pos.y, (width/2)-pos.x)).normalize();
if (dist(pos.x, pos.y, width/2, height/2)<=15) {
for (int j=0; j<s.size(); j++) {
if (abs(s.get(j).loc.dist(pos))<((S/2)+(s.get(j).S/2))) {
float angle = atan2(s.get(j).loc.y-pos.y, s.get(j).loc.x-pos.x);
PVector tanPos=new PVector(pos.x - S * cos(angle), pos.y - S * sin(angle));
VectorLine vLine = new VectorLine(tanPos, 10, 1);
vLine.rotation = angle + HALF_PI;
PVector lineStart = vLine.getOneEnd();
PVector lineEnd = vLine.getOtherEnd();
PVector normalToLine = new PVector(-(lineStart.y - lineEnd.y), lineStart.x - lineEnd.x);
normalToLine.normalize();
PVector incidence = new PVector(-s.get(j).vel.x, -s.get(j).vel.y);
float incidenceDOTline = incidence.dot(normalToLine);
PVector temp = PVector.mult(normalToLine, (2*incidenceDOTline));
s.get(j).vel = PVector.sub(temp, incidence);
ellipse(pos.x, pos.y, S, S);
VectorLine(PVector position, float lineLength, float lineWidth)
this.position = position;
this.lineLength = lineLength;
this.lineWidth = lineWidth;
float xbit = position.x - cos(rotation) * lineLength/2;
float ybit = position.y - sin(rotation) * lineLength/2;
return new PVector(xbit, ybit);
float xbit = position.x + cos(rotation) * lineLength/2;
float ybit = position.y + sin(rotation) * lineLength/2;
return new PVector(xbit, ybit);