Advertisement
MDell95

PongMPtxt

Sep 4th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 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/?50byk9d04yblqfg
  6.  
  7. //For more games and updates follow us on twitter: @d_codes_
  8.  
  9. int window_x=700, window_y=500;
  10.  
  11. int linelaenge=30, lineabstand=15;
  12. int liney;
  13. //Schiffe...
  14. int schiff1_h=90, schiff2_h=90, schiff1_b=15, schiff2_b=15;
  15. int xPos1=15, yPos1;
  16. int xPos2=window_x-xPos1-schiff2_b, yPos2;
  17. int seitenabstand=5;
  18. int geschw2; //ycheat;
  19. //instead of mouseY
  20. int keypos1=window_y/2;
  21. int keypos2=window_y/2;
  22. boolean[] keys;
  23. //Ball
  24. int r=10;
  25. int x=window_x/2, y=window_y/2;
  26. float yRichtung;
  27. float xRichtung;
  28. //Punkte
  29. int points1=0, points2=0;
  30. int errPunkte;
  31. boolean zehner;
  32.  
  33. void randomx()
  34. {
  35. float xspeed=random(-1,1);
  36. if (xspeed<=0)
  37. xRichtung=-1;
  38. else if (xspeed>0)
  39. xRichtung=1;
  40. }
  41.  
  42. void randomy()
  43. {
  44. float yspeed=random(-1,1);
  45. if (yspeed<=0)
  46. yRichtung=-1;
  47. else if (yspeed>0)
  48. yRichtung=1;
  49. }
  50.  
  51. PFont texts;
  52.  
  53. void setup()
  54. {
  55. texts=loadFont("schriftart.vlw");
  56. size(window_x, window_y);
  57. smooth();
  58. //noStroke();
  59. yPos1=((window_y/2)-(schiff1_h/2));
  60. yPos2=((window_y/2)-(schiff2_h/2));
  61. errPunkte=0;
  62. zehner=false;
  63. //to move both ships at the same time
  64. keys=new boolean[4];
  65. keys[0]=false;
  66. keys[1]=false;
  67. keys[2]=false;
  68. keys[3]=false;
  69. //ask();
  70.  
  71. randomx();
  72. randomy();
  73.  
  74. /*float ystartpos=random(window_y-r,r);
  75. y=int(ystartpos);*/
  76. }
  77.  
  78. void draw()
  79. {
  80. background(40);
  81. //Mittellinie...
  82. //fill(255,0,0);
  83. text(points1 +" : "+ points2, 339, 20, 10);
  84.  
  85. for(liney=30; liney <= window_y; liney+=linelaenge+lineabstand){
  86. line((window_x/2), liney, (window_x/2), liney+linelaenge);
  87. }
  88. //Schiff Spieler...
  89. if (keypos1>=seitenabstand+(schiff1_h/2) && keypos1<=(window_y-seitenabstand-schiff1_h/2))
  90. yPos1=keypos1-(schiff1_h/2);
  91. fill(255);
  92. rect(xPos1, yPos1, schiff1_b, schiff1_h);
  93.  
  94. if (keys[0])
  95. keypos1=keypos1-5;
  96. else if (keys[1])
  97. keypos1=keypos1+5;
  98.  
  99. //Schiff Computer...
  100. if (keypos2>=seitenabstand+(schiff1_h/2) && keypos2<=(window_y-seitenabstand-schiff1_h/2))
  101. yPos2=keypos2-(schiff1_h/2);
  102. fill(255);
  103. rect(xPos2, yPos2, schiff2_b, schiff2_h);
  104.  
  105. if (keys[2])
  106. keypos2=keypos2-5;
  107. else if (keys[3])
  108. keypos2=keypos2+5;
  109.  
  110. //println(yPos2);
  111. //Ball...
  112.  
  113. //Bewegung Ball:
  114. x+=xRichtung;
  115. y+=yRichtung;
  116. //Zeichnung
  117. fill(240);
  118. ellipse(x, y, r*2, r*2);
  119. //Kollision erkennen...
  120. //oben & unten
  121. if (y<=r || y>=(window_y-r))
  122. {
  123. yRichtung*=-1;
  124. if (yRichtung<0 && yRichtung>=-6)
  125. {
  126. yRichtung-=0.1;
  127. }
  128. else if (yRichtung>=0 && yRichtung<=6)
  129. {
  130. yRichtung+=0.1;
  131. }
  132. }
  133. //Kollision mit Schiff1
  134. if (x<=xPos1+schiff1_b+r && y>=yPos1-r/2 && y<=yPos1+schiff1_h+r/2) // Kollision an rechter Seite
  135. {
  136. xRichtung*=-1;
  137. if (xRichtung<=6)
  138. xRichtung+=0.3;
  139. }
  140. if ((y+r)>=yPos1-1 && (y+r)<=yPos1+1 && x>=xPos1-r && x<=(xPos1+schiff1_b+r/2)) //Kollision am oberen Rand
  141. yRichtung*=-1;
  142. //Kollision mit Schiff2
  143. if (x>=xPos2-r && y>=yPos2 && y<=yPos2+schiff1_h)
  144. {
  145. xRichtung*=-1;
  146. if (xRichtung>=-6)
  147. xRichtung-=0.1;
  148. }
  149.  
  150. /*if (upspeed<=5)
  151. xRichtung++;
  152. else if (upspeed*/
  153. //links
  154. if (x<-r)
  155. {
  156. points2++;
  157. delay(1000);
  158. //Nur vorläufig:
  159. //danach mit start bei gewinner
  160. x=window_x/2;
  161. y=window_y/2;
  162.  
  163. randomx();
  164. randomy();
  165. }
  166. //rechts
  167. if (x >= (window_x+r))
  168. {
  169. points1++;
  170. delay(1000);
  171. //Nur vorläufig:
  172. //danach mit start bei gewinner
  173. x=window_x/2;
  174. y=window_y/2;
  175.  
  176. randomx();
  177. randomy();
  178. }
  179.  
  180. println("speedx: " + xRichtung + " speedy: " + yRichtung);
  181. }
  182.  
  183. void keyPressed()
  184. {
  185. //TEST
  186. /*switch(key)
  187. {
  188. case 'q': y=r+1;
  189. break;
  190.  
  191. case 'a': y=window_y-r-1;
  192. break;
  193. //Anzahl punkte
  194. case '0':
  195. //errPunkte;
  196. break;
  197. case 't': yRichtung=1;
  198. xRichtung=-1;
  199. x=80; y=40;
  200. break;
  201. }*/
  202.  
  203. //to move both ships at the same time
  204.  
  205. if (key=='w')
  206. keys[0]=true;
  207.  
  208. if (key=='s')
  209. keys[1]=true;
  210.  
  211. if (key=='o')
  212. keys[2]=true;
  213.  
  214. if (key=='l')
  215. keys[3]=true;
  216.  
  217. }
  218.  
  219. //to move both ships at the same time
  220.  
  221. void keyReleased()
  222. {
  223. if (key=='w')
  224. keys[0]=false;
  225.  
  226. if (key=='s')
  227. keys[1]=false;
  228.  
  229. if (key=='o')
  230. keys[2]=false;
  231.  
  232. if (key=='l')
  233. keys[3]=false;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement