88 lines
1.9 KiB
Java
88 lines
1.9 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;
|
|
|
|
boolean pressed = false;
|
|
int kCode;
|
|
int gameFrame = 0;
|
|
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() {
|
|
gameFrame ++;
|
|
|
|
if (pressed && gameFrame % 15 == 0) pacman.keyPressed(kCode);
|
|
|
|
background(0);
|
|
pacman.draw();
|
|
for (int i = 0; i < wall.length; i++) {
|
|
render.drawWall(wall[i]);
|
|
}
|
|
}
|
|
|
|
public void keyPressed() {
|
|
pressed = true;
|
|
kCode = keyCode;
|
|
}
|
|
|
|
public void keyReleased() {
|
|
pressed = false;
|
|
}
|
|
|
|
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},
|
|
{4,0,5,0},
|
|
{0, 5, 0, 6},
|
|
{10,4,10,5},
|
|
{10,5,10,6},
|
|
{-1,0,0,0},
|
|
{-1,1,0,1},
|
|
{1,-1,1,0},
|
|
};
|
|
}
|
|
}
|