Pacman programming, edges.
in
Programming Questions
•
1 year ago
Hey guys,
im sorry if i miss something in the search function..i tried to find a similar thing to mine, but seems like im not smart enough to find it.
Well..i am creating a Pacman figure in my class and in my free time.
At the moment i am a little bit stuck in a "easy" task.
I want the Pacman to dissapear when he reaches the edges..and come from the other side back.
But my problem is, that i am only allowed to use my own code..i saw a few other versions how people fixed it...but i could not find it out for myself.
I managed to make the right and top side work...but well..the right and bottom side do not work.
Here is my Code, maybe you could look a bit over it and tell me how to fix my problem, would be great.
/* Program written by: K.T
Date: 17.10.2012 */
boolean movement = true; // boolean type for the mouth movement
float AngleOfMouth = 0; // definition of AngleOfMouth
float ChangeOfMouth = 6.1/180; // definition of ChangeOfMouth
float action = 0; // Action definition
float OpenAndClose = 0.1; // OpenAndClose definition
float eye = 0; // arc code definition of eye
float x = 200; // x definition for keypress
float y = 200; // y definition for keypress
int q = color(100,100,100); // Color definition for touching the edges
void setup() {
size(800, 600); // Window Size
colorMode(HSB,360,100,100);
}
void draw() {
// definition of "pacman"
pacman(2,2);
}
// Eye-size definition.
void pacman(int Eye_SizeX, int Eye_SizeY){
// opening and closing the mouth
if (movement == true) AngleOfMouth += ChangeOfMouth;
else AngleOfMouth -= ChangeOfMouth;
if (AngleOfMouth >= 6.1/8 || AngleOfMouth <= 0) movement = !movement;
if (action > 0.06){
OpenAndClose = -0.03;
} else if (action <= 0){
OpenAndClose = 0.03;
}
// keypress code for movement (define w,a,s,d)
if (keyPressed) {
if ((key == 'w') && (y>55)) { //w moves Pac Man up (not too high)
y = y-5;
}
else if ((key == 'a') && (x>55)) { //a moves PacMan left (not too left)
x = x-5;
}
else if ((key == 's') && (y<height-55)) { //s moves Pacman down (not too low)
y = y+5;
}
else if ((key == 'd') && (x<width-55)) { //d moves Pacman right (not too right)
x = x+5;
}
}
background(0); // whole background definition
// background changes on edges touch (interactive)
if(x > width-60){
background(0);
x = 0;
}
if(y > height-60){
background(0);
y = 0;
}
if(x < 60){
background(0);
}
if(y < 60){
background(0);
}
// food dot
fill((x +frameCount) % 360,100,100);
noStroke();
arc(300,200,15,15,eye,6.8-eye);
// Circle for Pacman (This time with an active arc() code)
fill(color(#FFFF00));
arc(x,y, 100, 100, 0+AngleOfMouth, 6.1-AngleOfMouth);
// Circle for the eye
fill(color(0));
noStroke();
arc(x+5,y-25,Eye_SizeX+15,Eye_SizeY+15,eye,6.8-eye);
}
1