Ohhh I fix one thing and then something else went wrong.
Now I have a few problems:
1. It get stock before the end of the row.
2. The scores are going up but on each other and I want to draw a rect so it will be clear but I don't know where to draw it.
3. Since it stock I can't see if after I eat 2660 I get the "YOU WON".
4. A big problem- it still counts when it false and I don't want that to happen.
HELP!!!
Pacman pm;
int score;
int life;
PFont font;
boolean [] [] food = new boolean [14][19];
void setup()
{
size(800, 600);
frameRate(2);
life=3;
pm = new Pacman();
smooth();
font = createFont("AgencyFB-Reg-30.vlw", 30);
background(0);
////make the background dots=food
for (int x=40; x<width; x=x+40) {
for (int y=40; y<height; y=y+40) {
fill (255);
ellipse(x, y, 20, 20);
}
}
}
void draw()
{
pm.move();
pm.draw();
scoreLife();
startOver();
////make packman eat the "food"
for (int r=0; r<14; r++) {
for (int c=0; c<19; c++) {
food [r][c] = true;
}
}
if (food [pm.y/40][pm.x/40]) {
score += 10;
}
}
// ================================================
void keyPressed()
{
if (keyCode==DOWN)
{
pm.speedX=0;
pm.speedY=1;
}
if (keyCode==UP)
{
pm.speedX=0;
pm.speedY=-1;
}
if (keyCode == RIGHT)
{
pm.speedX=1;
pm.speedY=0;
}
if (keyCode == LEFT)
{
pm.speedX=-1;
pm.speedY=0;
}
}
//draw Score + Life
void scoreLife () {
textFont(font);
fill (0, 255, 255);
text("Score "+score, 600, 600);
fill (255, 0, 255);
text("Life "+life, 500, 600);
}
////start over the game every time pacman touches the X and Y walls
void startOver () {
if ((pm.x > width) || (pm.x < 0) ||
(pm.y > height) || (pm.y < 0)) {
background(0);
////make the background dots=food
for (int x=40; x<width; x=x+40) {
for (int y=40; y<height; y=y+40) {
fill (255);
ellipse(x, y, 20, 20);
}
}
pm = new Pacman();
life-=1;
score=0;
println("You died");
}
if (life==0)
{
println ("Game over");
background (0);
textFont(font);
fill (0, 255, 255);
text("GAME OVER ", height/2, width/2);
}
if (score==2660)
{
println ("YOU WON!!!");
background (0);
textFont(font);
fill (0, 255, 255);
text("YOU WON!!!", height/2, width/2);
}
}
class Pacman
{
int x, y;
int speedX, speedY;
int openClose;
Pacman()
{
x=0;
y=40;
speedX=1;
speedY=0;
openClose=0;
}
void draw()
{
// draw pacman with open mouth
if (openClose==1)
{
// Body
noStroke();
if (speedX == 1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 0.52, 5.76);
fill (0);
ellipse (pm.x-40,pm.y,40,40);
}
else if (speedX == -1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 3.67, 8.9);
fill (0);
ellipse (pm.x+40,pm.y,40,40);
}
else if (speedY == -1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 5.15, 10.45);
fill (0);
ellipse (pm.x,pm.y+40,40,40);
}
else if (speedY == 1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 2.25, 7.35);
fill (0);
ellipse (pm.x,pm.y-40,40,40);
}
}
// draw pamcan with close mouth
else
{
// Body
fill (255, 255, 0);
noStroke();
if (speedX == 1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 0, 6.9);
fill (0);
ellipse (pm.x-40,pm.y,40,40);
}
else if (speedX == -1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 0, 6.9);
fill (0);
ellipse (pm.x+40,pm.y,40,40);
}
else if (speedY == -1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 0, 6.9);
fill (0);
ellipse (pm.x,pm.y+40,40,40);
}
else if (speedY == 1)
{
fill (255, 255, 0);
arc(x, y, 30, 30, 0, 6.9);
fill (0);
ellipse (pm.x,pm.y-40,40,40);
}
}
openClose=1-openClose;
}
// make pacman move
void move()
{
x += speedX * 40;
y += speedY * 40;
food [y/40][x/40] = false;
}
}