Dotsy Code

int number=0; //numer of circles on the screen
int [] circleX = new int [50]; //X position of each circle
int [] circleY = new int [50]; //Y position of each circle
int [] dir = new int [50]; //Direction of each circle
color cpoint; //Used for collision detection
int ax=45;
int ay;
boolean reset=false;
int speed=1;
int count=0;
int score=0;
PFont font;

void setup()
{
  size (480, 580);
  ay=height-45;
  noStroke();
  smooth();
  frameRate(30);
  font = loadFont("AppleCasual-48.vlw");
  textFont(font, 48);
  restart();
}

void draw()
{
  background (220, 175, 0);
  if (reset==false) {
    updateCircles();
    bottomBox();
  }
  else {
    delay(2000);
    fill(0, 0, 255);
    textAlign(CENTER);
    text ("Touch to Restart",width/2, height/2-50);
    textAlign(LEFT);
//    rect(width/2-50, height/2-125, 100, 50);
    bottomBox();
  }
  speed=int(count/3)+1; //Speed increases by 1 for every three circles
}

void restart() //Sets Initial Conditions
{
  reset=false;
  number=0;
  circleX[0]=200;
  circleY[0]=200;
  dir[0] = int(random(1, 5));
  dir[1] = int(random(1, 5));
  speed=1;
  count=0;
  score=0;
}

void mousePressed() //Add next circle
{
  if (reset==false) {
    number++;
    circleX[number]=mouseX;
    circleY[number]=mouseY;
    dir[number+1]= int(random(1, 5)); //determine direction of next circle
    count++;
    score+=speed; //Increase Score. Later circles are worth more points
  }
  else if (mouseX>(width/2-50) && mouseX<(width/2+50) && mouseY>(height/2-125) && mouseY<(height/2+125)) {
    restart();
  }
}

void updateCircles()
{
  for (int i=0; i<=number; i++)
  {
    //Update the location of each circle
    switch (dir[i]) {
    case 1: //right
      circleX[i]+=speed;
      if (circleX[i]>width-1)
      {
        circleX[i]=1;
      }
      fill(255, 0, 0);
      break;
    case 3: //left
      circleX[i]-=speed;
      if (circleX[i]<1)
      {
        circleX[i]=width-1;
      }
      fill(0, 255, 0);
      break;
    case 2: //down
      circleY[i]+=speed;
      if (circleY[i]>height-101)
      {
        circleY[i]=1;
      }
      fill(0, 0, 255);
      break;
    case 4: //up
      circleY[i]-=speed;
      if (circleY[i]<1)
      {
        circleY[i]=height-101;
      }
      fill(255, 0, 255);
      break;
    }
    
    //check for collision.
    cpoint = get(circleX[i], circleY[i]); 
    if (cpoint!=color(220, 175, 0)) {
      reset=true;
    }
    
    //Redraw each circle
    ellipse(circleX[i], circleY[i], 25, 25); 
  }
}

void bottomBox() //Creates the Score box at the bottom of the screen
{
  fill(255, 255, 255);
  rect(0, height-100, width, 100);
  fill(0);
  text("Score = " + score, 110, height-30);
  nextDir();
}

void nextDir() //Draws the next circle's direction as a arrow
{
  pushMatrix();
  fill(0, 0, 0);
  translate(ax, ay);
  rotate(radians(90*dir[number+1]));
  rect(-5, -26, 10, 41);
  triangle(0, -41, -15, -26, 15, -26);
  popMatrix();
}

Comments