How to finish this Ender's Game script in Processing?
<pre class="lang-java prettyprint-override"><code>   /* Draw a laser beam from the start point in the direction of the end point
 but have it stop if it bumps into a rock.*/

int laserColor = color(255, 0, 0);
int rockColor = color(0, 255, 0) ;
int startX = (1);
int startY = (1);
int laserX = (10);
int laserY = (20);
int laserDX = (30);
int laserDY = (40);

float r = 100;
float g = 150;
float b = 200;
float a = 200;
float f = 100;

float diam = 20;
float dim = 70;

float x = 100;
float y = 100;
float z = 20;
int t = 100;
int s = 100;
int w = 60;
int h = 60;
int eyeSize = 16;

void setup() {
  size(400, 400);
  background(239, 276, 238);
}

void draw() {
  drawPlayer();
  drawRocks();
  drawWall();
  drawBeam();
  background(255);
  if (mousePressed) {
    a--;
    fill(0);
    text("Score" + a, 325, 10);
  }
  {
  void drawPlayer(){
      // Draw player's head
  fill(255);
  ellipse(x,y,w,h);

  // Draw player's eyes
  fill(0);
  ellipse(x-w/3+1,y,eyeSize,eyeSize*2);
  ellipse(x+w/3-1,y,eyeSize,eyeSize*2);
  }

  void drawRocks(){
    //draw rocks
    fill(255);
    ellipse(x, y+(x/2), diam, diam);

    fill(255);
    ellipse(x+(3*x), y+(.5*x), diam, diam);

    fill (255);
    ellipse(x+(2*x), y+y, diam, diam);

    fill(255);
    ellipse(x+y, y+y, diam, diam);
  }

  void drawWall(){
    // draw the wall 
  stroke(0);
    fill(f, w, f, a);
  rect(x+(1.5*x), (y-(.05*z)), dim, diam);
  }

  void drawBeam(int startX, int startY, int endX, int endY) {
    float laserX, laserY, laserDX, laserDY;
    stroke(156, 255, 0);
    strokeWeight(5);
    float distance = dist(endX, endY, startX, startY);
  }
  }
}
{

// expand the reach of the beam about 1 pixel per loop iteration
// so it doesn't skip over anything

laserDX = (endX-startX)/distance;
laserDY = (endY-startY)/distance;

// make sure both laserDX and laserDY aren't zero or the loop will never end
if (laserDX == 0 &amp;&amp; laserDY == 0) {
  return; // don't draw anything
}

// lx,ly track where the beam will end
float lx = startX; 
float ly = startY;

// move along in the direction of the beam until you hit the edge or an object
while (get((int)lx, (int)ly) != rockColor &amp;&amp; lx &gt; 0 &amp;&amp; lx &lt; width &amp;&amp; ly &gt; 0 &amp;&amp; ly &lt; height) {
  lx = lx + laserDX;
  ly = ly + laserDY;
}
// found the end of the laser beam - draw it
line(startX, startY, lx, ly);
}
</code></pre>

<p>For some reason this comes up as an error. I don't know why the functions aren't working and I also don't know how to declare the laser and whatnot.  I have to do more with this code but right now I'm just trying to clean up what I have because I know this is the basic outline of what I have to do.</p>