Exemplo n.º 1
0
 public void loadData(String file) {
   try {
     Scanner txt = new Scanner(new File(file));
     mp3File = txt.nextLine();
     artist = txt.nextLine();
     album = txt.nextLine();
     while (txt.hasNext()) {
       long noteTime = txt.nextLong();
       int lengthThrowaway = txt.nextInt();
       String states = txt.next().trim();
       lines.add(new Line(noteTime, states));
     }
     song = new Music(mp3File);
     song.load();
   } catch (Exception e) {
     System.out.println(e);
   }
 } // end loadData
Exemplo n.º 2
0
  public void renderNotes(GLAutoDrawable gLDrawable, double dt) {
    // RENDER NOTES////////////////////////

    /*  OLD CODE TO CHECK/UPDATE TIME
    long songTime = song.getTime();
    long milliTime = System.currentTimeMillis();
    if(firstTime)
    {
    	time = songTime;
    	firstTime = false;
    }
    else
    {
    	if(songTime == oldSongTime)
    	{
    		updateTime += milliTime-oldTime;
    		System.out.println("update time: "+updateTime);

    	}
    	else
    	{
    		if (songTime == oldSongTime + updateTime)
    			System.out.println("WINWINWINWIWNWINWIWNWIN");
    		else
    			System.out.println("Difference: "+(songTime-oldSongTime - updateTime));


    		updateTime = 0;
    		System.out.println("New Time: "+time);
    	}
    	time = songTime + updateTime;
    }//end else

    	oldSongTime = songTime;
    	oldTime = milliTime;*/
    time = song.getTime();
    for (int i = lowestNoteToProcess; i < lines.size(); i++) {
      Line line = lines.get(i);
      if (line.getTime() - noteErrorDuration > time) break;
      if (line.getState() == 0) // not pressed
      {
        if (time > line.getTime() + noteErrorDuration) // missed line
        {
          // System.out.println("missed line");
          line.setState(3);
          score -= 1;
          lowestNoteToProcess++;
        }
      } // code below takes care of this
    } // end for

    // find closest line in bounds to be pressed
    // if a line exists
    // see if correct key combo was pressed
    // do the thing
    // else
    // play a bad line sound
    // if it doesnt exist
    // play a bad line sound
    Line closest = null;
    long closestDistance = 1000000;
    for (int i = lowestNoteToProcess; i < lines.size(); i++) {
      Line n = lines.get(i);
      if (n.getTime() - noteErrorDuration > time) break;
      if (n.getState()
          == 1) // user is holding down this line, so it is the only one that can be processed
      {
        closest = n;
        break;
      }
      if (Math.abs(time - n.getTime()) <= closestDistance
          && time >= n.getTime() - noteErrorDuration
          && time <= n.getTime() + noteErrorDuration) {
        closest = n;
        closestDistance = (long) Math.abs(time - n.getTime());
      }
    }
    if (closest != null) {
      if (closest.getState() == 0) // not pressed
      {
        boolean seq = true;
        for (int x = 0; x < 5; x++)
          if (key[x] != closest.getNotes()[x]) {
            seq = false;
            break;
          }
        if (seq) {
          // System.out.println("pressed button");
          closest.setState(2); // pressed button
          lowestNoteToProcess++;
        }
        score += 1;
      } else {
        // play bad line sound
      }
    }
    /*else if(closest.getState() == 1)
    { //holding and strummed, cant do that
    	closest.getState() = 2;
    	System.out.println("you interrupted the holding");
    	lowestNoteToProcess++;
    	//play bad line sound
    }*/
    // }
    else // (if closest == null)
    {
      // play bad line sound
    }

    // Part 2
    for (int i = lowestNoteToRender; i < lines.size(); i++) {
      Line line = lines.get(i);
      float posz =
          (line.getTime() + -targetPos / length * fretDuration - time)
              / fretDuration
              * length; // head
      if (posz > length) break; // not rendered yet
      float posz2 =
          (line.getTime() + -targetPos / length * fretDuration - time)
              / fretDuration
              * length; // tail
      if (posz2 <= 1) // will never be rendered again
      {
        lowestNoteToRender++;
        continue;
      }
      if (posz <= length)
        for (int x = 0; x < 5; x++) {
          if (!line.getNotes()[x]) continue;
          if (line.getState() == 2) continue; // pressed

          if (line.getState() == 3) // missed
          noteToDraw = new Note(127f, 127f, 127f);
          else noteToDraw = new Note(colors[x][0], colors[x][1], colors[x][2]);
          if (x < 4) noteToDraw.draw(gLDrawable, -3 + (1.5f * x), -4, -posz);
          else noteToDraw.drawBar(gLDrawable, -posz, false);
        }
    }
    // }//end if songIsPlaying
  }