add walls, movement
This commit is contained in:
parent
a5e0b2d32a
commit
e759c265f0
BIN
Pacman.class
BIN
Pacman.class
Binary file not shown.
18
Pacman.java
18
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() {
|
||||
|
||||
BIN
game.class
BIN
game.class
Binary file not shown.
@ -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
|
||||
|
||||
18
game.java
18
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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user