Pacman/game.java
2026-07-02 11:57:06 +02:00

68 lines
1.5 KiB
Java

/**
* Klasse game.
*
* @author
*/
import java.util.*;
import processing.core.PApplet;
public class Game extends PApplet{
/*---------------Attribute-----*/
int cellSize = 40;
Render render;
Pacman pacman;
int[][] wall;
/*---------------Konstruktor---*/
public Game() {
String[] processingArgs = {"MySketch"};
PApplet.runSketch(processingArgs, this);
render = new Render(this);
pacman = new Pacman(this);
populateWalls();
}
/*---------------Methoden------*/
public void settings() {
size(10 * cellSize, 10 * cellSize);
}
public void draw() {
background(0);
pacman.draw();
}
public void keyPressed() {
pacman.keyPressed(keyCode);
}
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;
}
public void populateWalls(){
wall = new int[][]{
{0, 0, 0, 1},
{0, 1, 1, 1},
};
}
}