public void sendToBack(Figure figure) { if (children.remove(figure)) { children.add(0, figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Decorations public void newDecos() { int prob = (int) (Math.random() * 100); // randomly spawnst he decoration if (prob == 1) { if (decoList.size() < 1) { int prob2 = (int) (Math.random() * 2); if (prob2 == 1) { // right side or left side decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, false)); } else { decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, true)); } } } Boolean check = true; for (Decorations i : decoList) { if (i.getYTop() >= 2000) { check = false; break; } } if (check == false && decoList.size() > 0) { // theres only on in the lsit but for consitency we kept it as a list decoList.remove(0); } }
public void bringToFront(Figure figure) { if (children.remove(figure)) { children.add(figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
public void checkStarCollision() { for (Star s : starList) { if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides if (s.checkCollision( s.getPics().get(s.getCounter()), player1)) { // if the player collides with the star we remove it then change the // velosity to the distance that the star provides sRemove.add(s); // remove star once you collide with it player1.setVelo(s.getDist()); // changes the velocity player1.setInvi(true); // sets the player invisble for a few seconds score += s.getPoints(); // points increase by the star type if (musicOn) { starSound.play(); // playthe star sound } } } else { sRemove.add(s); // remove the star if its not on the screen } } for (Star s : sRemove) { poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect starList.remove(s); } sRemove = new ArrayList<Star>(); }
public void checkEnemyCollision() { for (Enemy e : enemyList) { if (e.getOnScreen()) { // can be removed later on // goes through all the enemies and checks if they collide if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) { if (player1.getInvi() == false) { // If the player is not invisble then you get spiked. if (player1.getVelocity() > 0) { // if the player hits it from the bottom player1.setSpikeVelo(); loseCoins(); } else { player1.setVelo( 50); // if the player is on top instead the player bounces off the enemy if (musicOn) { bounce.play(); } } } eRemove.add(e); // once we hit, we remove the enemy } } else { eRemove.add(e); // if the enemy goes of the screen, we remove } } for (Enemy e : eRemove) { poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies enemyList.remove(e); } eRemove = new ArrayList<Enemy>(); }
public Figure basicRemoveChild(int index) { Figure figure = children.get(index); children.remove(index); quadTree.remove(figure); figure.removeFigureListener(figureHandler); needsSorting = true; return figure; }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Poofs public void removePoof() { // once the poof animation is the poof is removed from the list for (Poof p : poofList) { if (p.isDone()) { pRemove.add(p); } } for (Poof p : pRemove) { poofList.remove(p); } pRemove = new ArrayList<Poof>(); }
public static boolean polygonsIntersect(Polygon poly1, Polygon poly2) { // if any vertices from one polygon are inside the other polygon for (Mat vertex : poly1.vertices) { if (pointInPolygon(poly2, vertex)) { return true; } } for (Mat vertex : poly2.vertices) { if (pointInPolygon(poly1, vertex)) { return true; } } // if any edges hit eachother ArrayList<Mat> poly1EdgesA = poly1.vertices; ArrayList<Mat> poly1EdgesB = new ArrayList<Mat>(poly1EdgesA); poly1EdgesB.add(poly1EdgesB.get(0)); poly1EdgesB.remove(0); ArrayList<Mat> poly2EdgesA = poly2.vertices; ArrayList<Mat> poly2EdgesB = new ArrayList<Mat>(poly2EdgesA); poly2EdgesB.add(poly2EdgesB.get(0)); poly2EdgesB.remove(0); for (int e1 = 0; e1 < poly1EdgesA.size(); e1++) { for (int e2 = 0; e2 < poly2EdgesA.size(); e2++) { if (lineSegIntersect( poly1EdgesA.get(e1), poly1EdgesB.get(e1), poly2EdgesA.get(e2), poly2EdgesB.get(e2))) { return true; } } } // No? ok, cool. return false; }
public void checkJumperCollision() { // same as all the other collsions for (Jumper j : jumperList) { if (j.getOnScreen()) { // if (j.checkCollision(j.getImage(), player1)) { player1.setVelo(50); player1.setDown(false); if (musicOn) { bounce.play(); } } } else { jRemove.add(j); } } for (Jumper j : jRemove) { jumperList.remove(j); } jRemove = new ArrayList<Jumper>(); }
public void checkSpikeCollision() { // checks the spike collision for (Spikes s : spikeList) { if (s.getOnScreen()) { // if the spike is on the screen if (s.checkCollision(s.getImage(), player1)) { // if the user collides with the spike if (player1.getInvi() == false) { // if player is not invisiblity player1.setSpikeVelo(); // set the spike velocity loseCoins(); player1.setDown(true); } spRemove.add(s); } } else { spRemove.add(s); // remove the spike } } for (Spikes s : spRemove) { spikeList.remove(s); } spRemove = new ArrayList<Spikes>(); }
public void checkPupCollision() { // pretty much the same thing as before, however it alsoe does the powerup effects for (Powerup p : pupList) { if (p.getOnScreen()) { // can be removed later on if (p.checkCollision(player1)) { pupRemove.add(p); player1.setPower(p.getType()); player1.setVelo(50); } } else { pupRemove.add(p); } } if (player1.getPower().equals("Lucky")) { // changes everything to stars for (Coin c : coinList) { starList.add(new Star(c.getX(), c.getY(), 2)); cRemove.add(c); } for (Box b : boxList) { starList.add(new Star(b.getX(), b.getY(), 2)); bRemove.add(b); } for (Enemy e : enemyList) { starList.add(new Star(e.getX(), e.getY(), 2)); eRemove.add(e); } } else if (player1.getPower().equals("Magnet")) { // moves the coins towards the player for (Coin c : coinList) { c.moveTowards(player1); } } else { // else do nothing } for (Powerup p : pupRemove) { poofList.add(new Poof(p.getX(), p.getY(), 2)); pupList.remove(p); } pupRemove = new ArrayList<Powerup>(); }
public void checkBoxCollision() { // pretty much the same thing as all the other collisions for (Box b : boxList) { if (b.getOnScreen()) { // checks if its on the screen if (b.checkCollision(b.getImage(), player1)) { player1.setVelo(50); player1.setDown(false); b.setPcount( b.getPcount() - 1); // sets the type to one less so then you can bounce on it twice if (b.getPcount() == 0) { bRemove.add(b); // removes the box } if (musicOn) { bounce.play(); } } } else { bRemove.add(b); } } for (Box b : bRemove) { boxList.remove(b); } bRemove = new ArrayList<Box>(); }
public void checkCoinCollision() { for (Coin c : coinList) { if (c.getOnScreen()) { // check if the coin is on the screen if (c.checkCollision( c.getPics().get(c.getCounter()), player1)) { // if the player collides with the coin cRemove.add(c); // remove the coin player1.setVelo(50); // set the velocity so the player moves up player1.setDown(false); // set the down false (players moving up) coins += c.getValue(); // check the coins collected score += c.getPoints(); // get the score if (musicOn) { coinSound.play(); // play the sound } } } else { cRemove.add(c); // remove the coin } } for (Coin c : cRemove) { poofList.add(new Poof(c.getX(), c.getY(), 0)); coinList.remove(c); } cRemove = new ArrayList<Coin>(); }
// take the union of two polygons, assuming no enclosed empty spaces, and that the result will // be contiguous. public static Polygon combine(Polygon poly1, Polygon poly2) { ArrayList<Mat> vertices = new ArrayList<Mat>(); ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>(); int sizePoly1 = poly1.vertices.size(); int sizePoly2 = poly2.vertices.size(); int size = sizePoly1 + sizePoly2; boolean done; Publisher<GUISegmentMsg> segmentPub = node.newPublisher("/gui/Segment", "lab5_msgs/GUISegmentMsg"); Publisher<GUIEraseMsg> erasePub = node.newPublisher("/gui/Erase", "lab5_msgs/GUIEraseMsg"); // erasePub.publish(new GUIEraseMsg()); GUISegmentMsg segmentPlot = new GUISegmentMsg(); ColorMsg segmentPlotColor = new ColorMsg(); // add all the vertices in both polygons vertices.addAll(poly1.vertices); vertices.addAll(poly2.vertices); for (int i = 0; i < size; i++) { edgesTo.add(new TreeSet<Integer>()); } // add all the edges in both polygons for (int i = 0; i < sizePoly1; i++) { edgesTo.get(i).add(new Integer((i + 1) % sizePoly1)); edgesTo.get((i + 1) % sizePoly1).add(new Integer(i)); } for (int i = 0; i < sizePoly2; i++) { edgesTo.get(i + sizePoly1).add(new Integer(((i + 1) % sizePoly2) + sizePoly1)); edgesTo.get(((i + 1) % sizePoly2) + sizePoly1).add(new Integer(i + sizePoly1)); } System.err.println(vertices); System.err.println(edgesTo); segmentPlotColor.r = 255; segmentPlotColor.g = 0; segmentPlotColor.b = 0; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } } // find and merge colocated points done = false; while (!done) { done = true; checkFMCP: { for (int p0 = 0; p0 < size; p0++) { for (int p1 = 0; p1 < size; p1++) { if (p0 != p1) { if (ptsEqual(vertices.get(p0), vertices.get(p1))) { // System.err.println("found two colocated: " + p0 + " " + p1); // System.err.println(edgesTo); edgesTo.get(p0).addAll(edgesTo.get(p1)); edgesTo.get(p0).remove(p0); vertices.remove(p1); edgesTo.remove(p1); size--; for (int e0 = 0; e0 < size; e0++) { if (edgesTo.get(e0).contains(new Integer(p1))) { edgesTo.get(e0).remove(new Integer(p1)); edgesTo.get(e0).add(new Integer(p0)); } // System.err.println("e0: " + e0); // System.err.println(edgesTo.get(e0)); TreeSet<Integer> head = new TreeSet(edgesTo.get(e0).headSet(new Integer(p1))); // System.err.println(head); for (Integer e1 : edgesTo.get(e0).tailSet(new Integer(p1))) { head.add(e1 - 1); } head.remove(e0); // System.err.println(head); edgesTo.set(e0, head); // System.err.println(edgesTo.get(e0)); } done = false; // System.err.println(edgesTo); break checkFMCP; } } } } } } System.err.println("merged points"); System.err.println(edgesTo); /*segmentPlotColor.r = 0; segmentPlotColor.g = 0; segmentPlotColor.b = 255; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++){ for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } }*/ // find and split edges bisected by points done = false; while (!done) { done = true; checkFSEBP: { for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { for (int p = 0; p < size; p++) { if (e0 != p && e1 != p) { if (ptSegIntersect(vertices.get(e0), vertices.get(e1), vertices.get(p))) { edgesTo.get(p).add(new Integer(e0)); edgesTo.get(p).add(new Integer(e1)); edgesTo.get(e0).remove(new Integer(e1)); edgesTo.get(e0).add(new Integer(p)); edgesTo.get(e1).remove(new Integer(e0)); edgesTo.get(e1).add(new Integer(p)); done = false; break checkFSEBP; } } } } } } } System.err.println("split edges on points"); System.err.println(edgesTo); System.err.println("GOT HERE!"); int iters = 0; done = false; while (!done) { // find and split intersecting edges System.err.println("size: " + size); done = true; checkFSIE: { for (int e00 = 0; e00 < size; e00++) { for (int e10 = 0; e10 < size; e10++) { if (e00 != e10) { for (int e01 : new TreeSet<Integer>(edgesTo.get(e00))) { if (e01 != e10 && e01 != e00) { for (int e11 : new TreeSet<Integer>(edgesTo.get(e10))) { if (e11 != e00 && e11 != e01 && e11 != e10) { if (lineSegIntersect( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11))) { // System.err.println("intersectors for iter " + iters); // System.err.println(e00); // System.err.println(edgesTo.get(e00)); // Mat.print(System.err, vertices.get(e00)); // System.err.println(e01); // System.err.println(edgesTo.get(e01)); // Mat.print(System.err, vertices.get(e01)); // System.err.println(e10); // System.err.println(edgesTo.get(e10)); // Mat.print(System.err, vertices.get(e10)); // System.err.println(e11); // System.err.println(edgesTo.get(e11)); // Mat.print(System.err, vertices.get(e11)); if (iters > 10000) { // F**K! try { throw new Exception(); } catch (Exception e) { e.printStackTrace(); System.err.println("hey there"); System.exit(1); } } iters++; Mat newVertex = lineSegIntersection( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11)); if (ptsEqual(newVertex, vertices.get(e00))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e01))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e10))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e01)); } else if (ptsEqual(newVertex, vertices.get(e11))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e01)); } else { vertices.add(newVertex); edgesTo.add(new TreeSet<Integer>()); edgesTo.get(size).add(new Integer(e00)); edgesTo.get(size).add(new Integer(e01)); edgesTo.get(size).add(new Integer(e10)); edgesTo.get(size).add(new Integer(e11)); edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(size)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(size)); edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(size)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(size)); size++; } done = false; break checkFSIE; } } } } } } } } } System.err.println("split edges on edges"); System.err.println(edgesTo); } System.err.println("GOT HERE TOO!"); System.err.println("begin vertices"); for (Mat vertex : vertices) { Mat.print(System.err, vertex); } System.err.println("end vertices"); System.err.println(edgesTo); return perimeter(vertices, edgesTo); }
/* space ship has died from some sort of collision */ public void kill(ArrayList movingObjects) { int index = movingObjects.indexOf(this); movingObjects.remove(index); }