update game

This commit is contained in:
hihoman23 2026-07-09 12:50:55 +02:00
parent d78d3c5538
commit 299c5ffffd
2 changed files with 15 additions and 3 deletions

Binary file not shown.

View File

@ -10,18 +10,23 @@ public class Game extends PApplet{
/*---------------Attribute-----*/ /*---------------Attribute-----*/
int cellSize = 40; int cellSize = 40;
Render render; Render render;
Pacman pacman; public Pacman pacman;
boolean pressed = false; boolean pressed = false;
int kCode; int kCode;
int gameFrame = 0; int gameFrame = 0;
int[][] wall; int[][] wall;
Ghost[] ghosts;
/*---------------Konstruktor---*/ /*---------------Konstruktor---*/
public Game() { public Game() {
String[] processingArgs = {"MySketch"}; String[] processingArgs = {"MySketch"};
PApplet.runSketch(processingArgs, this); PApplet.runSketch(processingArgs, this);
render = new Render(this);
pacman = new Pacman(this); pacman = new Pacman(this);
ghosts = new Ghost[4];
for (int i = 0; i < 4; i++) {
ghosts[i] = new Ghost(this, cellSize / 2 + cellSize * (i + 4), 300);
}
render = new Render(this);
populateWalls(); populateWalls();
} }
@ -36,8 +41,15 @@ public class Game extends PApplet{
gameFrame ++; gameFrame ++;
if (pressed && gameFrame % 15 == 0) pacman.keyPressed(kCode); if (pressed && gameFrame % 15 == 0) pacman.keyPressed(kCode);
if (gameFrame % 30 == 0) {
for (int i = 0; i < 4; i++) {
ghosts[i].move();
}
}
background(0); background(0);
for (int i = 0; i < 4; i++) {
ghosts[i].draw();
}
pacman.draw(); pacman.draw();
for (int i = 0; i < wall.length; i++) { for (int i = 0; i < wall.length; i++) {
render.drawWall(wall[i]); render.drawWall(wall[i]);