College project help - PACMAN!!
in
Programming Questions
•
1 years ago
Ok so if i could get help with this i would greatly appreciate it.
Basically, I have a figure of Pacman and need to move him around the screen using the Arrow keys. When it changes direction, the mouth has to face the appropriate way (ie. if I press up, he moves up and the mouth points up).
When the arrow key is depressed, the pacman is to stop.
When it gets to the edge of the screen, I want it to re-appear at the opposite side (if he goes off the screen at the left, he is to come back out on the right hand side.)
Also, I need to simulate him opening and closing his mouth like in the game.
Another thing I noticed, is when the keys are not pressed, the pacman disappears off the screen and only shows when a key is pressed.
Here is the code i have so far, and any help would be great.
- int radius = 10, direction = 1;
- int direction2 = 1;
- float x = 10, speed = 0.5, y = 10;
- void setup()
- {
- size(500,500);
- smooth();
- ellipseMode(RADIUS);
- }
- void draw()
- {
- background(0);
- if((x > width - radius) || (x < radius))
- direction = -direction;
- if((y > height - radius) || (y < radius))
- direction2 = -direction2;
- if(keyPressed)
- {
- if (key == CODED)
- {
- if(keyCode == RIGHT)
- x = x + speed * direction;
- if(keyCode == LEFT)
- x = x - speed * direction;
- if(keyCode == DOWN)
- y = y + speed * direction2;
- if(keyCode == UP)
- y = y - speed*direction2;
- }
- if(keyCode == RIGHT)
- arc(x, y, radius, radius, 0.52, 5.76);
- if(keyCode == LEFT)
- arc(x, y, radius, radius, 3.67, 8.90);
- if(keyCode == UP)
- arc(x, y, radius, radius, 5.15, 10.45);
- if(keyCode == DOWN)
- arc(x, y, radius, radius, 2.25, 7.35);
- }
- }
1