exporting as application issues
              in 
             Integration and Hardware 
              •  
              3 months ago    
            
 
           
             I have just finished (kind of) my first Processing sketch thanks to the help from many people on this forum but now I want to export it and share it with the world it fails. The problem lies when moving between the welcome and game screen it freezes. I understand it is difficult without the sound files and images, would it be better if I uploaded the whole folder? Here is the code anyway.
            
             
            
            
              
           
 
            
           - import ddf.minim.*;
 - import processing.pdf.*;
 - import java.util.Date;
 - import sms.*;
 - import ddf.minim.ugens.*;
 - // -------------------------------------------------------------------AUTH DETAILS FOR TWITTER API---------------------------
 - static String OAuthConsumerKey = "myKey";
 - static String OAuthConsumerSecret = "mySecret";
 - static String AccessToken = "myAccessToken";
 - static String AccessTokenSecret = "myATSecret";
 - String myTimeline;
 - String myQueryWord = "cheese";
 - java.util.List statuses = null;
 - User[] friends;
 - TwitterFactory twitterFactory;
 - Twitter twitter;
 - RequestToken requestToken;
 - String[] theSearchTweets = new String[11];
 - long previousIdOfTweetContainingQuery = 0;
 - private static AccessToken loadAccessToken() {
 - return new AccessToken(AccessToken, AccessTokenSecret); // get my oauth details
 - }
 - //-------------------------------------------------------------------VARIABLES------------------------------------------------
 - String [] headlines;
 - public float inByte;
 - public String msg; //the tweets
 - public int speed;
 - public float total = 08.;
 - String typing = ""; // enter new tweet
 - String saved = ""; //save tweet to search
 - ArrayList<Tweets> tweets; //tweets array
 - boolean running = true;
 - boolean pull;
 - int delayTime = 2000;
 - PrintWriter output; //write to txt file
 - PImage img;
 - PImage forest;
 - PImage bullet;
 - PImage ammoi;
 - PFont font;
 - PFont arial;
 - boolean start;
 - boolean runOnce = true;
 - int score = 0;
 - int playButtonWidth, playButtonHeight;
 - int playButtonX, playButtonY;
 - int ammo = 4;
 - Minim minim;
 - AudioSample bang;
 - AudioSample hit;
 - AudioSample reload;
 - AudioPlayer forestSound;
 - //--------------------------------------------SETUP---------------------------------
 - void setup() {
 - font = createFont("PICOWA__.TTF", 20); //Fonts
 - arial = createFont("Arial", 80);
 - textFont(font, 20);
 - size(1440, 900);
 - img = loadImage("twitter_bird.png"); //Images
 - forest = loadImage("clouds.png");
 - bullet = loadImage("bullet.jpg");
 - ammoi = loadImage("ammo.png");
 - myQueryWord = "";
 - minim = new Minim(this); //Sounds
 - bang = minim.loadSample("bang.mp3");
 - hit = minim.loadSample("hit.mp3");
 - forestSound = minim.loadFile("forest.mp3");
 - reload = minim.loadSample("reload.mp3");
 - forestSound.play();
 - //------------------------------------------------------DRAW------------------------
 - }
 - void draw() {
 - if (start == true) {
 - gameScreen(); //Game
 - }
 - else if (start == false) {
 - welcomeScreen(); //Welcome screen
 - }
 - if ((total < 0) && (start == true)) {
 - gameOver(); //Game over screen
 - }
 - }
 - //------------------------------GAME SCREEN-------------------
 - void gameScreen() {
 - if (runOnce == true) { //effectivly run once when game starts
 - ammo = 4;
 - score = 0;
 - running = true;
 - configure();
 - thread("getSearch");
 - tweets = new ArrayList<Tweets>();
 - output = createWriter("tweets.txt"); // Print to txt file
 - tweets.add(new Tweets());
 - runOnce = false;
 - }
 - image(forest, 0, 0, displayWidth, displayHeight);
 - cursor(CROSS);
 - headlines = loadStrings("tweets.txt"); //read from txt file
 - for (int i = tweets.size()-1;i>=0;i--) {
 - Tweets tweet = tweets.get(i);
 - tweet.getTweet(i);
 - tweet.check(); // check to see if I have hit it
 - }
 - fill(255); // ammo boxes
 - rect(620, 20, 140, 40, 20);
 - rect(40, 20, 100, 40, 20);
 - rect(1190, 20, 180, 50, 20);
 - image(ammoi, 1200, 25, 40, 35);
 - image(ammoi, 1240, 25, 40, 35);
 - image(ammoi, 1280, 25, 40, 35);
 - image(ammoi, 1320, 25, 40, 35);
 - textFont(font, 35);
 - fill(0);
 - text(total, 630, 45);
 - text(score, 50, 45 );
 - if (ammo == 3) {
 - fill(255);
 - rect(1320, 25, 40, 35);
 - }
 - else if (ammo == 2) {
 - fill(255);
 - rect(1320, 25, 40, 35);
 - rect(1280, 25, 40, 35);
 - }
 - else if (ammo == 1) {
 - fill(255);
 - rect(1320, 25, 40, 35);
 - rect(1280, 25, 40, 35);
 - rect(1240, 25, 40, 35);
 - }
 - else if (ammo == 0) {
 - fill(255);
 - rect(1320, 25, 40, 35);
 - rect(1280, 25, 40, 35);
 - rect(1240, 25, 40, 35);
 - rect(1200, 25, 40, 35);
 - fill(0);
 - text("RELOAD!", 1200, 20, 160, 40);
 - }
 - if (mousePressed) { // ammo goes down...
 - ammo = ammo -1;
 - }
 - if (ammo < 1) {
 - ammo = 0;
 - }
 - reloading(); // and up
 - }
 - //------------------------------------WELCOME SCREEN-------------------------------------------------------------
 - void welcomeScreen() {
 - image(forest, 0, 0, displayWidth, displayHeight);
 - textFont(font, 100);
 - fill(255);
 - text("Twitter Targets", 300, 200, 1000, 500);
 - noFill();
 - noStroke();
 - rect(600, 500, 100, 50);
 - fill(255);
 - text("Start", 600, 500, 100);
 - if ((rectRectIntersect(800, 500, 800+100, 500+100, mouseX, mouseY, mouseX+200, mouseY+100) == true)) {
 - fill(0);
 - text("Start", 600, 500, 100);
 - }
 - fill(255);
 - textFont(arial, 20);
 - rect(600, 100, 300, 50, 18);
 - textMode(CENTER);
 - text("Enter a hashtag above and click start to begin. To reload, lift the left side of your macbook", 340, 350, 1000, 220);
 - fill(0);
 - text("# " + typing, 620, 135);
 - text(" " + saved, 620, 135);
 - if (mousePressed) {
 - if ((rectRectIntersect(800, 500, 800+100, 500+100, mouseX, mouseY, mouseX+200, mouseY+100) == true)) {
 - hit.trigger();
 - runOnce = true;
 - start = true; // move on to the game screen
 - }
 - else {
 - bang.trigger();
 - }
 - }
 - }
 - //----------------------------------------------------------------
 - void keyPressed() { //type hashtag to search
 - if (key == '\n') {
 - saved = typing;
 - typing = "";
 - myQueryWord = saved;
 - }
 - else {
 - if (keyCode == BACKSPACE && typing.length() > 0) {
 - typing = typing.substring(0, typing.length() -1);
 - }
 - else
 - if (key != CODED) typing += key;
 - }
 - }
 - //--------------------------------------------------------------------
 - void reloading() {
 - int[] vals = Unimotion.getSMSArray(); // motion detector in macbook
 - int inString = vals[0];
 - inByte = float(inString);
 - inByte = map(inByte, 0, 100, 0, 10);
 - if ((inByte > 4.00) && (ammo< 8)) { // if motion is detected reload ammo
 - ammo = 4;
 - reload.trigger();
 - }
 - }
 - boolean rectRectIntersect(float left, float top, float right, float bottom, // my collision detection algorithim
 - float otherLeft, float otherTop, float otherRight, float otherBottom) {
 - return !(left > otherRight || right < otherLeft || top > otherBottom || bottom < otherTop);
 - }
 - //--------------------------------------------------Game over screen------------------------------------------------------------
 - void gameOver() {
 - running = false;
 - image(forest, 0, 0, displayWidth, displayHeight);
 - font = createFont("PICOWA__.TTF", 35);
 - textFont(font, 80);
 - fill(255);
 - text("GAME OVER", 500, 100);
 - text("Score : " + score, 530, 500);
 - fill(255);
 - textFont(font, 50);
 - text("Try again?", 560, 300, 100);
 - if ((rectRectIntersect(900, 300, 900+100, 300+100, mouseX, mouseY, mouseX+450, mouseY+50) == true)) {
 - fill(0);
 - text("Try again?", 560, 300, 100);
 - }
 - if (mousePressed) {
 - if ((rectRectIntersect(900, 300, 900+100, 300+100, mouseX, mouseY, mouseX+450, mouseY+50) == true)) {
 - hit.trigger();
 - total = 05.;
 - start = false;
 - }
 - else {
 - bang.trigger();
 - fill(255);
 - }
 - }
 - }
 - void getSearch() {
 - while (running == true){
 - try {
 - println ("Searching.... Current time = " + hour() + ":" + minute() + ":" + second());
 - Query query = new Query(myQueryWord);
 - query.count(50); // how many results to fetch
 - QueryResult result = twitter.search(query);
 - ArrayList tweetsContainingQuery = (ArrayList) result.getTweets();
 - if (tweetsContainingQuery.size() > 0) {
 - Status mostRecentTweetContainingQuery = (Status) tweetsContainingQuery.get(0);
 - long mostRecentTweetContainingQueryId = mostRecentTweetContainingQuery.getId();
 - if (previousIdOfTweetContainingQuery == 0) {
 - previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
 - }
 - if (mostRecentTweetContainingQueryId != previousIdOfTweetContainingQuery) {
 - // my word is tweeted
 - previousIdOfTweetContainingQuery = mostRecentTweetContainingQueryId;
 - Date d = mostRecentTweetContainingQuery.getCreatedAt();
 - msg = mostRecentTweetContainingQuery.getText(); //msg becomes tweets
 - tweets.add(new Tweets()); // add to the tweet array
 - println(msg); //print in console for reference
 - output.println(msg);
 - output.flush(); //save to text file
 - //add to total to display number of tweets
 - }
 - }
 - }
 - catch (TwitterException te) {
 - println("Error connecting to Twitter: " + te); //let me know if somethings not right
 - };
 - delay(delayTime); // Delay time between fetching tweets
 - }
 - }
 - //-------------------------------------------------------------API CONFIGURATION---------------------------------------------
 - void configure(){
 - ConfigurationBuilder cb = new ConfigurationBuilder();
 - cb.setOAuthConsumerKey(OAuthConsumerKey);
 - cb.setOAuthConsumerSecret( OAuthConsumerSecret );
 - cb.setOAuthAccessToken( AccessToken);
 - cb.setOAuthAccessTokenSecret( AccessTokenSecret );
 - twitterFactory = new TwitterFactory(cb.build());
 - twitter = twitterFactory.getInstance();
 - println("connected");
 - }
 - public class Tweets {
 - String files = "file";
 - float ix = random(displayWidth - 100);
 - float iy = random(displayHeight - 400);
 - float iw = 25;
 - float ih = 25;
 - boolean collide;
 - float iyi = iy;
 - int speed = 0;
 - int up = 0;
 - void getTweet(int index) {
 - if (index < headlines.length) {
 - image(img, ix, iyi, 100, 100); // if there are tweets display the bird
 - iyi = iyi + speed;
 - if (iyi == iy ) { // whilst the bird is up reduce time limit
 - total = total - 0.10;
 - }
 - if (collide == true && iyi == iy && ammo >= 1) { //bird drops if it is hit
 - image(bullet, ix+30, iy+40, 25, 25);
 - fill(255);
 - hit.trigger();
 - speed = 50;
 - total = total + 1;
 - score = score + 1;
 - }
 - if (speed > 5) { //tweet spirit rises up out of the bird
 - textFont(arial, 10);
 - text(headlines[index], ix, iy, iw, ih);
 - iyi = iyi + 10;
 - iy = iy - random(10);
 - iw = iw + 8;
 - ih = ih + 3;
 - }
 - }
 - if ((mousePressed == true) && (collide == false) && (ammo >= 1)) { //missed
 - bang.trigger();
 - }
 - }
 - void check() {
 - if (mousePressed) {
 - if ((rectRectIntersect(ix, iy, ix+100, iy+100, mouseX, mouseY, mouseX, mouseY) == true)) { //check if its hit
 - collide = true;
 - }
 - }
 - else {
 - collide = false;
 - }
 - }
 - }
 - //Unimotion.java
 - //Unimotion
 - package sms;
 - public class Unimotion {
 - // Load the JNI Interface
 - static {
 - System.loadLibrary("UnimotionLib");
 - }
 - // Native function
 - private static native int[] readSMS();
 - // Return three values as array
 - public static int[] getSMSArray() {
 - return readSMS();
 - }
 - // Return just the X
 - public static int getSMSX() {
 - return readSMS()[0];
 - }
 - // Return just the Y
 - public static int getSMSY() {
 - return readSMS()[1];
 - }
 - // Return just the Z
 - public static int getSMSZ() {
 - return readSMS()[2];
 - }
 - }
 
 
              
              1  
            
 
            