gedrückt habe ich den folgenden Code meine Spieler Schritt zu machen:machen Geschwindigkeit 5, wenn Shift-Taste
class Player {
PVector direction;
PVector location;
float rotation;
int speed;
Player() {
location = new PVector(width/2, height/2);
speed =2;
}
void visualPlayer() {
direction = new PVector(mouseX, mouseY);
rotation = atan2(direction.y - location.y, direction.x - location.x)/ PI * 180;
if (keyPressed) {
if ((key == 'w' && dist(location.x, location.y, direction.x, direction.y)>5) || (key == 'w' && key == SHIFT && dist(location.x, location.y, direction.x, direction.y)>5)) {
speed = 2;
location.x = location.x + cos(rotation/180*PI)*speed;
location.y = location.y + sin(rotation/180*PI)*speed;
if (key == SHIFT) {
speed = 5;
}
}
} else {
location.x = location.x;
location.y = location.y;
}
println(speed);
ellipse(location.x, location.y, 10, 10);
}
}
wenn ich die w-Taste der Spieler bewegt sich in Richtung der Maus drücken. aber ich möchte den Spieler schneller bewegen, wenn ich die Shift-Taste drücke. aber jetzt hört mein player auf sich zu bewegen, wenn ich die shift-taste drücke ... warum passiert das? Anregungen, mir zu helfen, dieses Problem zu beheben sind willkommen :)
Was sind 'keyPressed' und' SHIFT' in Ihrem Code? Wie könnte deiner Meinung nach dieser 'key == 'w' && key == SHIFT' wahr sein? – jhamon
[diese Frage] (http://stackoverflow.com/questions/14301775/get-key-combinations) könnte Ihnen helfen – jhamon
versuchen, verschieben 'if (key == SHIFT) {...} 'vor' location.x = loca ... ' –