Game issues for christmas

In my opinion you could rewrite your mousePressed like this:



function mousePressed() {

  if (state==0) {
    mousePressedForState0();
  }
  //----
  else if (state==1) {
    mousePressedForState1();
  }
  //----
  else if (state==2) {
    mousePressedForState2();
  }
  //----
  else if (state==3) {
    mousePressedForState3();
  }
  //----
  else if (state==4) {
    mousePressedForState4();
  }
  //----
  else if (state==5) {
    mousePressedForState5();
  } else {
    // error
    println ("Error"); 
    exit(); 
    return;
  }//else 
  //
}//function

Then make those functions and put what you have in mousePressed now inside those functions (the stuff for state 0 in the appropriate function mousePressedForState0() and so on).

Then your code is better readable since it’s in nice modules.

Same goes for function draw() by the way

2 Likes