Java Processing 3을 사용하고 2 인용 탱크 게임을 만들고 있습니다. 아래는 포탑에 대한 내 코드입니다. 현재 나는 tDir에서 마우스를 따라 포탑을 목표로하고 있는데, 위아래 화살표를 사용하여 목표를 0도에서 90도까지 위 아래로 움직일 수 있기를 원했습니다.Java Processing 목적으로 화살표 키 사용
어떻게하면됩니까? 감사.
/*
Uzair
*/
PVector mPos; //mouse position
PVector tPos; //position of turret
PVector tDir; //the firing direction of the turret
int gravMult = 3;
void setup() {
size(1200, 600);
init();
}
void init() {
//PVector initializations
mPos = new PVector(); //zero til mouse x and y exist
tPos = new PVector(width/8, height);
tDir = new PVector(); //
}
void draw() {
//clear last frame
background(100,100,140);
//check keys to see if there is new key input for turret
if (keyPressed){
if (key == 'w'){
tDir.y -= 10;
}
else if (key == 's'){
tDir.y += 10;
}
}
mPos.set(mouseX, mouseY);
tDir = PVector.sub(mPos, tPos);
tDir.normalize();
tDir.mult(50);
//draw
fill(255);
ellipse(tPos.x, tPos.y, 40, 40);
strokeWeight(5);
line(tPos.x, tPos.y, tPos.x + tDir.x, tPos.y + tDir.y);
fill(255, 0, 0);
ellipse(tPos.x + tDir.x, tPos.y + tDir.y, 10, 10);
}
Java가 처리되지 않습니다. Processing-mode가 아닌 Java-mode로 될 사람들이 많으므로 Java에 대한 참조를 제거하도록 권장 할 것입니다. Java 관련 문제가 아니기 때문입니다. – Makoto