Skip to content

Instantly share code, notes, and snippets.

@stephkoltun
Created March 10, 2017 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephkoltun/82d57aeed53d7e3e1bf83b55fd80ebcb to your computer and use it in GitHub Desktop.
Save stephkoltun/82d57aeed53d7e3e1bf83b55fd80ebcb to your computer and use it in GitHub Desktop.
void adjustPlayer(Client thisClient, String message) {
// which player?
Paddle thisPlayer = new Paddle();
String clientID = thisClient.ip();
if (activeClients.size() == players.length) {
// determine with player client is associated with
for (int i = 0; i < players.length; i++) {
if (players[i].clientID.equals(clientID)) {
// player identified!
thisPlayer = players[i];
println("adjust player " + i);
}
}
switch (message) {
case "u":
if (thisPlayer.constMove == false) {
thisPlayer.y = thisPlayer.y - thisPlayer.increment;
} else {
thisPlayer.upSpeed = 1;
thisPlayer.dnSpeed = 0;
}
break;
case "d":
thisPlayer.y = thisPlayer.y + thisPlayer.increment;
if (thisPlayer.constMove == false) {
thisPlayer.y = thisPlayer.y + thisPlayer.increment;
} else {
thisPlayer.upSpeed = 0;
thisPlayer.dnSpeed = 1;
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment