【发布时间】:2016-08-08 21:13:35
【问题描述】:
我有以下代码可以让我的玩家移动:
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);
}
}
当我按下 w 键时,玩家会朝鼠标的方向移动。但是如果我按下 shift 键,我想让玩家移动得更快。但是现在当我按下 shift 键时,我的播放器停止移动……为什么会这样??欢迎任何帮助我解决此问题的建议:)
【问题讨论】:
-
您的代码中的
keyPressed和SHIFT是什么?在您看来,key == 'w' && key == SHIFT怎么可能是真的? -
this question 可以帮到你
-
尝试在
location.x = loca...之前移动if (key == SHIFT) { ... } -
不行还是不行...
标签: java processing game-physics