Advertisement
Guest User

Untitled

a guest
May 25th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1.  
  2. //TYGAME
  3. myObject[] objs = new myObject[6];
  4.  
  5.  
  6. float dx1, dy1, grav;
  7. float a, b;
  8. int size1, sizey1, size2 = 65, size3 = 175, count = 3, counter;
  9. PImage ty, boom, tyty, lob;
  10. PImage tyler, catimg, burgerimg, jbimg, lettuceimg;
  11. PVector location1;
  12. float theDist;
  13. int m;
  14. int diam = 75;
  15.  
  16. //state machine
  17. boolean showInstructions = true;
  18. boolean playing = false;
  19. boolean ended = false;
  20.  
  21. void setup() {
  22. background(#FAABED);
  23. size(800, 600);
  24.  
  25. //defining properties of various objects within the class myObject's array
  26. objs[0] = new myObject(loadImage("cat.png"), 50, 80, diam, 3, 5, "cat" );
  27. objs[1] = new myObject(loadImage("jb.png"), 70, 80, diam, 6, 7, "jb" );
  28. objs[2] = new myObject(loadImage("burger.png"), 90, 80, diam, 3, 8, "burger" );
  29. objs[3] = new myObject(loadImage("lettuce.png"), 200, 90, diam, 4.5, 4, "lettuce");
  30. objs[4] = new myObject(loadImage("donut.png"), 800, 100, diam, 3.2, 3.7, "donut") ;
  31. objs[5] = new myObject(loadImage("ty-bird.png"), 350, 250, diam, 2, 2, "tyty");
  32.  
  33. //setting values
  34. ty = loadImage("Tyler face center.png");
  35. boom = loadImage("boom.png");
  36. tyty = loadImage("ty-bird.png");
  37. lob = loadImage("lobsta.png");
  38. location1 = new PVector(350, 250);
  39. size1 = 80;
  40. sizey1 = 100;
  41. a = 100;
  42. b = 100;
  43. dx1 = 4;
  44. dy1 = 9;
  45. grav = .9;
  46. m = millis();
  47. }
  48.  
  49.  
  50. void draw() {
  51. if (showInstructions) {
  52. background(#FAABED);
  53. println("show");
  54. //initial screen, instructions and introduction
  55. textSize(30);
  56. text("keep objects away from tyler's face!", 130, 100);
  57. text("click objects with lobster to protect him", 105, 150);
  58. text("press s to start", 310, 500);
  59. image(ty, 350, 250);
  60. } else if (playing) {
  61. background(#FAABED);
  62. image(ty, location1.x, location1.y);
  63.  
  64. //lobster shield
  65. cursor(lob);
  66. lob.resize(120, 120);
  67.  
  68. //health tracker
  69. text(count, 30, 30);
  70.  
  71. //score keeper
  72. m = counter++;
  73. text(counter, 700, 40);
  74.  
  75.  
  76. //implementing class into live game
  77. for (int i = 0; i < 5; i++) {
  78. objs[i].update();
  79. objs[i].display();
  80. }
  81. if (count <= 0 ) {
  82. playing = false;
  83. ended = true;
  84. }
  85. } else if (ended) {
  86.  
  87. //develop losing scenario
  88. playing = false;
  89. background(#FAABED);
  90. text("fin.", 400, 550);
  91. image(ty, 350, 250);
  92. text("winning capabilities = " + m, 350, 40);
  93.  
  94. //restart button properties
  95. image(tyty, a, b);
  96. tyty.resize(150, 150);
  97. a = a + dx1;
  98. b = b + dy1;
  99. dy1 = dy1 + grav;
  100.  
  101. //buttons restraints
  102. if (a > (width+diam)) {
  103. a = 0-diam;
  104. }
  105. if (a < (0-diam)) {
  106. dx1 = -dx1;
  107. }
  108. if ((b > (height-diam)) ||(b < (0+diam))) {
  109. dy1 = -dy1+grav;
  110. }
  111. //click function
  112. if (dist(mouseX, mouseY, a, b) < 50) {
  113. background(#FAABED);
  114. counter = 0;
  115. count = 3;
  116. ended = false;
  117. showInstructions = true;
  118. }
  119.  
  120. //end-game instructions
  121. text("catch tyBird to start again loser", 185, 100);
  122. }
  123. }
  124.  
  125.  
  126.  
  127.  
  128. void mousePressed() {
  129.  
  130. //game's challenge
  131. for (int i = 0; i < objs.length; i++) {
  132. if (mouseX >= objs[i].x - size2 && mouseX <= objs[i].x+size2 && mouseY >= objs[i].y-size2 && mouseY <= objs[i].y + size2) {
  133. objs[i].dx *= -1;
  134. objs[i].dy *= -1;
  135. }
  136. }
  137. }
  138.  
  139.  
  140. //To avoid inherited properties, implemented class to enable idiosyncratic values among objects
  141.  
  142. class myObject {
  143. //PVector location;
  144. float x, y;
  145. PImage img;
  146. float dx, dy;
  147. boolean hova;
  148. String myName;
  149. int diam;
  150.  
  151. myObject(PImage _img, float _x, float _y, int _diam, float _dx, float _dy, String _myName) {
  152. x = _x;
  153. y = _y;
  154. diam = _diam;
  155. dx = _dx;
  156. dy = _dy;
  157. img = _img;
  158. myName = _myName;
  159. }
  160.  
  161.  
  162. void update() {
  163. x = x + dx;
  164. y = y + dy;
  165. if (((y+.5*diam) > height) || ((y+.5*diam) < 0) ) {
  166. dy = -dy;
  167. }
  168. if (((x+.5*diam) > width) || ((x+.5*diam) < 0) ) {
  169. dx = -dx;
  170. }
  171.  
  172. if (m>30) {
  173. dx = dx++;
  174. dy = dy++;
  175. }
  176.  
  177. theDist = dist(x, y, location1.x, location1.y);
  178. if (theDist < (size2/2 + size1/2)) {
  179. count--;
  180. image(boom, 150, 40);
  181. dy=-dy;
  182. dx=-dx;
  183. }
  184. }
  185.  
  186.  
  187. void display() {
  188. fill(250);
  189. image(img, x, y, size2, size2);
  190. }
  191.  
  192.  
  193. }
  194.  
  195.  
  196. void keyPressed() {
  197. if (key == 's' || key == 'S') {
  198. println("s is pressed");
  199.  
  200. showInstructions = false;
  201. playing = true;
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement