- code cleanup

- Verbeteringen in stoppen van audio
-- Simpelere afhandeling
-- Thread stopt wanneer (clip != null) ipv .stop()
This commit is contained in:
Bilel Bghiel
2015-06-19 19:40:35 +02:00
parent c019fdeea3
commit b86ce91755
11 changed files with 77 additions and 135 deletions
+4 -14
View File
@@ -25,8 +25,8 @@ public class GameStateManager {
public GameState currentState;
private SongHandler sh;
private int index = 0;
public int fps;
private int index = 0;
public int fps;
private float timeOfNoAction = 0,
maxTimeToHaveNoAction = 45000;
@@ -40,7 +40,7 @@ public class GameStateManager {
public GameStateManager(SongHandler sh, SQLConnector sql){
this.sh = sh;
gamestates = new ArrayList<GameState>();
gamestates = new ArrayList<>();
gamestates.add(new TitleState(this, sh, sql));
gamestates.add(new MenuState(this, sh, sql));
gamestates.add(new HelpState(this, sh, sql));
@@ -51,18 +51,10 @@ public class GameStateManager {
public void setState(State st)
{
if (st.ordinal() > 0)
if (currentState != null)
currentState.stopAudio();
currentState = gamestates.get(st.ordinal());
init();
}
public void next() {
index++;
index %= gamestates.size();
currentState = gamestates.get(index);
init();
}
@@ -89,13 +81,11 @@ public class GameStateManager {
public void buttonPressed(ButtonEvent e) {
timeOfNoAction = 0;
currentState.buttonPressed(e);
}
public void buttonReleased(ButtonEvent e) {
timeOfNoAction = 0;
currentState.buttonReleased(e);
}
public void onJoystickMoved(JoystickEvent e) {
+2 -2
View File
@@ -16,10 +16,10 @@ public class NetworkHandler implements Runnable{
private DatagramSocket udp;
private String host;
private int port;
private int port;
private boolean running;
private Thread t;
private Thread t;
private byte[] send,
receive;
+10 -13
View File
@@ -7,14 +7,14 @@ import control.NetworkHandler;
public class Button {
private Color color;
private int ledID,
buttonID;
private NetworkHandler ntw;
public int pressed;
private Color color;
private int ledID,
buttonID;
public int pressed;
private NetworkHandler ntw;
public Button(int buttonID, int ledID, NetworkHandler ntw)
{
public Button(int buttonID, int ledID, NetworkHandler ntw) {
color = new Color(255,255,255);
this.ledID = ledID;
this.buttonID = buttonID;
@@ -23,17 +23,14 @@ public class Button {
setLed();
}
private void setLed()
{
if(Window.ON_RASP)
{
private void setLed() {
if(Window.ON_RASP) {
ntw.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
ntw.show();
}
}
public void setColor(Color newColor)
{
public void setColor(Color newColor) {
color = newColor;
setLed();
}
+2 -2
View File
@@ -1,6 +1,6 @@
package control.button;
public interface ButtonListener {
public void buttonPressed(ButtonEvent e);
public void buttonReleased(ButtonEvent e);
void buttonPressed(ButtonEvent e);
void buttonReleased(ButtonEvent e);
}