Restructuring
This commit is contained in:
46
src/main/java/se/urmo/game/state/PlayingState.java
Normal file
46
src/main/java/se/urmo/game/state/PlayingState.java
Normal file
@ -0,0 +1,46 @@
|
||||
package se.urmo.game.state;
|
||||
|
||||
import se.urmo.game.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class PlayingState implements GameState {
|
||||
private final Game game;
|
||||
private final GameStateManager gameStateManager;
|
||||
private PacMan pacman;
|
||||
private GameMap map;
|
||||
public PlayingState(Game game, GameStateManager gameStateManager) {
|
||||
this.game = game;
|
||||
this.gameStateManager = gameStateManager;
|
||||
this.map = new GameMap();
|
||||
this.pacman = new PacMan(game, new CollisionChecker(map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
pacman.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
map.draw(g);
|
||||
pacman.draw(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
switch (e.getKeyCode()) {
|
||||
case KeyEvent.VK_W -> pacman.setDirection(Direction.UP);
|
||||
case KeyEvent.VK_S -> pacman.setDirection(Direction.DOWN);
|
||||
case KeyEvent.VK_A -> pacman.setDirection(Direction.LEFT);
|
||||
case KeyEvent.VK_D -> pacman.setDirection(Direction.RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
pacman.setMoving(false);
|
||||
pacman.setDirection(Direction.NONE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user