Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float x = 400, y=100;
- int a=20,b=10;
- void setup() { size(800, 200); }
- void draw() {
- rect(x-10, y-5, a, b);
- }
- void keyPressed() {
- int k=' ';
- if (keyCode == RIGHT) {
- x++;
- } else if (keyCode == LEFT) {
- x--;
- } else if (keyCode == UP){
- y--;
- } else if (keyCode == DOWN){
- y++;
- }
- }
- float x = 400, y = 100;
- int a = 20, b = 10;
- boolean isExtended = false;
- void setup() { size(800, 200); }
- void draw() {
- fill(255);
- rect(0, 0, 800, 200);
- rect(x - a / 2, y - b / 2, a, b);
- }
- void keyPressed() {
- if (keyCode == RIGHT) {
- x++;
- } else if (keyCode == LEFT) {
- x--;
- } else if (keyCode == UP){
- y--;
- } else if (keyCode == DOWN){
- y++;
- } else if (keyCode == ' ') {
- isExtended = !isExtended;
- a = isExtended ? 40 : 20;
- b = isExtended ? 20 : 10;
- }
- }
Add Comment
Please, Sign In to add comment