Unknown Syntax for Case/switch statement
in
Programming Questions
•
2 years ago
Full code_ (It's short)
final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result;
float x,y;
void setup() {
size(512,400);
frameRate(30);
result = 0;
x = width/2;
y = height/2;
}
void draw() {
background(0);
switch(result) {
case NORTH: y--; break;
case EAST: x++; break;
case SOUTH: y++; break;
case WEST: x--; break;
case NORTH|EAST: y--; x++; break;
case NORTH|WEST: y--; x--; break;
case SOUTH|EAST: y++; x++; break;
case SOUTH|WEST: y++; x--; break;
}
fill(255);
rect(x,y,10,10);
}
void keyPressed(){
switch(key) {
case('w'):case('W'):result |=NORTH;break;
case('d'):case('D'):result |=EAST;break;
case('s'):case('S'):result |=SOUTH;break;
case('a'):case('A'):result |=WEST;break;
}
}
void keyReleased(){
switch(key) {
case('w'):case('W'):result ^=NORTH;break;
case('d'):case('D'):result ^=EAST;break;
case('s'):case('S'):result ^=SOUTH;break;
case('a'):case('A'):result ^=WEST;break;
}
}
PLEASE, NOWHERE does that pipe "|" or whatever this is "^" show up in ANY resource I have ;(
also if anyone understands what this code is doing please, it was uncommented :p
final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result;
float x,y;
void setup() {
size(512,400);
frameRate(30);
result = 0;
x = width/2;
y = height/2;
}
void draw() {
background(0);
switch(result) {
case NORTH: y--; break;
case EAST: x++; break;
case SOUTH: y++; break;
case WEST: x--; break;
case NORTH|EAST: y--; x++; break;
case NORTH|WEST: y--; x--; break;
case SOUTH|EAST: y++; x++; break;
case SOUTH|WEST: y++; x--; break;
}
fill(255);
rect(x,y,10,10);
}
void keyPressed(){
switch(key) {
case('w'):case('W'):result |=NORTH;break;
case('d'):case('D'):result |=EAST;break;
case('s'):case('S'):result |=SOUTH;break;
case('a'):case('A'):result |=WEST;break;
}
}
void keyReleased(){
switch(key) {
case('w'):case('W'):result ^=NORTH;break;
case('d'):case('D'):result ^=EAST;break;
case('s'):case('S'):result ^=SOUTH;break;
case('a'):case('A'):result ^=WEST;break;
}
}
PLEASE, NOWHERE does that pipe "|" or whatever this is "^" show up in ANY resource I have ;(
also if anyone understands what this code is doing please, it was uncommented :p
1