Pacman/game.java
2026-07-02 12:31:24 +02:00

72 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(11 * cellSize, 11 * cellSize);
}
public void draw() {
background(0);
pacman.draw();
for (int i = 0; i < wall.length; i++) {
render.drawWall(wall[i]);
}
}
public void keyPressed() {
pacman.keyPressed(keyCode);
}
public boolean wantMove(int ox, int oy, int nx, int 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, 4, 0, 5},
{0, 5, 0, 6},
{10,4,10,5},
{10,5,10,6},
};
}
}