ReflectingProjectiles/InputEvent.pde

47 lines
1010 B
Plaintext

void userMovement(char k, float hfo) {
// Move User 'basePosition'
float finalAngle = hfo;
switch (k) {
case 'a':
finalAngle -= HALF_PI;
break;
case 'd':
finalAngle += HALF_PI;
break;
case 's':
finalAngle += PI;
break;
}
if (finalAngle == hfo && k != 'w')
return;
PVector t = PVector.fromAngle(finalAngle);
t.setMag(USER_ACCELERATION_MAGNITUDE);
userVelocity.add(t);
userVelocity.limit(USER_TERMINAL_VELOCITY);
}
void mousePressed() {
// Move Wall Endpoints
if (mouseButton == LEFT) {
for (int i = 0; i < walls.size(); i++) {
Wall w = walls.get(i);
final float d1 = PVector.dist(w.start, mouse);
if (d1 <= PROJECTILE_RADIUS) {
dragIndex = i;
break;
}
final float d2 = PVector.dist(w.end, mouse);
if (d2 <= PROJECTILE_RADIUS) {
dragIndex = i;
dragType = true;
break;
}
}
}
}
void mouseReleased() {
dragIndex = -1;
dragType = false;
}