element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products & Partners
    Products & Partners
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum trying to make work by halloween
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 0 replies
  • Subscribers 337 subscribers
  • Views 290 views
  • Users 0 members are here
  • lazer
  • maze
  • processing
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

trying to make work by halloween

e14 Contributor
e14 Contributor over 13 years ago

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();

}

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube