Kleuren scrollen mee met het liedje
This commit is contained in:
@@ -39,6 +39,16 @@ public class MenuState extends GameState {
|
|||||||
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int kleurButton1 = 0;
|
||||||
|
int kleurButton2 = 1;
|
||||||
|
int kleurButton3 = 2;
|
||||||
|
int kleurButton4 = 3;
|
||||||
|
int kleurButton5 = 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MenuState(GameStateManager gsm, SongHandler sh) {
|
public MenuState(GameStateManager gsm, SongHandler sh) {
|
||||||
super(gsm, sh);
|
super(gsm, sh);
|
||||||
buttons = new ArrayList<MenuButton>();
|
buttons = new ArrayList<MenuButton>();
|
||||||
@@ -47,12 +57,12 @@ public class MenuState extends GameState {
|
|||||||
startanimation = true;
|
startanimation = true;
|
||||||
subscreen = false;
|
subscreen = false;
|
||||||
|
|
||||||
buttons.add(new MenuButton(-600, 50,1.7, 0, Color.green, selectedToSong(selected-2) ));
|
// buttons.add(new MenuButton(400,150,GameModel.colors[kleurInt-2],selectedToSong(selected-2)));
|
||||||
buttons.add(new MenuButton(-600, 150, 1.7, 10, Color.BLUE, selectedToSong(selected-1)));
|
// buttons.add(new MenuButton(400,250,GameModel.colors[kleurInt-1],selectedToSong(selected-1)));
|
||||||
buttons.add(new MenuButton(-600, 250, 1.7, 20, Color.red, selectedToSong(selected)));
|
// buttons.add(new MenuButton(400,350,GameModel.colors[kleurInt],selectedToSong(selected)));
|
||||||
buttons.add(new MenuButton(-600, 350, 1.7, 30, Color.yellow,selectedToSong(selected+1)));
|
// buttons.add(new MenuButton(400,450,GameModel.colors[kleurInt+1],selectedToSong(selected+1)));
|
||||||
buttons.add(new MenuButton(-600, 450, 1.7, 30, Color.WHITE,selectedToSong(selected+2)));
|
// buttons.add(new MenuButton(400,550,GameModel.colors[kleurInt+2],selectedToSong(selected+2)));
|
||||||
buttons.get(2).setSelected(true);
|
// buttons.get(2).setSelected(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -72,15 +82,14 @@ public class MenuState extends GameState {
|
|||||||
}else{
|
}else{
|
||||||
previousScreen();
|
previousScreen();
|
||||||
}
|
}
|
||||||
for(MenuButton b:buttons){
|
|
||||||
b.update();
|
|
||||||
}
|
|
||||||
if(selected != oldselected){
|
if(selected != oldselected){
|
||||||
for(int i = 0; i < buttons.size(); i++){
|
for(int i = 0; i < buttons.size(); i++){
|
||||||
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
||||||
|
|
||||||
}
|
}
|
||||||
oldselected = selected;
|
oldselected = selected;
|
||||||
|
|
||||||
|
|
||||||
buttons2.clear();
|
buttons2.clear();
|
||||||
int instanceNr = 0;
|
int instanceNr = 0;
|
||||||
for(int i = sh.getCurrentSong().getSongs().size(); i>0; i--){
|
for(int i = sh.getCurrentSong().getSongs().size(); i>0; i--){
|
||||||
@@ -90,13 +99,20 @@ public class MenuState extends GameState {
|
|||||||
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
||||||
instanceNr += 100;
|
instanceNr += 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
|
buttons.clear();
|
||||||
|
buttons.add(new MenuButton(400,150,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
|
||||||
|
buttons.add(new MenuButton(400,250,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
|
||||||
|
buttons.add(new MenuButton(400,350,GameModel.colors[kleurButton3],selectedToSong(selected)));
|
||||||
|
buttons.add(new MenuButton(400,450,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
|
||||||
|
buttons.add(new MenuButton(400,550,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
|
||||||
|
buttons.get(2).setSelected(true);
|
||||||
|
|
||||||
|
|
||||||
g2.setColor(Color.BLACK);
|
g2.setColor(Color.BLACK);
|
||||||
@@ -212,6 +228,7 @@ public class MenuState extends GameState {
|
|||||||
difSelect = 0;
|
difSelect = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// System.out.println(difSelect);
|
// System.out.println(difSelect);
|
||||||
}
|
}
|
||||||
sh.set(sh.getCurrentSong().getSongs().get(difSelect));
|
sh.set(sh.getCurrentSong().getSongs().get(difSelect));
|
||||||
@@ -222,8 +239,56 @@ public class MenuState extends GameState {
|
|||||||
}else{ //Screen for selecting song
|
}else{ //Screen for selecting song
|
||||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||||
selected++;
|
selected++;
|
||||||
|
// if(kleurInt > GameModel.colors.length-1){
|
||||||
|
// kleurInt = 0;
|
||||||
|
// } else
|
||||||
|
// kleurInt++;
|
||||||
|
kleurButton1++;
|
||||||
|
kleurButton1 %= 6;
|
||||||
|
|
||||||
|
kleurButton2++;
|
||||||
|
kleurButton2 %= 6;
|
||||||
|
|
||||||
|
kleurButton3++;
|
||||||
|
kleurButton3 %= 6;
|
||||||
|
|
||||||
|
kleurButton4++;
|
||||||
|
kleurButton4 %= 6;
|
||||||
|
|
||||||
|
kleurButton5++;
|
||||||
|
kleurButton5 %= 6;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||||
selected--;
|
selected--;
|
||||||
|
kleurButton1--;
|
||||||
|
if(kleurButton1 < 0){
|
||||||
|
kleurButton1 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kleurButton2--;
|
||||||
|
if(kleurButton2 < 0){
|
||||||
|
kleurButton2 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kleurButton3--;
|
||||||
|
if(kleurButton3 < 0){
|
||||||
|
kleurButton3 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kleurButton4--;
|
||||||
|
if(kleurButton4 < 0){
|
||||||
|
kleurButton4 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kleurButton5--;
|
||||||
|
if(kleurButton5 < 0){
|
||||||
|
kleurButton5 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||||
sh.play(true);
|
sh.play(true);
|
||||||
|
|||||||
@@ -4,123 +4,60 @@ import java.awt.BasicStroke;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.LinearGradientPaint;
|
|
||||||
import java.awt.Paint;
|
|
||||||
import java.awt.geom.GeneralPath;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import model.GameModel;
|
||||||
import audio.Song;
|
import audio.Song;
|
||||||
|
|
||||||
public class MenuButton {
|
public class MenuButton {
|
||||||
|
|
||||||
private ArrayList<GeneralPath> buttonparts;
|
|
||||||
private GeneralPath border, line;
|
|
||||||
private ArrayList<Color> colors;
|
private ArrayList<Color> colors;
|
||||||
private Paint gradient;
|
private int x, y;
|
||||||
private int x, y, rounding;
|
|
||||||
private double scalefactor;
|
|
||||||
|
|
||||||
private boolean selected;
|
private boolean selected;
|
||||||
private int fadecounter;
|
|
||||||
|
|
||||||
private Song song;
|
private Song song;
|
||||||
|
Color color;
|
||||||
|
|
||||||
public MenuButton(int x, int y, double scale, int rounding, Color c0, Song song){
|
public MenuButton(int x, int y, Color color, Song song){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.scalefactor = scale;
|
this.color = color;
|
||||||
this.rounding = rounding;
|
|
||||||
calculateButton();
|
|
||||||
setSong(song);
|
setSong(song);
|
||||||
|
|
||||||
colors = new ArrayList<Color>();
|
|
||||||
|
|
||||||
Color c1 = c0.darker();
|
|
||||||
Color c2 = c0.darker().darker();
|
|
||||||
Color c3 = c0.darker().darker().darker();
|
|
||||||
|
|
||||||
c1 = new Color((int)(c1.getRed()*0.8), (int)(c1.getGreen()*0.8),(int)(c1.getBlue()*0.8));
|
|
||||||
c2 = new Color((int)(c2.getRed()*0.8), (int)(c2.getGreen()*0.8),(int)(c2.getBlue()*0.8));
|
|
||||||
c3 = new Color((int)(c3.getRed()*0.8), (int)(c3.getGreen()*0.8),(int)(c3.getBlue()*0.8));
|
|
||||||
|
|
||||||
colors.add(c2);
|
|
||||||
colors.add(c3);
|
|
||||||
colors.add(c2);
|
|
||||||
colors.add(c0);
|
|
||||||
colors.add(c1);
|
|
||||||
colors.add(c0);
|
|
||||||
|
|
||||||
gradient = new LinearGradientPaint(
|
|
||||||
new Point2D.Double((-100)*scalefactor,(512)*scalefactor),
|
|
||||||
new Point2D.Double((600)*scalefactor,(512)*scalefactor),
|
|
||||||
new float[]{0.0f, 1.0f},
|
|
||||||
new Color[]{new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), 10), c0});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateButton(){
|
|
||||||
buttonparts = new ArrayList<GeneralPath>();
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{449, 1}, {449, 68},{113, 103}, {106, 35}})); //background right
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{113, 103}, {106, 35},{70, 12+rounding}, {77, 88+rounding}})); //background middle
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{70, 12+rounding}, {77, 88+rounding},{4, 104+(int)(rounding*0.5)}, {-4, 32+(int)(rounding*0.5)}})); //background left
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{449, 15}, {449, 54},{118, 88}, {114, 48}})); //foreground right
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{118, 88}, {114, 48},{78, 25+rounding}, {82, 73+rounding}})); //foreground middle
|
|
||||||
buttonparts.add(arrayToGeneralpath(new int[][]{{78, 25+rounding}, {82, 73+rounding},{15, 88+(int)(rounding*0.5)}, {10, 43+(int)(rounding*0.5)}})); //foreground left
|
|
||||||
|
|
||||||
border = arrayToGeneralpath(new int[][]{{449,15}, {114,48},{78,25+rounding},{10,43+(int)(rounding*0.5)},{15,88+(int)(rounding*0.5)},{82,73+rounding},{118,88},{449,54}});
|
|
||||||
line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
|
|
||||||
}
|
|
||||||
|
|
||||||
public GeneralPath arrayToGeneralpath(int block[][]){
|
|
||||||
GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, block.length);
|
|
||||||
polyline.moveTo ((block[0][0]+x)*scalefactor, (block[0][1]+y)*scalefactor);
|
|
||||||
for (int index = 1; index < block.length; index++) {
|
|
||||||
polyline.lineTo((block[index][0]+x)*scalefactor, (block[index][1]+y)*scalefactor);
|
|
||||||
};
|
|
||||||
polyline.closePath();
|
|
||||||
return polyline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g2d){
|
public void draw(Graphics2D g2d){
|
||||||
for(int i = 0; i < buttonparts.size(); i++){ //fill every part of the button with a specific color
|
g2d.setColor(color);
|
||||||
g2d.setColor(colors.get(i));
|
g2d.fillRect(x,y,880,50);
|
||||||
g2d.fill((buttonparts.get(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(selected){
|
if(selected){
|
||||||
g2d.setStroke(new BasicStroke(4));
|
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.draw(border);
|
g2d.drawRect(x, y, 880, 50);
|
||||||
}
|
}
|
||||||
g2d.setPaint(gradient);
|
|
||||||
g2d.fill(line);
|
|
||||||
|
|
||||||
//draw text
|
//draw text
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
Font textFont = new Font("OCR A Extended", Font.BOLD, (int)(30*scalefactor));
|
Font textFont = new Font("OCR A Extended", Font.BOLD,60);
|
||||||
g2d.setFont(textFont);
|
g2d.setFont(textFont);
|
||||||
g2d.translate((x+160)*scalefactor, (y+74)*scalefactor);
|
g2d.drawString(song.getTitle(), x+50, y+50);
|
||||||
g2d.rotate(-0.1);
|
|
||||||
g2d.drawString(song.getTitle(), 0, 0);
|
|
||||||
g2d.rotate(0.1);
|
|
||||||
g2d.translate(-(x+160)*scalefactor, -(y+74)*scalefactor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
// public void update(){
|
||||||
if(selected && fadecounter < 5){
|
// if(selected && fadecounter < 5){
|
||||||
x += 8;
|
// x += 8;
|
||||||
y -= 8;
|
// y -= 8;
|
||||||
scalefactor += 0.04;
|
// scalefactor += 0.04;
|
||||||
fadecounter++;
|
// fadecounter++;
|
||||||
calculateButton();
|
// calculateButton();
|
||||||
}else if(!selected && fadecounter >0){
|
// }else if(!selected && fadecounter >0){
|
||||||
x += 8;
|
// x += 8;
|
||||||
y += 8;
|
// y += 8;
|
||||||
fadecounter--;
|
// fadecounter--;
|
||||||
scalefactor -= 0.04;
|
// scalefactor -= 0.04;
|
||||||
calculateButton();
|
// calculateButton();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setSelected(boolean selected) {
|
public void setSelected(boolean selected) {
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
@@ -131,7 +68,6 @@ public class MenuButton {
|
|||||||
}
|
}
|
||||||
public void setX(int x){
|
public void setX(int x){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
calculateButton();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
|
|||||||
Reference in New Issue
Block a user