Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. int canvasWidth = 320;
  2. int canvasHeight = 480;
  3. boolean onScreen = false;
  4. int foodX;
  5. int foodY;
  6. int obstacleX;
  7. int obstacleY;
  8. int obstacleHeight;
  9. int obstacleWidth;
  10. int score = 0;
  11.  
  12. void setup() {
  13. size(320, 480);
  14. textSize(32);
  15. }
  16.  
  17. void draw() {
  18. if (!onScreen) {
  19. foodY = int(random(canvasHeight));
  20. foodX = int(random(canvasWidth));
  21. obstacleX = int(random(canvasHeight));
  22. obstacleY = int(random(canvasWidth));
  23. obstacleHeight = int(random(canvasHeight));
  24. obstacleWidth = int(random(canvasWidth));
  25. onScreen = true;
  26. }
  27.  
  28. if (mouseX > obstacleX & mouseX < (obstacleX + obstacleWidth) & mouseY > obstacleY & mouseY < (obstacleY + obstacleHeight)) {
  29. score--;
  30. onScreen = false;
  31. }
  32.  
  33. background(204);
  34. text(("Score: " + str(score)), 10, 30);
  35. color c = color(255, 0, 0);
  36. fill(c);
  37. noStroke();
  38. rect(obstacleX, obstacleY, obstacleHeight, obstacleWidth);
  39. color d = color(255, 255, 255);
  40. fill(d);
  41. noStroke();
  42. rect(foodX, foodY, 10, 10);
  43. }
  44.  
  45. void mouseClicked() {
  46. if (mouseX > foodX & mouseX < (foodX + 10) & mouseY > foodY & mouseY < (foodY + 10)) {
  47. score++;
  48. onScreen = false;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement