diff --git a/Pacman.class b/Pacman.class index 92be23d..4113f1d 100644 Binary files a/Pacman.class and b/Pacman.class differ diff --git a/Pacman.java b/Pacman.java index 22a502e..fa9371b 100644 --- a/Pacman.java +++ b/Pacman.java @@ -19,9 +19,25 @@ public class Pacman { /*---------------Methoden------*/ public void keyPressed(int keyCode) { - if (keyCode == game.LEFT) { + int oldX = x; int oldY = y; + if (keyCode == game.RIGHT) { x += game.cellSize; } + if (keyCode == game.LEFT) { + x -= game.cellSize; + } + x = (x + (10 * game.cellSize)) % (10 * game.cellSize); + if (keyCode == game.UP) { + y -= game.cellSize; + } + if (keyCode == game.DOWN) { + y += game.cellSize; + } + y = (y + (10 * game.cellSize)) % (10 * game.cellSize); + if (!game.wantMove(oldX/game.cellSize, oldY/game.cellSize, x/game.cellSize, y/game.cellSize)) { + x = oldX; + y = oldY; + } } public void draw() { diff --git a/game.class b/game.class index b40726a..7298b41 100644 Binary files a/game.class and b/game.class differ diff --git a/game.ctxt b/game.ctxt index 0a87090..7d7c866 100644 --- a/game.ctxt +++ b/game.ctxt @@ -10,8 +10,8 @@ comment3.params= comment3.target=void\ draw() comment4.params= comment4.target=void\ keyPressed() -comment5.params= -comment5.target=boolean\ wantMove() +comment5.params=ox\ oy\ nx\ ny +comment5.target=boolean\ wantMove(int,\ int,\ int,\ int) comment6.params= comment6.target=void\ populateWalls() numComments=7 diff --git a/game.java b/game.java index 3e9e8fc..69741b3 100644 --- a/game.java +++ b/game.java @@ -38,7 +38,23 @@ public class Game extends PApplet{ pacman.keyPressed(keyCode); } - public boolean wantMove() { + public boolean wantMove(int ox, int oy, int nx, int ny) { + System.out.println(","+ox+","+ oy+","+ nx+","+ ny); + if (ox == nx && oy > ny) { + int a = oy; + oy = ny; + ny = a; + } else if(ox > nx) { + int a = ox; + ox = nx; + nx = a; + } + for (int i = 0; i < wall.length; i++) { + int[] w = wall[i]; + if (w[0] == ox && w[1] == oy && w[2] == nx && w[3] == ny) { + return false; + } + } return true; }