Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. PImage backgroundImage;
  2. PImage playerImage;
  3. PImage tanniImage;
  4. float tanniY;
  5. float tanniX;
  6. int score;
  7. int state;
  8.  
  9. void setup() {
  10. size(1280, 720, P2D);
  11. backgroundImage = loadImage("school.jpg");
  12. backgroundImage.resize(width, height);
  13. playerImage = loadImage("chimpanzee.png");
  14. playerImage.resize(200, 200);
  15. tanniImage = loadImage("tanni.png");
  16. tanniImage.resize(100, 100);
  17. imageMode(CENTER);
  18. tanniY = -50;
  19. tanniX = random(50, width - 50);
  20. fill(0);
  21. score = 0;
  22. state = 0;
  23. }
  24.  
  25. void draw() {
  26. background(backgroundImage);
  27. switch(state) {
  28. case 0:
  29. titleScene();
  30. break;
  31. case 1:
  32. gameScene();
  33. break;
  34. case 2:
  35. resultScene();
  36. break;
  37. }
  38. }
  39.  
  40. void resetTanni() {
  41. tanniY = -50;
  42. tanniX = random(50, width - 50);
  43. }
  44.  
  45. void titleScene() {
  46. textSize(70);
  47. textAlign(CENTER, CENTER);
  48. text("Title Scene", width / 2, height / 2);
  49. textSize(30);
  50. text("ENTER to Start", width / 2, height / 2 + 80);
  51. if (keyCode == ENTER) {
  52. state = 1;
  53. }
  54. }
  55.  
  56. void gameScene() {
  57. textSize(50);
  58. textAlign(RIGHT, TOP);
  59. tanniY += 8;
  60. image(playerImage, mouseX, 520);
  61. tanniY += 8;
  62. image(tanniImage, tanniX, tanniY);
  63. if (height < tanniY - 50) {
  64. resetTanni();
  65. }
  66. if (dist(mouseX, 520, tanniX, tanniY) < 80) {
  67. resetTanni();
  68. score++;
  69. }
  70. text("score: " + score, width, 0);
  71. if (10 <= score) {
  72. state = 2;
  73. }
  74. }
  75.  
  76. void resultScene() {
  77. textSize(70);
  78. textAlign(CENTER, CENTER);
  79. text("Result Scene", width / 2, height / 2);
  80. textSize(30);
  81. text("ENTER to play again / ESC to exit", width / 2, height / 2 + 80);
  82. if (keyCode == ENTER) {
  83. score = 0;
  84. state = 0;
  85. } else if (keyCode == ESC) {
  86. exit();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement