class Man{ Node n; int index, id; Ball ball; int life = 5; Vector zapPath; int [] power; Man(Node n, int id){ this.n = n; this.id = id; index = grid.nodes.indexOf(n); ball = new Ball(n); zapPath = new Vector(); power = new int[1]; power[0] = 48; } void draw(){ if(life > 0){ fill(colTable[id]); noStroke(); ellipse(n.x(), n.y(), gridScale, gridScale); if(power[0] > 0){ fill(0, 255, 255, 50); ellipse(n.x(), n.y(), gridScale + 5, gridScale + 5); power[0]--; } if(!ball.carried){ ball.draw(); } if(zapPath.size() > 0){ stroke(50, 50, 255); noFill(); strokeWeight(2); beginShape(); for(int i = 0; i < man.length; i++){ if(man[i].n != n){ if(zapPath.indexOf(man[i].n) > -1){ man[i].hit(); } } } for(int i = 0; i < zapPath.size(); i++){ Node z = (Node)zapPath.get(i); vertex(z.x() + random(-5, 5), z.y() + random(-5, 5)); } endShape(); } } } void hit(){ if(power[0] == 0){ power[0] = 48; life--; } } void zap(){ if(ball.carried){ ball.carried = false; } else { if(n == ball.n){ ball.carried = true; } else { zapPath = grid.getPath(n, ball.n); } } } void move(int x, int y){ int newIndex = index + x + y * gridWide; if(zapPath.size() > 0){ zapPath = new Vector(); } if(newIndex > -1 && newIndex < grid.nodes.size()){ Node dest = (Node)grid.nodes.get(newIndex); if(n.links.indexOf(dest) > -1){ n = dest; index = newIndex; if(ball.carried){ ball.n = n; } } } } class Ball{ Node n; boolean carried; Ball(Node n){ this.n = n; carried = true; } void draw(){ strokeWeight(1); stroke(0, 255, 255); fill(colTable[id]); ellipse(n.x(), n.y(), gridScale * 0.6, gridScale * 0.6); } } }