Advertisement
Guest User

Usozo.java

a guest
Feb 26th, 2011
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package com.eschere.usozo;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.puredata.android.io.AudioParameters;
  7. import org.puredata.android.io.PdAudio;
  8. import org.puredata.core.PdBase;
  9. import org.puredata.core.utils.IoUtils;
  10.  
  11. import android.util.Log;
  12. import processing.core.*;
  13.  
  14. public class Usozo extends PApplet {
  15.  
  16.     Blune blune;
  17.     Background back;
  18.     Sound sound;
  19.     private static final int SAMPLE_RATE = 44100;
  20.     int inactiveThreshold = 300 + (int)random(-100, 100);
  21.     int inactiveCounter;
  22.     int randomPointInterval = (int)random(300, 500);
  23.     float centerX, centerY;
  24.     float usozoSpeed;
  25.     boolean mouseInactive, mouseStarted = false;
  26.     boolean renderText;
  27.     int backgroundColor = color(100, 100, 120);
  28.     String patch;
  29.  
  30.    
  31.  
  32.     public void setup() {    
  33.         noFill();
  34.         centerX = random(screenWidth/3, screenWidth/3 + screenWidth/3);
  35.         centerY = random(screenHeight/3, screenHeight/3 + screenHeight/3);
  36.         blune = new Blune(10, this);
  37.         back = new Background(200, 3, 50, this);
  38.         sound = new Sound(this);
  39.     }
  40.  
  41.     public void draw() {
  42.         if(!renderText) {
  43.             usozoSpeed = blune.speed();
  44.             background(100 + usozoSpeed * 10, 100 + usozoSpeed * 10, 120 + usozoSpeed * 4);
  45.         }
  46.         back.drawBackground("shadow");
  47.         back.drawBackground("front");
  48.         if(mouseX != 0 && !mouseStarted) mouseStarted = true;
  49.         mouseCount();
  50.         if(frameCount % randomPointInterval == 0 && mouseInactive) {  
  51.             centerX = random(screenWidth);
  52.             centerY = random(screenHeight);
  53.         }
  54.         else if(!mouseInactive && mouseStarted) {
  55.             centerX = mouseX;
  56.             centerY = mouseY;
  57.         }
  58.         blune.update(centerX, centerY, mouseInactive);
  59.         sound.sendData(centerX, centerY);
  60.     }
  61.  
  62.     void mouseCount() {
  63.         if(mouseX == pmouseX && mouseY == pmouseY) {
  64.             if(inactiveCounter < inactiveThreshold) {
  65.                 inactiveCounter++;
  66.             }
  67.             else if(inactiveCounter == inactiveThreshold) {
  68.                 mouseInactive = true;
  69.             }
  70.         }
  71.         else {
  72.             inactiveCounter = 0;
  73.             mouseInactive = false;
  74.         }  
  75.     }
  76.  
  77.     static public void main(String args[]) {
  78.         PApplet.main(new String[] { "Usozo" });
  79.     }
  80.    
  81.     @Override
  82.     protected void onResume() {
  83.         super.onResume();
  84.         int nOut = Math.min(AudioParameters.suggestOutputChannels(), 2);
  85.         try {
  86.             PdAudio.initAudio(SAMPLE_RATE, 0, nOut, 1, true);
  87.             PdAudio.startAudio(this);
  88.         } catch (IOException e) {
  89.             Log.e(sound.TAG, e.toString());
  90.         }
  91.     }
  92.    
  93.     @Override
  94.     protected void onPause() {
  95.         PdAudio.stopAudio();
  96.         super.onPause();
  97.     }
  98.    
  99.     @Override
  100.     public void onDestroy() {
  101.         sound.cleanup();
  102.         super.onDestroy();
  103.     }
  104.    
  105.     @Override
  106.     public void finish() {
  107.         sound.cleanup();
  108.         super.finish();
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement