Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import java.awt.Rectangle;
  2. // Breakout // // 28/02/2007
  3. // Steph Thirion - Game Mod workshop: < http://trsp.net/teaching/gamemod >
  4. //
  5. // english version :)
  6. // made with Processing 0124 Beta
  7.  
  8.  
  9. Rectangle gameFrame;
  10. Brick[] bricks;
  11. Paddle paddle (x,y);
  12. Ball[] balls;
  13. Paddle block;}
  14.  
  15. //
  16. //
  17. int frameNum = 0;
  18. //
  19. // SCREEN PROPERTIES --
  20. int displayWidth = 400;
  21. int displayHeight = 400;
  22. color backgroundColor = #303030;
  23. boolean backgroundRefreshes = false;
  24. //
  25. // GAME FRAME PROPERTIES --
  26. int gameFrameWidth = 300;
  27. int gameFrameHeight = 300;
  28. color gameFrameStroke = #FFFFFF;
  29. boolean gameFrameHasStroke = false;
  30. color gameFrameFill = #000000;
  31. int opacityOfRefresh = 255;
  32. boolean gameFrameRefreshes = true;
  33. //
  34. //
  35. int recX = (displayWidth-gameFrameWidth)/2;
  36. int recY = (displayHeight-gameFrameHeight)/2;
  37. //
  38.  
  39.  
  40.  
  41.  
  42. // SETUP FUNCTION --
  43. void setup() {
  44. size(displayWidth, displayHeight, P3D);
  45. background(backgroundColor);
  46. frameRate(60);
  47. //
  48. // create objects
  49. gameFrame = new Rectangle(gameFrameWidth, gameFrameHeight, gameFrameHasStroke, gameFrameStroke, true, gameFrameFill);
  50. gameFrame.opacity = opacityOfRefresh;
  51. createBricks();
  52. createBalls();
  53. paddle = new Paddle(60,100);
  54. block = new Paddle(100,200);
  55.  
  56. //
  57. refreshScreen();
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. // DRAW FUNCTION --
  65. void draw() {
  66. refreshScreen();
  67. //
  68. //
  69. //
  70. saveScreenshots();
  71.  
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. void createBalls() {
  83. // BALL(S) PROPERTIES --
  84. int numberOfBalls = 1;
  85. int yBalls = 150;
  86. //
  87. balls = new Ball[numberOfBalls];
  88. for (int i=0; i<numberOfBalls; i++) {
  89. int x = i*20;
  90. balls[i] = new Ball(x, yBalls);
  91. }
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98. void createBricks() {
  99. // BRICK GROUP PROPERTIES --
  100. int numberOfBricks = 60;
  101. int bricksPerRow = 10;
  102. int brickWidth = gameFrameWidth/bricksPerRow;
  103. int brickHeight = 10;
  104. boolean brickHasStroke = false;
  105. color brickStroke = #ffffff;
  106. boolean brickHasFill = true;
  107.  
  108. int yBricks = 50;
  109. color[] rowsColors = {#ff00ff, #ff0000, #ff9900, #ffff00, #00ff00, #00ffff};
  110. //
  111. //
  112. // CREATE BRICKS --
  113. bricks = new Brick[numberOfBricks];
  114. for (int i=0; i<numberOfBricks; i++) {
  115. int rowNum = i/bricksPerRow;
  116. // coords
  117. int x = brickWidth*i;
  118. x -= rowNum*bricksPerRow*brickWidth;
  119. int y = yBricks+i/bricksPerRow*brickHeight;
  120. // color
  121. int num = min(rowNum, rowsColors.length-1);
  122. color rowColor = rowsColors[num];
  123. // create brick
  124. bricks[i] = new Brick(x, y, brickWidth, brickHeight, brickHasStroke, brickStroke, brickHasFill, rowColor);
  125. }
  126. }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. void refreshScreen() {
  135. // BACKGROUND
  136. if (backgroundRefreshes) {
  137. background(backgroundColor);
  138. }
  139. // GAME FRAME
  140. if (gameFrameRefreshes) {
  141. gameFrame.drawYourself();
  142. }
  143. // PADDLE
  144. paddle.refresh();
  145. block.refresh();
  146. //
  147. // BRICKS
  148. for (int i=0; i<=bricks.length-1; i++) {
  149. bricks[i].refresh();
  150. // println(i);
  151. }
  152. // BALLS
  153. for (int i=0; i<balls.length; i++) {
  154. balls[i].refresh();
  155. }
  156. }
  157.  
  158.  
  159.  
  160.  
  161. // be careful with this function - only change if you know what you're doing
  162. // the hard disk could fill up with images in a few minutes
  163. //
  164. //
  165. // press the 'G' key to save frames in TGA pictures in 'saved' folder
  166. //
  167. void saveScreenshots() {
  168. frameNum++;
  169. if (keyPressed) {
  170. if (key == 'g' || key == 'G') {
  171. if (frameNum%2==0) {
  172. saveFrame("saved/frame-####.tga");
  173. }
  174. }
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement