Advertisement
Guest User

prototype

a guest
May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. int NumberofCars = 2;
  2. int score;
  3. float [] xCoord= new float[NumberofCars];
  4. float [] yCoord= new float[NumberofCars];
  5. float [] xMove= new float[NumberofCars];
  6. float [] yMove= new float[NumberofCars];
  7. int xFrog;
  8. int yFrog;
  9.  
  10.  
  11. void setup() {
  12. score = 0;
  13. size(500, 500);
  14. xCoord[0]=10;
  15. yCoord[1]=10;
  16. //position of frog
  17. xFrog = width/2;
  18. yFrog = height-20;
  19.  
  20. for (int i = 0; i < NumberofCars; i++) {
  21. xCoord[i]= random(width);
  22. yCoord[i]= i*250+50;
  23. xMove[i]=random(2, 4);
  24. }
  25.  
  26. }
  27.  
  28. void draw () {
  29. drawBackground();
  30. fill(26, 95, 26);
  31. ellipse(xFrog, yFrog, 20, 20);
  32. ellipse(xFrog-5, yFrog-9, 10, 10);
  33. ellipse(xFrog+5, yFrog-9, 10, 10);
  34. fill(0);
  35. ellipse(xFrog-5, yFrog-9, 3, 3);
  36. ellipse(xFrog+5, yFrog-9, 3, 3);
  37.  
  38. noStroke();
  39. noFill();
  40.  
  41. //draw the cars at their location
  42.  
  43. for (int i = 0; i < NumberofCars; i++) {
  44. fill(111, 169, 219);
  45. rect(xCoord[i], yCoord[i], 33, 16);
  46. fill(255, 0, 0);
  47. rect(xCoord[i]-16, yCoord[i]+16, 66, 26);
  48. fill(0);
  49. ellipse(xCoord[i], yCoord[i]+43, 16, 16);
  50. ellipse(xCoord[i]+33, yCoord[i]+43, 16, 16);
  51. //moves cars across screen
  52. xCoord[i]= xCoord[i] + xMove[i];
  53. noFill();
  54.  
  55. if (xCoord[i]>width) {
  56. xCoord[i]=0;
  57. }
  58. if (xCoord[i]<0) {
  59. xCoord[i]=width;
  60. }
  61. //hit test
  62. if (dist(xFrog, yFrog, xCoord[i], yCoord[i]) < 65) {
  63. setup();
  64. }
  65. }
  66. }
  67.  
  68.  
  69. void drawBackground() {
  70. background(170, 240, 70);
  71. text(score,10,10);
  72. //road
  73. fill(50, 50, 50);
  74. rect(0, 50, 500, 50);
  75. rect(0, 300, 500, 50);
  76.  
  77. //lines n shit
  78. fill(239, 247, 32);
  79. rect(0, 70, 40, 10);
  80. rect(200, 70, 50, 10);
  81. rect(400, 70, 50, 10);
  82. rect(500, 70, 50, 10);
  83. rect(50, 320, 50, 10);
  84. rect(250, 320, 50, 10);
  85. rect(450, 320, 50, 10);
  86.  
  87. //river
  88. fill(8, 79, 139);
  89. rect(0, 150, 500, 100);
  90.  
  91.  
  92. }
  93. //controlkeys
  94. void keyPressed(){
  95. if (key == 'w' || key == 'W'){
  96. yFrog -= 5;
  97. score += 1;
  98. }
  99. else if (key == 's' || key == 'S'){
  100. yFrog += 5;
  101. score += 1;
  102. }
  103. else if (key == 'a' || key == 'A'){
  104. xFrog -= 5;
  105. }
  106. else if (key == 'd' || key == 'D'){
  107. xFrog += 5;
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement