Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding A Timer with Score
    primarykey
    data
    text
    <p>Im Currently developing a game with Processing and Fiducials. Basically this game consists of asking questions related to certain countries. Each ANS of each question is a Country. Example where is the Tower of Pisa, and the ASN italy. the user must show a Fiducial that represents the Italian Flag</p> <p>I got the count down timer to run but i cant ge it to reset when a new level is started. we have each level in a switch. </p> <p>Thanks A lot guys for your help!!</p> <p>here is the code:</p> <pre><code> import ddf.minim.*; import TUIO.*; TuioProcessing tuioClient; HashMap&lt;Integer, String&gt; symbolWordMap=new HashMap&lt;Integer, String&gt;(); //The below variables are used to show the background image PImage bg; PImage start; PImage q1; PImage q2; PImage correct; PImage wrong; //The following are the variables used fro playing the sounds AudioPlayer player; AudioPlayer playerfail; Minim minim; int level = 0; int objSize=50; //This variable will be reduced everytime the player gets the answer wrong int lives = 5; //This variable will keep track of the score of the player int score = 0; //Declaring the font variable so as to display text on the screen PFont font; //Declaring the variable to be used for the timer //Timer t; //Below is the timer that will be used void time(){ int c; int csec; int climit = 20; //defined for a 20 second countdown c = climit*1000 - millis(); csec = (c/(1000)); if (csec &gt; 0){ text("TIME: "+csec+" secs",1800,50); } else { background(bg); text("TIME: 0 secs",1800,50); text("Time is up!",950,488); } } void setup() { symbolWordMap.put(0, "Start"); symbolWordMap.put(1, "Italy"); symbolWordMap.put(2, "France"); symbolWordMap.put(3, "Spain"); symbolWordMap.put(4, "UK"); symbolWordMap.put(5, "USA"); symbolWordMap.put(6, "Malta"); symbolWordMap.put(7, "Australia"); symbolWordMap.put(8, "Germany"); size(1920,976); //This is an instance of Minim minim = new Minim(this); //Load the applause mp3 file player = minim.loadFile("applause.mp3",2048); //Load the fail mp3 file playerfail = minim.loadFile("fail.mp3",2048); //Creating an instance of the Timer class //t = new Timer(20000); //savedTime = millis(); //The below statement will load the image to be placed as a background from the Data folder. This image must be the same size as the window in which the program will run bg = loadImage("map.png"); //Load the image for correct answer correct = loadImage("correct.png"); //Load image for the incorrect answer wrong = loadImage("wrong.jpg"); //Load the image for Question 1 q1 = loadImage("Question1.png"); //Load the image for Question 2 q2 = loadImage("question2.png"); //Load the image for the welcome page start = loadImage("Intro.png"); //Creating the font of text to be displayed on screen; font = createFont("Arial",24,true); rectMode(CENTER); textAlign(CENTER, CENTER); // an instance of the TuioProcessing // since we ad "this" class as an argument the TuioClient expects // an implementation of the TUIO callback methods tuioClient = new TuioProcessing(this); } void draw() { //The following command will present the background background(bg); //Specifying the font to be used for text that is displayed on screen textFont(font,24); //Specifying the colour of the text that will be displayed on screen fill(0); if (level&gt;0){ text("SCORE: "+score,100,50); //text("Lives: "+lives,100,100); } //Creating the different levels switch(level){ case 0: //Welcome Screen // get all the tuio objects detected by reactivision Vector&lt;TuioObject&gt; tuioObjectList =tuioClient.getTuioObjects(); image(start,550,160); // Process each fiducial in turn for (int i=0;i&lt;tuioObjectList.size();i++) { TuioObject tobj = tuioObjectList.get(i); pushMatrix(); // Move origin to location of TUI object and rotate translate(tobj.getScreenX(width), tobj.getScreenY(height)); rotate(tobj.getAngle()); // draw the box fill(255); rect(0, 0, objSize, objSize); // Write the text inside the box fill(0); int id = tobj.getSymbolID(); String txt; if (symbolWordMap.containsKey(id)) { // if ID is in symbolWordMap, then look it up to find word txt = symbolWordMap.get(id); } else { // otherwise, we'll just display the id number with a dot after txt = id+"."; } text(txt, 0, 0); popMatrix(); if (id == 0){ level = 1; delay(2000); } } break; case 1: //Level 1 //Start timer //time(); //noLoop(); // get all the tuio objects detected by reactivision Vector&lt;TuioObject&gt; tuioObjectList1 =tuioClient.getTuioObjects(); image(q1,550,160); // Process each fiducial in turn for (int i=0;i&lt;tuioObjectList1.size();i++) { TuioObject tobj = tuioObjectList1.get(i); pushMatrix(); // Move origin to location of TUI object and rotate translate(tobj.getScreenX(width), tobj.getScreenY(height)); rotate(tobj.getAngle()); // draw the box fill(255); rect(0, 0, objSize, objSize); // Write the text inside the box fill(0); int id = tobj.getSymbolID(); String txt; if (symbolWordMap.containsKey(id)) { // if ID is in symbolWordMap, then look it up to find word txt = symbolWordMap.get(id); } else { // otherwise, we'll just display the id number with a dot after txt = id+"."; } text(txt, 0, 0); popMatrix(); if (id == 1){ //Displays the text Correct on screen //text("Correct",500,500); score=score+10; background(bg); image(correct,800,300); player.play(); player.rewind(); //Time delay before advancing to next level delay(5000); //Advance to level 2 level++; } else { //Display the text Wrong to the left of the screen //text("Wrong",500,500); lives=lives-1; background(bg); image(wrong,700,300); playerfail.play(); playerfail.rewind(); } } break; case 2: //Level 2 //Start timer //time(); //noLoop(); // get all the tuio objects detected by reactivision Vector&lt;TuioObject&gt; tuioObjectList2 =tuioClient.getTuioObjects(); //Load image for question 2 image(q2,550,160); // Process each fiducial in turn for (int i=0;i&lt;tuioObjectList2.size();i++) { TuioObject tobj = tuioObjectList2.get(i); pushMatrix(); // Move origin to location of TUI object and rotate translate(tobj.getScreenX(width), tobj.getScreenY(height)); rotate(tobj.getAngle()); // draw the box fill(255); rect(0, 0, objSize, objSize); // Write the text inside the box fill(0); int id = tobj.getSymbolID(); String txt; if (symbolWordMap.containsKey(id)) { // if ID is in symbolWordMap, then look it up to find word txt = symbolWordMap.get(id); } else { // otherwise, we'll just display the id number with a dot after txt = id+"."; } text(txt, 0, 0); popMatrix(); if (id == 8){ //Displays the text Correct on screen //text("Correct",500,500); score=score+10; background(bg); image(correct,900,500); player.play(); player.rewind(); //Time delay before advancing to next level delay(5000); //Advance to level 2 level++; } else { //Display the text Wrong to the left of the screen //text("Wrong",500,500); lives=lives-1; background(bg); image(wrong,700,300); playerfail.play(); playerfail.rewind(); } } break; case 3: //Level 3 break; case 4: //Level 4 break; case 5: //Level 5 break; } //End of switch } void stopSound() { player.close(); playerfail.close(); minim.stop(); super.stop(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload