Add judgement display upon hitting a note.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
3973e122cf
commit
9d522eeca4
@ -2,6 +2,9 @@ package main.java.LLSIG;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
@ -13,6 +16,10 @@ public class Canvas extends JPanel{
|
||||
this.setSize(size);
|
||||
this.setMinimumSize(size);
|
||||
}
|
||||
public Rectangle2D calculateStringBoundsFont(String msg, Font font) {
|
||||
FontRenderContext frc = this.getFontMetrics(font).getFontRenderContext();
|
||||
return font.getStringBounds(msg, frc);
|
||||
}
|
||||
public void paintComponent(Graphics g) {
|
||||
|
||||
final int MIDDLE_X = this.getWidth()/2;
|
||||
@ -22,6 +29,7 @@ public class Canvas extends JPanel{
|
||||
final int NOTE_SIZE = 96;
|
||||
final int LANE_SPACING_X = 100;
|
||||
final int NOTE_DISTANCE = (int)(LLSIG.WINDOW_SIZE.width/2)-NOTE_SIZE;
|
||||
final Color[] colorList = new Color[]{Color.BLACK,Color.BLUE,Color.CYAN,Color.DARK_GRAY,Color.GRAY,Color.GREEN,Color.LIGHT_GRAY,Color.MAGENTA,Color.ORANGE,Color.PINK,Color.RED,Color.WHITE,Color.YELLOW};
|
||||
|
||||
super.paintComponent(g);
|
||||
if (LLSIG.game!=null) {
|
||||
@ -39,10 +47,40 @@ public class Canvas extends JPanel{
|
||||
g.setColor(Color.GRAY);
|
||||
}
|
||||
//g.fillRect(MIDDLE_X-JUDGEMENT_LINE_WIDTH/2+LANE_X_OFFSET,MIDDLE_Y-JUDGEMENT_LINE_HEIGHT/2,JUDGEMENT_LINE_WIDTH,JUDGEMENT_LINE_HEIGHT);
|
||||
g.fillOval((int)(MIDDLE_X-Math.cos(Math.toRadians(22.5*i))*NOTE_DISTANCE-NOTE_SIZE/2),(int)(MIDDLE_Y+Math.sin(Math.toRadians(22.5*i))*NOTE_DISTANCE-NOTE_SIZE/2),NOTE_SIZE,NOTE_SIZE);
|
||||
int NOTE_X=(int)(MIDDLE_X-Math.cos(Math.toRadians(22.5*i))*NOTE_DISTANCE-NOTE_SIZE/2);
|
||||
int NOTE_Y=(int)(MIDDLE_Y+Math.sin(Math.toRadians(22.5*i))*NOTE_DISTANCE-NOTE_SIZE/2);
|
||||
g.fillOval(NOTE_X,NOTE_Y,NOTE_SIZE,NOTE_SIZE);
|
||||
g.setColor(NOTE_COLOR);
|
||||
|
||||
Lane lane = LLSIG.game.lanes.get(i);
|
||||
if (LLSIG.game.PLAYING) {
|
||||
if (LLSIG.game.musicPlayer.getPlayPosition()-lane.lastNote<500) {
|
||||
switch (lane.lastRating) {
|
||||
case PERFECT:
|
||||
g.setColor(colorList[(LLSIG.game.frameCount/10)%colorList.length]);
|
||||
break;
|
||||
case EXCELLENT:
|
||||
g.setColor(Color.YELLOW);
|
||||
break;
|
||||
case GREAT:
|
||||
g.setColor(Color.GREEN);
|
||||
break;
|
||||
case EARLY:
|
||||
g.setColor(Color.CYAN);
|
||||
break;
|
||||
case LATE:
|
||||
g.setColor(Color.MAGENTA);
|
||||
break;
|
||||
case MISS:
|
||||
g.setColor(Color.RED);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Rectangle2D textBounds = calculateStringBoundsFont(lane.lastRating.name(), g.getFont());
|
||||
g.drawString(lane.lastRating.name(),(int)(NOTE_X-textBounds.getCenterX()),(int)(NOTE_Y+textBounds.getHeight()));
|
||||
}
|
||||
}
|
||||
int noteCounter = 0;
|
||||
while (lane.noteExists(noteCounter)) {
|
||||
Note n = lane.getNote(noteCounter);
|
||||
|
||||
@ -60,6 +60,11 @@ public class LLSIG implements KeyListener{
|
||||
gameLoop = new Thread() {
|
||||
public void run() {
|
||||
frameCount++;
|
||||
for (int i=0;i<9;i++) {
|
||||
Lane l =lanes.get(i);
|
||||
l.markMissedNotes();
|
||||
l.clearOutInactiveNotes();
|
||||
}
|
||||
window.repaint();
|
||||
}
|
||||
};
|
||||
@ -146,6 +151,7 @@ public class LLSIG implements KeyListener{
|
||||
if (l.noteExists()) {
|
||||
Note n = l.getNote();
|
||||
int diff = n.getStartFrame()-LLSIG.game.musicPlayer.getPlayPosition();
|
||||
if (diff<=BAD_TIMING_WINDOW) {
|
||||
if (Math.abs(diff)<=PERFECT_TIMING_WINDOW) {l.lastRating=TimingRating.PERFECT;} else
|
||||
if (Math.abs(diff)<=EXCELLENT_TIMING_WINDOW) {l.lastRating=TimingRating.EXCELLENT;} else
|
||||
if (Math.abs(diff)<=GREAT_TIMING_WINDOW) {l.lastRating=TimingRating.GREAT;} else
|
||||
@ -154,6 +160,7 @@ public class LLSIG implements KeyListener{
|
||||
n.active=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
keyState[lane]=true;
|
||||
}
|
||||
//System.out.println("Pressed "+e.getKeyChar()+" on frame "+musicPlayer.getPlayPosition());
|
||||
|
||||
@ -60,4 +60,16 @@ public class Lane{
|
||||
}
|
||||
System.out.println("Note added: "+n);
|
||||
}
|
||||
public void markMissedNotes() {
|
||||
if (LLSIG.game.PLAYING) {
|
||||
noteChart.forEach((note)->{
|
||||
int diff = note.getStartFrame()-LLSIG.game.musicPlayer.getPlayPosition();
|
||||
if (diff<-LLSIG.BAD_TIMING_WINDOW) {
|
||||
note.active=false;
|
||||
lastRating = TimingRating.MISS;
|
||||
lastNote = LLSIG.game.musicPlayer.getPlayPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user