i am trying to use the application known as processing but the coding i recieved is wrong. It has many values that i just dont know what to exactly change. this project is for lazer maze halloween type event that i want to finish.
here is the link for more guidance
http://www.instructables.com/id/LASER-Maze-Halloween-Haunted-House/
here is the code:
import ddf.minim.*; // audio library
import processing.serial.*; // serial communication library
import codeanticode.gsvideo.*; // video playback library
GSMovie movie; // new video object
Minim minim; // set up audio
AudioSnippet alarm;
PFont font;
boolean movieStarted;
float grn; // a green color
Serial myPort; // the Arduino serial port
int i; //
float timerStart; // players starting time
String timerTotal;
int score; // players score
int state; // controls state of the game and what is displayed on screen
// 0 = PRESS START screen
// 1 = show intro movie
// 2 = show 3, 2, 1, GO
// 3 = active game - show timer and score
// 4 = end of game - show final score
void setup() {
// set the window size
size(displayWidth, displayHeight); 100
// change to the port your Arduino is using
// don't generate a serialEvent() unless you get a newline character
:
// load and configure font
font = loadFont("CourierNewPSMT-60.vlw");
textAlign(CENTER);
textFont(font, 120);
fill(0,200,0);
// load sounds
minim = new Minim(this); // new audio object
alarm = minim.loadSnippet("c:/alarm.mp3"); // load sound effects
// load video
movie = new GSMovie(this, "laser_maze.mp4");
imageMode(CENTER);
reset();
}
void draw() {
delay(50);
drawbg();
switch(state) {
// PRESS START screen
case 0:
text("PRESS START", width/2, height/2);
break;
// play the intro movie
case 1:
// start the movie if it isn't playing
if(!movie.isPlaying()) {
movie.play();
textFont(font, 48);
fill(0,80,0);
}
// advance the game state if we are at the end of the movie
else if (movie.frame() == movie.length()) {
movie.stop();
state++;
}
// display the current frame
else {
image(movie, width/2, height/2);
text("press START to skip", width/2, height*0.85);
}
break;
// 3, 2, 1, GO
case 2:
// stop movie if it was skipped
if(movie.isPlaying()) {
movie.stop();
}
textFont(font, 120);
fill(0,200,0);
// show countdown
if (i >= 0){
if (i == 0) text("GO!", width/2, height/2);
else text(i, width/2, height/2);
i--;
}
// start the game
else {
state++;
// start the game timer
timerStart = millis();
}
delay(800);
break;
// active game - show the timer and score
case 3:
// calculate the timer
float milliseconds = (millis() - timerStart);
float seconds = truncate(milliseconds/1000.0);
//timerTotal = truncate(seconds);
timerTotal = ""+seconds;
// display timer and score on the screen
text("time", (width/4), height/2 - 40);
text(timerTotal, (width/4), height/2 + 80);
text("alarms", (width/4)*3, height/2 - 40);
text(score, (width/4)*3, height/2 + 80);
break;
// end of game - show final score
case 4:
textFont(font, 120);
fill(0,200,0);
text("time", (width/4), height/2 - 40);
text(timerTotal, (width/4), height/2 + 80);
text("alarms", (width/4)*3, height/2 - 40);
text(score, (width/4)*3, height/2 + 80);
textFont(font, 48);
fill(0,80,0);
text("press START to reset", width/2, height*0.85);
break;
default:
reset();
}
}
void movieEvent(GSMovie movie) {
movie.read();
}
void serialEvent (Serial myPort) {
// get the ASCII string
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace
inString = trim(inString);
if (inString.equals("alarm")){
if (state == 3){
// only play alarm sound if it is not already playing
//if (!alarm.isPlaying()) {
alarm.play(0);
score++;
//}
}
}
else if (inString.equals("start")){
if (state < 2 || state > 3){
state++;
}
}
else if (inString.equals("stop")){
if (state == 3){
grn = 200; // used for drawbg()
state++;
}
}
else if (inString.equals("reset")){
reset();
}
}
}
// resets game variables to defaults for new game
void reset() {
background(0);
score = 0;
state = 0;
i = 3;
movie.goToBeginning();
movieStarted = false;
textFont(font, 120);
fill(0,200,0);
}
// draws different backgrounds based on game state
void drawbg(){
if (state == 1 || state == 2) {
background(0);
}
else if (state == 4){
// fade green to black
grn -= 5;
if (grn < 1) grn = 0;
background(0, grn, 0);
}
else {
// set random width, position, and green color and draw vertical stripe
strokeCap(SQUARE);
strokeWeight(random(width/100,(width/100)*3));
float grn = random(0,50);
// use brighter green randomly or if alarm is playing
if (grn < 1 || alarm.isPlaying()) grn = random(50,200);
stroke(0,grn,0);
float x = random(0,width);
line(x,0,x,height);
// draw horizontal black bar for center 1/3 of screen
stroke(0,0,0);
strokeWeight(height/3);
line(0,height/2,width,height/2);
}
}
// returns your float truncated to tenths position
float truncate(float x){
if ( x > 0 )
return float(floor(x * 10))/10;
else
return float(ceil(x * 10))/10;
}
void stop() {
// always close Minim audio classes
alarm.close();
// always stop Minim before exiting
minim.stop();
// allow normal clean up routing to run after stop()
super.stop();
}