class Player { Particle p; float radius, speed, forceRadius; boolean up, right, down, left, suck, blow; // for keyboard control private boolean sucking, blowing; private int suckCnt, blowCnt; Player (Particle part, float r, float s) { p = part; p.makeFixed(); radius = r; forceRadius = r*8; speed = s; up = right = down = left = false; suckCnt = blowCnt = 0; } 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() - 5; } void render() { noFill(); stroke(255, 255, 0); // suck waves if ( sucking ) { float rad = forceRadius * cos((suckCnt%30)*PI/60); ellipse(x(), y(), rad, rad); suckCnt++; } else suckCnt = 0; // blow waves if ( blowing ) { float rad = forceRadius * sin((blowCnt%30)*PI/60); ellipse(x(), y(), rad, rad); blowCnt++; } else blowCnt = 0; // the player ellipse(x(), y(), radius, radius); } float x() { return p.position().x(); } float y() { return p.position().y(); } }