Restructuring

This commit is contained in:
Urban Modig
2025-08-12 16:34:31 +02:00
parent 5ffb77dd00
commit 87b2d8df3c
14 changed files with 246 additions and 203 deletions

View 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);
}
}