class Player { Particle p; float radius, speed, forceRadius; boolean up, right, down, left, suck, blow; // for keyboard control private boolean sucking, blowing; Player (Particle part, float r, float s) { p = part; p.makeFixed(); radius = r; forceRadius = r*6; speed = s; up = right = down = left = false; } void keyMove() { float moveAmt; if ( up ) { moveAmt = min(y() - 5, speed); p.moveBy(0, -moveAmt, 0); } if ( down ) { moveAmt = min(height - y() - 5, speed); p.moveBy(0, moveAmt, 0); } if ( left ) { moveAmt = min(x() - 5, speed); p.moveBy(-moveAmt, 0, 0); } if ( right ) { moveAmt = min(width - x() - 5, speed); p.moveBy(moveAmt, 0, 0); } } void move(float x, float y) { p.moveBy(x, y, 0); if ( x() < radius ) p.moveTo(radius, y(), 0); else if ( x() > width - radius ) p.moveTo(width - radius, y(), 0); if ( y() < radius ) p.moveTo(x(), radius, 0); else if ( y() > height - radius ) p.moveTo(x(), height - radius, 0); } void suck(boolean b) { sucking = b; } void keySuck() { suck(suck); } boolean isSucking() { return sucking; } void blow(boolean b) { blowing = b; } void keyBlow() { blow(blow); } boolean isBlowing() { return blowing; } boolean withinRange(Pulser puls) { return puls.distFrom(this) < forceRadius + puls.getRadius(); } void render() { if ( useSmooth ) smooth(); noStroke(); // suck waves if ( sucking ) { fill(255, 255, 0, 64); ellipse(x(), y(), forceRadius, forceRadius); } // blow waves if ( blowing ) { fill(0, 255, 0, 64); ellipse(x(), y(), forceRadius, forceRadius); } // the player fill(0, 0, 255); ellipse(x(), y(), radius, radius); } float x() { return p.position().x(); } float y() { return p.position().y(); } }