SHARE
TWEET

Untitled

a guest Sep 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float x = 200;
  2. float y = 200;
  3. float xSpeed = 2.5;
  4. float ySpeed = 1.5;
  5.  
  6. boolean leftPressed = false;
  7. boolean rightPressed = false;
  8. boolean upPressed = false;
  9. boolean downPressed = false;
  10.  
  11. void setup() {
  12.   size(400, 400);
  13. }
  14.  
  15. void draw() {
  16.   background(0);
  17.  
  18.   if (x > width - 25) {
  19.     x = width - 25;
  20.     xSpeed = -xSpeed;
  21.   }
  22.  
  23.   if (x < 25) {
  24.     x = 25;
  25.     xSpeed = -xSpeed;
  26.   }
  27.  
  28.   if (y > height - 25) {
  29.     y = height - 25;
  30.     ySpeed = -ySpeed;
  31.   }
  32.  
  33.   if (y < 25) {
  34.     y = 25;
  35.     ySpeed = -ySpeed;
  36.   }
  37.  
  38.   if (leftPressed) {
  39.     xSpeed = xSpeed - 0.1;
  40.   }
  41.   // Legg inn påvirkning fra andre taster som er holdt inne her
  42.  
  43.   x = x + xSpeed;
  44.   y = y + ySpeed;
  45.   ellipse(x, y, 50, 50);
  46. }
  47.  
  48. void keyPressed() {
  49.   if (keyCode == LEFT || key == 'a') {
  50.     leftPressed = true;
  51.   }
  52.   // Legg inn håndtering av at andre taster trykkes ned her
  53. }
  54.  
  55. void keyReleased() {
  56.   if (keyCode == LEFT || key == 'a') {
  57.     leftPressed = false;
  58.   }
  59.   // Legg inn håndtering av at andre taster slippes opp her
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top