For statement problem

edited January 2014 in Questions about Code

Hello :) So im fairly new at processing. This is supposed to be just a simple whackamole game, everything was working fine until I tried to set a timerScore variable to decrease the amount of time that they had to click on the mole every time they gained 5 points. And I'm fairly sure the problem lies in that for statement. Your comments and thoughts would be greatly appreciated! My code is below.

PTimer timer;
int timerScore;
int score;
float moleX;
float moleY;
PImage mole;
PImage mallet;
PImage grass;
float time;
boolean move;

void setup() {
  size(600, 600);
  score = 0;
  moleX = random(600);
  moleY = random(600);
  textSize(36);
  grass = loadImage("grass.jpg");
  mallet = loadImage("mallet.jpg");
  timer = new PTimer();
  move = false;
  timerScore = 0;

}

void draw() {
  // clear the background
  background (grass);

  // draw the mole
  fill(150, 100, 25);
  ellipse(moleX, moleY, 50, 50);


  // write the score
  fill(0, 200, 100);
  text(score, 400, 50);

  //draw the mallet
 // mallet = (mouseX, mouseY);

  cursor(mallet);

  //change the speed of the mole
   for (timerScore = 5) {
        timer.callIn = 5000 - 100;
        timerScore = 0;
}

void mousePressed() {
  float distance = dist(mouseX, mouseY, moleX, moleY);
  if (distance < 25) {
    // got one
    score = score + 1;
    timerScore = timerScore + 1;
    moleX = random(600);
    moleY = random(600);
  }
  else 
 score = score - 1;
}

void callback() {
  timer.callIn (5000);
}

Answers

  • @ # 45, shouldn't be an if rather than a for? :-?
    Also, you're gonna need an extra closing curly brace for draw().
    Use CTRL+T to format your code inside the IDE!

Sign In or Register to comment.