game logic fixed by tips of johan
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package control;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import model.GameModel;
|
||||
import view.GameView;
|
||||
import control.button.ButtonEvent;
|
||||
@@ -7,17 +12,21 @@ import control.button.ButtonListener;
|
||||
import control.joystick.JoystickEvent;
|
||||
import control.joystick.JoystickListener;
|
||||
|
||||
public class GameControl implements JoystickListener, ButtonListener {
|
||||
public class GameControl implements JoystickListener, ButtonListener,ActionListener {
|
||||
|
||||
private long lastTime = System.currentTimeMillis();
|
||||
GameModel model;
|
||||
GameView view;
|
||||
GameStateManager gsm;
|
||||
Timer update;
|
||||
|
||||
public GameControl(GameModel model, GameView view,GameStateManager gsm)
|
||||
{
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
this.gsm = gsm;
|
||||
update = new Timer(0, this);
|
||||
update.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,4 +45,12 @@ public class GameControl implements JoystickListener, ButtonListener {
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
gsm.currentState.onJoystickMoved(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
model.update(currentTime - lastTime);
|
||||
lastTime = currentTime;
|
||||
view.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class GameStateManager {
|
||||
currentState.init();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
currentState.update();
|
||||
public void update(float factor){
|
||||
currentState.update(factor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user