import processing.xml.*; import java.util.*; XMLElement xml; //sets deafault feed; String URL = "http://www.engadget.com/rss.xml"; // http://www.dvorak.org/blog/?feed=rss ||engadget.xml | int feedNum = 0; //** vars for feed txt String titleItem = "Can you rock da box?!?"; java.util.List titles; int hitCnt = 0; int titleIndex = -1; String feedLabel = ""; String gameResults = ""; //vars for opponent int xmove = 0; int gogo = 0; //** vars for laser beam int laserCount = 0; int lineY1 = height-80; int lineY2 = height-100; boolean laserMove = false; //sets default frameRate float frameCnt = 12; //* SETUP void setup() { size (600,400); smooth(); fill(0); frameCnt = 12; frameRate(frameCnt); titles = scrape(URL); // for (Iterator i=titles.iterator(); i.hasNext();) { // println((String)i.next()); // } } //* DRAW void draw() { println(frameCnt); println(frameRate); background(0); PFont font; PFont font2; font = loadFont("Tahoma-14.vlw"); font2 = loadFont("CenturyGothic-30.vlw"); textFont(font); fill(255); //* label for feed text(titleItem, width/30, height/6); //** label for different feed options fill(255); text("d = dvorak.org | e = engadget.com | i = infoworld.com", width/30, height-10); //*CALLS GOGO FUNCTION to get feed label at the top getFeed(); textFont(font2); text(feedLabel, width/1.75, height/10); //*CALL LASER FUNCTION laser(); //*CALL GOGO FUNCTION FOR BOUNCING BOX gogo(); //** USER AND LASER COUNT DISPLAY smooth(); stroke(150, 0, 0); fill(120, 120, 120,75); triangle(width/2-40, height-40, width/2, height-85, width/2+40, height-40); textFont(font); //** draws number of shots left String laserString = str(laserCount); fill(255); text(laserString, width/2 + 50, height-40); //**determines titleItem after the game is done... if ((laserCount <= 0)) { if (hitCnt > 0) { gameResults = "Yay! You got " + hitCnt + " out of " + feedNum; fill(150, 204, 47); } else { gameResults = "Boo! You got " + hitCnt + " out of " + feedNum; fill(150, 0, 0); } text(gameResults, width/30, height/5); } } //** function that strips items out of feed and puts them in List java.util.List scrape(String url) { titles = new ArrayList(); xml = new XMLElement(this, url); XMLElement category = xml.getChild(0); XMLElement[] children = category.getChildren(); for (int i=0; i= 0){ titleItem = titles.get(titleIndex).toString(); } } } //** GOGO: void gogo() { strokeWeight(1); //** OPPONENT SWITCH** these if statements are the switch for back and forth motion fill(120, 120, 120,75); if(gogo == 0){ //set the stroke color and make it more transparent as x decreases stroke(150, 204, 47, xmove/2); rect(xmove, 100, 50, 50); xmove += 20; //if it hits the side of the screen, reverse directions if(xmove >= width){ gogo = 1; } } //same as above, just in the other direction by decrementing xmove else if(gogo == 1){ stroke(150, 204, 47, xmove); rect(xmove, 100, 50, 50); xmove -= 20; if(xmove <= 0){ gogo = 0; } } } //** MOUSECLICKED: decrements lasercount and makes laser mean move up stage void mouseClicked() { if (laserCount > 0) { laserMove = true; laserCount --; } } //** LASER: void laser() { if (lineY2 <= 0) { laserMove = false; } if (laserMove) { stroke(150, 0, 0); strokeWeight(5); line(width/2, lineY1, width/2, lineY2); lineY1 -= 20; lineY2 -= 20; if ( (lineY2 >= 100) && (lineY2 <= 150) && (xmove >= abs(width/2-30)) && (xmove <=abs(width/2+30)) ) { laserMove = false; titleIndex ++; hitCnt ++; frameCnt ++; redraw(); frameRate(frameCnt); float rand = random(0, abs(feedNum)); titleItem = titles.get(titleIndex).toString(); } } // resets the position of the laser else if (laserMove == false) { lineY1 = height-80; lineY2 = height-100; } }