Ejemplo n.º 1
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
Ejemplo n.º 2
0
  public void changeColor() {

    // set initial color of top left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.cyan);
    }
    // set initial color of top right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.magenta);
    }
    // set initial color of bottom left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.yellow);
    }
    // set initial color of bottom right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.black);
    }
  }
Ejemplo n.º 3
0
  private ArrayList<RSTile> generatePath(Line[] lines) {
    double minStep = 5, maxStep = 10, wander = 3;
    if (lines.length < 2) return null;
    ArrayList<RSTile> path = new ArrayList<RSTile>();
    Line l1, l2 = lines[0];
    double distFromCenter = random(0, l2.getDistance() + 1);
    RSTile p = l2.translate((int) distFromCenter);
    distFromCenter = l2.getDistance() / 2 - distFromCenter;
    double centerXdist, centerYdist, line1Xdist, line1Ydist, line2Xdist, line2Ydist;
    double line1dist, line2dist, centerDist;
    double x, y;
    double distOnLine, last, cap1, cap2, move;
    double distFromCenterX1, distFromCenterY1, distFromCenterX2, distFromCenterY2;
    double force1, force2, slopeX, slopeY, slopeDist;
    boolean finished;
    int lastX = p.getX(), lastY = p.getY(), curX, curY;
    double dist, xdist, ydist;
    for (int i = 1; i < lines.length; i++) {
      l1 = l2;
      l2 = lines[i];
      centerXdist = l2.getCenterX() - l1.getCenterX();
      centerYdist = l2.getCenterY() - l1.getCenterY();
      centerDist = Math.sqrt(centerXdist * centerXdist + centerYdist * centerYdist);
      line1Xdist = l2.getX() - l1.getX();
      line1Ydist = l2.getY() - l1.getY();
      line2Xdist = l2.getX2() - l1.getX2();
      line2Ydist = l2.getY2() - l1.getY2();

      centerXdist /= centerDist;
      centerYdist /= centerDist;
      line1Xdist /= centerDist;
      line1Ydist /= centerDist;
      line2Xdist /= centerDist;
      line2Ydist /= centerDist;
      distOnLine = 0;
      last = 0;
      finished = false;
      while (!finished) {

        distOnLine += random(minStep, maxStep);
        if (distOnLine >= centerDist) {
          distOnLine = centerDist;
          finished = true;
        }
        x = centerXdist * distOnLine + l1.getCenterX();
        y = centerYdist * distOnLine + l1.getCenterY();

        distFromCenterX1 = x - (line1Xdist * distOnLine + l1.getX());
        distFromCenterY1 = y - (line1Ydist * distOnLine + l1.getY());

        distFromCenterX2 = x - (line2Xdist * distOnLine + l1.getX2());
        distFromCenterY2 = y - (line2Ydist * distOnLine + l1.getY2());

        slopeX = distFromCenterX2 - distFromCenterX1;
        slopeY = distFromCenterY2 - distFromCenterY1;
        slopeDist = Math.sqrt(slopeX * slopeX + slopeY * slopeY);
        slopeX /= slopeDist;
        slopeY /= slopeDist;

        line1dist =
            Math.sqrt(distFromCenterX1 * distFromCenterX1 + distFromCenterY1 * distFromCenterY1);
        line2dist =
            Math.sqrt(distFromCenterX2 * distFromCenterX2 + distFromCenterY2 * distFromCenterY2);

        move = (distOnLine - last) / maxStep * wander;

        force1 = line1dist + distFromCenter;
        force2 = line2dist - distFromCenter;

        cap1 = Math.min(move, force1);
        cap2 = Math.min(move, force2);

        if (force1 < 0) distFromCenter -= force1;
        else if (force2 < 0) distFromCenter += force2;
        else distFromCenter += random(-cap1, cap2);

        if (finished) {
          RSTile t = l2.translateFromCenter(distFromCenter);
          curX = t.getX();
          curY = t.getY();
        } else {
          curX =
              (int)
                  Math.round(distOnLine * centerXdist + l1.getCenterX() + distFromCenter * slopeX);
          curY =
              (int)
                  Math.round(distOnLine * centerYdist + l1.getCenterY() + distFromCenter * slopeY);
        }

        xdist = curX - lastX;
        ydist = curY - lastY;
        dist = Math.sqrt(xdist * xdist + ydist * ydist);
        xdist /= dist;
        ydist /= dist;
        for (int j = 0; j < dist; j++)
          path.add(
              new RSTile((int) Math.round(xdist * j + lastX), (int) Math.round(ydist * j + lastY)));

        last = distOnLine;
        lastX = curX;
        lastY = curY;
      }
    }
    return cutUp(path);
  }
Ejemplo n.º 4
0
 /**
  * creates a copy of this Line object. This method creates a new Line, sets its locations, sets
  * its select state, and returns the new Line.
  */
 public Object clone() {
   Line l = new Line(startX, startY, endX, endY);
   l.setLocation(getLocation());
   l.setSelectState(getSelectState());
   return l;
 }
Ejemplo n.º 5
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
  }