Initial commit
This commit is contained in:
44
src/main/java/se/urmo/game/state/Playing.java
Normal file
44
src/main/java/se/urmo/game/state/Playing.java
Normal file
@ -0,0 +1,44 @@
|
||||
package se.urmo.game.state;
|
||||
|
||||
import se.urmo.game.Game;
|
||||
import se.urmo.game.GameMap;
|
||||
import se.urmo.game.PacMan;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
public class Playing {
|
||||
private PacMan pacMan;
|
||||
private GameMap map = new GameMap();
|
||||
private final CollisionChecker collisionChecker = new CollisionChecker(map);
|
||||
public Playing(Game game) {
|
||||
this.pacMan = new PacMan(game, collisionChecker);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
pacMan.update();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
pacMan.setMoving(true);
|
||||
switch (e.getKeyCode()) {
|
||||
case KeyEvent.VK_A -> pacMan.setLeft();
|
||||
case KeyEvent.VK_D -> pacMan.setRight();
|
||||
case KeyEvent.VK_W -> pacMan.setUp();
|
||||
case KeyEvent.VK_S -> pacMan.setDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
map.draw(g);
|
||||
pacMan.draw(g);
|
||||
}
|
||||
|
||||
public void keyReleased() {
|
||||
pacMan.setMoving(false);
|
||||
}
|
||||
public GameMap getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user