Added fade in animation
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package model.gameState;
|
||||
|
||||
import image.Images;
|
||||
import image.Images.ImageType;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import model.objects.MenuButton;
|
||||
@@ -16,14 +20,18 @@ import control.joystick.JoystickEvent;
|
||||
public class MenuState extends GameState {
|
||||
private ArrayList<MenuButton> buttons;
|
||||
private int selected;
|
||||
|
||||
int frame = 0;
|
||||
int maxFrames = 2560;
|
||||
int animationcounter;
|
||||
|
||||
public MenuState(GameStateManager gsm) {
|
||||
super(gsm);
|
||||
buttons = new ArrayList<MenuButton>();
|
||||
buttons.add(new MenuButton(330,50,1.7,"Genre", 0, Color.green));
|
||||
buttons.add(new MenuButton(330, 150, 1.7, "Most played", 10, new Color(0,0,255)));
|
||||
buttons.add(new MenuButton(330, 250, 1.7, "Best played", 20, Color.red));
|
||||
buttons.add(new MenuButton(330, 350, 1.7, "Last played", 30, Color.yellow));
|
||||
buttons.add(new MenuButton(-600, 50,1.7,"Genre", 0, Color.green));
|
||||
buttons.add(new MenuButton(-600, 150, 1.7, "Most played", 10, new Color(60,60,255)));
|
||||
buttons.add(new MenuButton(-600, 250, 1.7, "Best played", 20, Color.red));
|
||||
buttons.add(new MenuButton(-600, 350, 1.7, "Last played", 30, Color.yellow));
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
@@ -31,16 +39,20 @@ public class MenuState extends GameState {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
buttonInAnimation(animationcounter);
|
||||
for(MenuButton b:buttons){
|
||||
b.update();
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
for(MenuButton b:buttons){
|
||||
g2.drawImage(Images.getImage(ImageType.background), -640 -((frame * 4) % maxFrames), 0, 5120, 1024, null);
|
||||
for(MenuButton b:buttons){
|
||||
b.draw(g2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,5 +86,18 @@ public class MenuState extends GameState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonInAnimation(int button){
|
||||
if(button >= 0 && button < buttons.size() ){
|
||||
buttons.get(button).setX(buttons.get(button).getX()+40);
|
||||
if(buttons.get(button).getX() >= 320){
|
||||
animationcounter++;
|
||||
}
|
||||
if(buttons.get(button).getX() >= -200){
|
||||
buttonInAnimation(button+1);
|
||||
System.out.println(buttons.get(button).getX());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MenuButton {
|
||||
private boolean selected;
|
||||
private int fadecounter;
|
||||
|
||||
public MenuButton(int x, int y, double scale, String text, int rounding, Color color){
|
||||
public MenuButton(int x, int y, double scale, String text, int rounding, Color c0){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scalefactor = scale;
|
||||
@@ -31,29 +31,28 @@ public class MenuButton {
|
||||
this.rounding = rounding;
|
||||
calculateButton();
|
||||
|
||||
line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
|
||||
gradient = new LinearGradientPaint(
|
||||
new Point2D.Double((-358+x)*scalefactor,(167+y)*scalefactor),
|
||||
new Point2D.Double((-7+x)*scalefactor,(70+y)*scalefactor),
|
||||
new float[]{0.0f, 1.0f},
|
||||
new Color[]{new Color(color.getRed(), color.getGreen(), color.getBlue(), 10), color});
|
||||
|
||||
|
||||
colors = new ArrayList<Color>();
|
||||
// colors.add(new Color(47,153,21,255));
|
||||
// colors.add(new Color(36,120,16,255));
|
||||
// colors.add(new Color(48,154,22,255));
|
||||
// colors.add(new Color(77,254,41,255));
|
||||
// colors.add(new Color(61,201,32,255));
|
||||
// colors.add(new Color(77,254,41,255));
|
||||
|
||||
Color c1 = c0.darker();
|
||||
Color c2 = c0.darker().darker();
|
||||
Color c3 = c0.darker().darker().darker();
|
||||
|
||||
colors.add(color.darker().darker());
|
||||
colors.add(color.darker().darker().darker());
|
||||
colors.add(color.darker().darker());
|
||||
colors.add(color);
|
||||
colors.add(color.darker());
|
||||
colors.add(color);
|
||||
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(){
|
||||
@@ -66,6 +65,7 @@ public class MenuButton {
|
||||
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[][]){
|
||||
@@ -79,7 +79,7 @@ public class MenuButton {
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2d){
|
||||
for(int i = 0; i < buttonparts.size(); i++){ //fill every button part
|
||||
for(int i = 0; i < buttonparts.size(); i++){ //fill every part of the button with a specific color
|
||||
g2d.setColor(colors.get(i));
|
||||
g2d.fill((buttonparts.get(i)));
|
||||
}
|
||||
@@ -119,11 +119,18 @@ public class MenuButton {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public void setX(int x){
|
||||
this.x = x;
|
||||
calculateButton();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user