Hey all,
I am having some problems with changing the values with PVectors.
Here is my code:
Rocket rocket = new Rocket();
void keyPressed() {
switch(key) {
case 'w':
rocket.up();
case 's':
rocket.down();
case 'd':
rocket.right();
case 'a':
rocket.left();
}
}
void setup() {
size(800, 800);
}
void draw() {
background(0);
rocket.show();
rocket.updatePos();
}
And here is the rocket class:
class Rocket{
PVector pos = new PVector(100, 100);
PVector acc = new PVector(0, 0);
void show(){
fill(0, 255, 0);
ellipse(pos.x, pos.y, 8, 8);
}
void updatePos(){
pos = new PVector(pos.x + acc.x, pos.y + acc.y);
}
void up(){
acc.y--;
}
void down(){
acc.y++;
}
void right(){
acc.x++;
}
void left(){
acc.x--;
}
}
The rocket can move left and down just fine, but it can never move right or up. Any suggestions?