Advertisement
MDell95

Breakouttxt

Jul 20th, 2011
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. //ATTENTION: this code is written in PROCESSING
  2.  
  3. //ATTENTION: THIS IS JUST THE SOURCE CODE AND IT WON'T WORK WITHOUT THE RELEVANT FILES.
  4. // FOR THE FULL, PLAYABLE GAME PLEASE DOWNLOAD:
  5. // http://www.mediafire.com/?ofxbyuqg1er7asf
  6.  
  7. //program almost complete, little updates could follow!!
  8.  
  9. //follow us on twitter: @d_codes_
  10.  
  11. int window_x, window_y=400;
  12. int schiff_x=100, schiff_y=20;
  13. int xPos, yPos;
  14. int xRichtung=2, yRichtung=2;
  15. int r=10, x, y;
  16. //Fuer Balken:
  17. int anz_x=8, anz_y=5;
  18. int px=0, py=10, abstand=5;
  19. int bbalken=90, hbalken=20;
  20. int [][] wall = new int[anz_x][anz_y];
  21. int xblockpos, yblockpos;
  22. int xlauf, ylauf;
  23. int festigkeit;
  24. int life=3;
  25. int hschiff=40;
  26. int schraeg=30;
  27. boolean gameOver;
  28.  
  29. PFont schrift;
  30.  
  31.  
  32. void setup() {
  33. schrift = loadFont("schriftartgo.vlw");
  34. window_x = anz_x*bbalken+px*2;
  35. size(window_x,window_y);
  36. yPos=window_y-hschiff-schiff_y;
  37. x = window_x/2;
  38. y = window_y/2;
  39. smooth();
  40. for (xblockpos=0; xblockpos<anz_x; xblockpos++)
  41. {
  42. for (yblockpos=0; yblockpos<anz_y; yblockpos++)
  43. {
  44. float rdmfestigkeit=random(1,5);
  45. festigkeit = int(rdmfestigkeit);
  46. wall[xblockpos][yblockpos]=festigkeit;
  47. //println(festigkeit);
  48. }
  49. }
  50. gameOver = false;
  51. life=3;
  52. }
  53.  
  54.  
  55.  
  56. //int altemouse = 0;
  57.  
  58. void draw() {
  59. fill (255);
  60. background(0);
  61. text("life: "+ life, 20, window_y-20, 10);
  62. text("speed (y): "+ yRichtung, 200, window_y-20, 10);
  63. text("speed (x): "+ xRichtung, 100, window_y-20, 10);
  64. if (mouseX>=px && mouseX<=(window_x-px-schiff_x))
  65. {
  66. //int dmouse;
  67. //int g;
  68. xPos=mouseX-schiff_x/2;
  69.  
  70. // schraeg an seite
  71. if (y==yPos-r && x>=xPos && x<=xPos+schraeg && xRichtung<=0)
  72. {
  73. yRichtung++;
  74. }
  75. if (y==yPos-r && x>=xPos && x<=xPos+schraeg && xRichtung>0)
  76. {
  77. yRichtung--;
  78. }
  79. if (y==yPos-r && x>=xPos+schiff_x-schraeg && x<=xPos+schiff_x && xRichtung<0)
  80. {
  81. yRichtung--;
  82. }
  83. if (y==yPos-r && x>=xPos+schiff_x-schraeg && x<=xPos+schiff_x && xRichtung>=0)
  84. {
  85. yRichtung++;
  86. }
  87. /*
  88. if ((y-r) >= yPos)
  89. {
  90. dmouse = xPos - altemouse;
  91. if (abs(dmouse) > 10){
  92. if (dmouse > 0)
  93. dmouse -=10;
  94. if (dmouse < 0)
  95. dmouse += 10;
  96. }
  97.  
  98. //weitere Ueberlegung notwendig
  99.  
  100. xRichtung = xRichtung +dmouse;
  101.  
  102.  
  103. println("x:"+xRichtung+" delta:"+dmouse+" Mouse: "+xPos);
  104. }
  105. altemouse = xPos;*/
  106. }
  107. rect(xPos, yPos, schiff_x, schiff_y);
  108. fill(0, 0, 255); //color down
  109. rect(xPos, yPos, schraeg, schiff_y);
  110. fill(0, 0, 255); //color down
  111. rect(xPos+schiff_x-schraeg, yPos, schraeg, schiff_y);
  112. fill(255);
  113. if (life>0)
  114. {
  115. ellipse(x,y,r*2,r*2);
  116. }
  117. x+=xRichtung;
  118. y+=yRichtung;
  119. if (y==r)
  120. yRichtung*=-1;
  121. if (y>=(window_y-hschiff-schiff_y-r) && (x>xPos && x<(xPos+schiff_x)))
  122. yRichtung*=-1;
  123. if (x>=(window_x-r) || x<=r)
  124. xRichtung*=-1;
  125. if ((x>=xPos && y>=yPos && y<=yPos+schiff_y) || (x<=xPos+schiff_x-r && y>=yPos && y<=yPos+schiff_y))
  126. xRichtung*=-1;
  127. if (y>window_y+r && life>0)
  128. {
  129. life--;
  130. delay(1000);
  131. x=window_x/2;
  132. y=window_y/2;
  133. }
  134. if (life==0)
  135. {
  136. text("GAME OVER", window_x-120, window_y-20, 10);
  137. text("Click the left mouse button", window_x/2, window_y/2, 10);
  138. gameOver = true;
  139. }
  140.  
  141. for(ylauf=0; ylauf<anz_y; ylauf++)
  142. {
  143. for(xlauf=0; xlauf<anz_x; xlauf++)
  144. {
  145. if (wall[xlauf][ylauf]==4)
  146. {
  147. fill(43, 93, 39);
  148. rect(px+xlauf*bbalken, py+ylauf*hbalken, bbalken, hbalken);
  149. }
  150. if (wall[xlauf][ylauf]==3)
  151. {
  152. fill(57, 139, 52);
  153. rect(px+xlauf*bbalken, py+ylauf*hbalken, bbalken, hbalken);
  154. }
  155. if (wall[xlauf][ylauf]==2)
  156. {
  157. fill(56, 175, 48);
  158. rect(px+xlauf*bbalken, py+ylauf*hbalken, bbalken, hbalken);
  159. }
  160. if (wall[xlauf][ylauf]==1)
  161. {
  162. fill(46, 224, 34);
  163. rect(px+xlauf*bbalken, py+ylauf*hbalken, bbalken, hbalken);
  164. }
  165. }
  166. }
  167. for (xlauf=0; xlauf<anz_x; xlauf++)
  168. {
  169. for (ylauf=0; ylauf<anz_y; ylauf++)
  170. {
  171.  
  172. if (y<=py+ylauf*hbalken+r+hbalken && y>=py+ylauf*hbalken-r)
  173. {
  174. if (x<=px+xlauf*bbalken+bbalken && x>=px+xlauf*bbalken)
  175. {
  176. if (wall[xlauf][ylauf]>0)
  177. {
  178. wall[xlauf][ylauf]--;
  179. yRichtung*=-1;
  180. }
  181. }
  182. }
  183. }
  184. }
  185.  
  186.  
  187. }
  188.  
  189. void keyPressed ()
  190. {
  191. switch (key)
  192. {
  193. case '1': xRichtung=xRichtung/abs(xRichtung);
  194. yRichtung=yRichtung/abs(yRichtung);
  195. break;
  196. case '2': xRichtung=2*xRichtung/abs(xRichtung);
  197. yRichtung=2*yRichtung/abs(yRichtung);
  198. break;
  199.  
  200. case '3': xRichtung=3*xRichtung/abs(xRichtung);
  201. yRichtung=3*yRichtung/abs(yRichtung);
  202. break;
  203. case '4': xRichtung=4*xRichtung/abs(xRichtung);
  204. yRichtung=4*yRichtung/abs(yRichtung);
  205. break;
  206. case '5': xRichtung=5*xRichtung/abs(xRichtung);
  207. yRichtung=5*yRichtung/abs(yRichtung);
  208. break;
  209. case '6': xRichtung=6*xRichtung/abs(xRichtung);
  210. yRichtung=6*yRichtung/abs(yRichtung);
  211. break;
  212. case '7': xRichtung=7*xRichtung/abs(xRichtung);
  213. yRichtung=7*yRichtung/abs(yRichtung);
  214. break;
  215. case 'M': x=mouseX;
  216. y=mouseY;
  217. break;
  218. case '*': life++;
  219. break;
  220. case '+': life--;
  221. break;
  222. }
  223.  
  224. }
  225.  
  226. void mousePressed ()
  227. {
  228. if(gameOver==true)
  229. {
  230. setup();
  231. }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement