Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. function setup() {
  2. createCanvas(800, 600);
  3. var entities = [player, obs1, obs2]
  4. var drawables = [player, obs1, obs2, clickedCircle, exit];
  5. var movables = [player, obs1, obs2];
  6. noStroke()
  7. }
  8.  
  9. function draw() {
  10. background(100);
  11. //Iterate through systems;
  12. for (var drawable of drawables) {
  13. drawable.drawCallback();
  14. }
  15. for (var movable of movables) {
  16. movable.moveCallback();
  17. }
  18. for (var entity of entities) {
  19. checkEdges(entity);
  20. }
  21.  
  22. checkForExit();
  23. }
  24.  
  25. var player = {
  26. rgb: [255,204,0],
  27. x: 50,
  28. y: 50,
  29. diameter: 25,
  30. drawCallback: function() {
  31. fill.apply(null,player.rgb);
  32. circle(player.x, player.y, player.diameter);
  33. },
  34. moveCallback: function() {
  35. if (keyIsDown(83)) {
  36. player.y += 10;
  37. }
  38. else if (keyIsDown(87)) {
  39. player.y -= 10;
  40. }
  41. if (keyIsDown(65)) {
  42. player.x -= 10;
  43. }
  44. else if (keyIsDown(68)) {
  45. player.x += 10;
  46. }
  47. }
  48. }
  49.  
  50. var obs1 = {
  51. rgb: [165,33,233],
  52. x: 83,
  53. y: 76,
  54. size: 62,
  55. drawCallback: function () { fill.apply(null,this.rgb); circle(this.x, this.y, this.size) },
  56. moveCallback: function () {
  57. this.x = this.x + random(30);
  58. this.x = this.x - random(30);
  59. this.y = this.y + random(30);
  60. this.y = this.y - random(30);
  61. }
  62. }
  63.  
  64. var obs2 = {
  65. rgb: [65,42,233],
  66. x: 46,
  67. y: 98,
  68. size: 90,
  69. drawCallback: function () { fill.apply(null,this.rgb); square(this.x, this.y, this.size) },
  70. moveCallback: function () {
  71. this.x = this.x + random(30);
  72. this.x = this.x - random(30);
  73. this.y = this.y + random(30);
  74. this.y = this.y - random(30);
  75. }
  76. }
  77.  
  78. function checkEdges(entity) {
  79. if (entity.x > 800) {
  80. entity.x = entity.x - 800;
  81. } else if (entity.x < 0) {
  82. entity.x = entity.x + 800;
  83. }
  84. if (entity.y > 600) {
  85. entity.y = entity.y - 600;
  86. } else if (entity.y < 0) {
  87. entity.y = entity.y + 600;
  88. }
  89. }
  90. var clickedCircle = {
  91. x: 0,
  92. y: 0,
  93. drawCallback: function() { fill(50,86,10);circle(this.x, this.y, 30) }
  94. }
  95.  
  96. function mousePressed() {
  97. clickedCircle.x = mouseX;
  98. clickedCircle.y = mouseY;
  99. }
  100.  
  101. var exit = {
  102. x1: 750,
  103. y1: 550,
  104. x2: 800,
  105. y2: 600,
  106. drawCallback: function () {
  107. fill(255, 0, 0)
  108. rect(exit.x1, exit.y1, 50, 50)
  109. fill(0, 0, 0)
  110. textSize(12)
  111. text('Exit', 765, 580)
  112. }
  113. }
  114. function checkForExit() {
  115. if (player.x < exit.x2 && player.x > exit.x1 && player.y < exit.y2 && player.y > exit.y1) {
  116. fill(255, 0, 0);
  117. rect(0, 0, 800, 600);
  118. fill(0, 0, 0);
  119. textSize(72);
  120. text('YOU WIN!', 200, 300);
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement