Big&Small Pacmans

In this project, originally, I made a pacman animation. Red picman and yellow picman show in the screen at the same time with their mouths open and close alternatively. The yellow pacman goes beyond the red pacman and then disappears while the red pacman stays in the screen. Ocassionally, I found a game on the website which I mix my idea into it. There are two balls in the game, you can use your mouse to control one ball and catch up with the other ball. When the two balls meet, their sizes and speeds will change. My originally idea can help the game change simple balls into cute pacmans, in addition, the background of the game can be adjusted to a more colourful scene.

You can see the video here: Processing Game

However, when I tried to fix the game’s code by inserting my original code into it, there was something wrong happened. I only paid attention to the part where I wanted to change and ignored the whole body of the code. With Scoot’s help, finally I got the old-based new game! This experience reminds me to get clear about each steps and the logics in the code, why to write in this way other than other ways. In addition, I will focus more on the process of writing codes and make every step clear for me.

Here is the code:

float x, y;
float V;
float Vx, Vy;
float Real;
float R;
float sphereR;
float spherex;
float spherey;
float Dxsphere;
float Dysphere;
float myArc = 0;
int myColor = 0;

void setup() {
  size(700, 700);
  x = width/2;
  y = height/2;
  Real = 10;
  spherex = random(0, width);
  spherey = random(0, height);
  sphereR = random(8, R);
void draw() {
  myColor ++;
  background(0, myColor, 200);
  myArc += 0.02;
  if (myArc > PI/5) {
    myArc = 0;
  V = 50/Real + 1;
  float Dx = mouseX - x;
  float Dy = mouseY - y;
  float D = sqrt(sq(Dx)+sq(Dy));
  Vx = (V/D)*Dx;
  Vy = (V/D)*Dy;
  float Dxsphere = spherex - x;
  float Dysphere = spherey - y;
  float sphereD = sqrt(sq(Dxsphere)+sq(Dysphere));

  // this is the chaser
  //fill(250, 250, 0);
  //ellipse(x, y, 2*R, 2*R);

  fill(250, 250, 0);
  arc(x, y, 2*R, 2*R, myArc, 2*PI - myArc);
  fill(250, 0, 0);
  ellipse(x+3, y-19, 10, 10);


  // this is the chasee
  //fill(250, 0, 0);
  //ellipse(spherex, spherey, 2*sphereR, 2*sphereR);

  fill(250, 0, 0);
  arc(spherex, spherey, 2*sphereR, 2*sphereR, myArc, 2*PI - myArc);
  fill(250, 250, 0);
  ellipse(spherex+3, spherey-19, 10, 10);

  if (sphereD < abs(R) - abs(sphereR)) {
    Real = sqrt(sq(R)+sq(sphereR));
    spherex = random(0, width);
    spherey = random(0, height);
    sphereR = random(9, R);
  if (R < Real) {
    R+= 2.5;
void keyPressed() {
  if (key == 'r') {
void restart() {
  x = width/2;
  y = height/2;
  Real = 10;
  R = Real;
  spherex = random(0, width);
  spherey = random(0, height);
  sphereR = random(3, R);



Leave a Reply