Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. float y;
  2. float x;
  3. float inc_x=1;
  4. float inc_y=1;
  5. float lim_x=0;
  6. float lim_y=0;
  7. int direcao_x=-1;
  8. int direcao_y=1;
  9. int pont=0;
  10. int tempo=0;
  11. int parar=0;
  12. int bolas=0;
  13. int contagem=0;
  14. int contagem1=61000;
  15. int pontmax=0;
  16. int comeco=1;
  17. int tempojogo=0;
  18. PImage img;
  19. int n=1;
  20.  
  21.  
  22. void setup() {
  23. size(800, 600);
  24. x = 100; // POSIÇÃO INICIAL DA BOLA
  25. y = 100;
  26.  
  27.  
  28. img = loadImage("fundo3.jpg");
  29. PFont font;
  30. font = createFont("font.vlw", 60);
  31. textFont(font, 60);
  32.  
  33. rectMode(CORNERS);
  34. textSize(20);
  35. textAlign(CENTER);
  36. }
  37.  
  38. void draw() {
  39.  
  40. tempo=millis(); // INICIAR O TEMPO COM O PROGRAMA A CORRER
  41.  
  42. inicio(); // DESENHA MENU INICIAL
  43.  
  44. if (comeco==0) {
  45.  
  46. background(img);
  47.  
  48. contagem=(contagem1-tempo)/1000; // CODIGO QUE CALCULA O TEMPO RESTANTE DE JOGO -> CONTAGEM1 -> DESTINO(TEMPO ACTUAL + 1 MINUTO) // TEMPO -> TEMPO ACTUAL DO PROGRAMA
  49.  
  50.  
  51. fill(255); // DESENHA INFORMAÇÕES
  52. textSize(14);
  53. text("CLOCK", 50, height-80);
  54. text(contagem, 50, height-50);
  55. text("MAXIMUM SCORE", width-100, 50);
  56. text(pontmax, width-100, 80);
  57. fill(10);
  58. textSize(12);
  59.  
  60.  
  61. if (direcao_x==-1 && inc_x>0) { // RESOLUÇÃO PARA MOVIMENTO FUNCIONAR BEM::: TECLAS FAZEM SEMPRE O SUPOSTO
  62. inc_x=-inc_x;
  63. }
  64. if (direcao_x==1 && inc_x<0) {
  65. inc_x=-inc_x;
  66. }
  67. if (direcao_y==-1 && inc_y>0) {
  68. inc_y=-inc_y;
  69. }
  70. if (direcao_y==1 && inc_y<0) {
  71. inc_y=-inc_y;
  72. }
  73.  
  74. float lim_x=abs(constrain(inc_x, -9, 9)); // MUDAR VELOCIDADE MAXIMA E MINIMA EM X
  75. float lim_y=abs(constrain(inc_y, -9, 9)); // MUDAR VELOCIDADE MAXIMA E MINIMA EM Y
  76.  
  77. if (lim_x<9 && lim_x>-9) { // ESCREVE MAXIMO QUANDO ATINGE LIMITE
  78. text(abs(lim_x), width-30, height-50);
  79. }
  80. if ((lim_x==9) || (lim_x==-9)) {
  81. text("Max", width-30, height-50); // ABS() TORNA OS VALORES SEMPRE POSITIVOS E CONSTRAIN() LIMITA OS VALORES
  82. }
  83. if ((lim_y==9) || (lim_y==-9)) {
  84. text("Max", width-30, height-30);
  85. }
  86. if (lim_y<9 && lim_y>-9) {
  87. text(abs(lim_y), width-30, height-30);
  88. }
  89. noStroke();
  90. fill(#C4EA72);
  91. ellipse(x, y, 15, 15);
  92. x = x+(lim_x*direcao_x); // MOVIMENTO DA BOLA -> LIM_X E LIM_Y INCREMENTO AO MOVIMENTO COM AS TECLAS
  93. y = y+(lim_y*direcao_y);
  94.  
  95.  
  96. rectangulos(); // FUNÇÕES DE MOVIMENTO PONTUAÇÃO E DESENHO DOS RECTANGULOS
  97. movimento();
  98. pontuacao();
  99.  
  100. if (tempo>=contagem1-1000) { // MENU QUANDO O JOGO PARA
  101. parar=1;
  102. if (pont>pontmax) {
  103. pontmax=pont;
  104. }
  105. x=width/2;
  106. y=height/2;
  107. background(img);
  108. float x= random(800);
  109. float y= random(600);
  110.  
  111. if (x<width/2) {
  112. if (y<height/2)
  113. fill(219, 240, 206, 200);
  114. else fill(random(200),random(200), random(200));
  115. } else {
  116.  
  117. if (y<height/2)
  118. fill(random(255),random(255), random(255));
  119.  
  120. else fill(random(100),random(100), random(100));
  121. }
  122. ellipse(x-100, y-100, 20, 20);
  123.  
  124.  
  125. stroke(255);
  126. rect(800/2-60, 600/2+100, 800/2+60, 600/2+150);
  127. fill(255);
  128. textSize(20);
  129. text("NEW GAME", 800/2, 600/2+125);
  130. fill(255);
  131. text("END!", width/2, height/2-100);
  132. text("SCORE:", width/2, height/2-50);
  133. text(pont, width/2, height/2);
  134. textSize(14);
  135. text("MAXIMUM SCORE", width-100, height-100);
  136. text(pontmax, width-100, height-80);
  137.  
  138. println(contagem);
  139. }
  140. }
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147. void inicio() {
  148.  
  149. if (comeco==1) {
  150. background(img);
  151. stroke(255);
  152. strokeWeight(5);
  153. fill(#0C145F);
  154. ellipse(width/2, height/2+90, 100, 100);
  155. fill(255);
  156. strokeWeight(20);
  157. textSize(40);
  158. stroke(#0C145F);
  159. text("-Floating Point-", width/2, height/2-200);
  160. textSize(30);
  161. text("Start", width/2, height/2+100);
  162. }
  163. }
  164.  
  165. void mousePressed() {
  166.  
  167.  
  168.  
  169. if (mouseX<width/2+60 && mouseX>width/2-60) { // QUANDO O JOGO PARA
  170. if (mouseY<height/2+150 && mouseY>height/2+100) {
  171. if (parar==1) {
  172.  
  173.  
  174. inc_x=1;
  175. inc_y=1;
  176. pont=0;
  177. bolas=0;
  178. comeco=0;
  179. tempojogo=0;
  180. contagem1=60000+tempo;
  181. parar=0;
  182. }
  183. }
  184. }
  185.  
  186. if (mouseY<height/2+110 && mouseY>height/2+80) { // QUANDO O JOGO INICIA
  187.  
  188. if (mouseX>width/2-60 && mouseX<width/2+60) {
  189.  
  190. if (comeco==1) {
  191. tempojogo=0;
  192. contagem1=60000+tempo;
  193. comeco=0;
  194. parar=0;
  195. }
  196. }
  197. }
  198. }
  199.  
  200.  
  201. void pontuacao() {
  202.  
  203. if (x>=width-2-10) {
  204.  
  205. if (y>=30-7.5 && y<=80+7.5) {
  206. direcao_x=-1;
  207. pont=pont+6;
  208. } else if (y>=300-7.5 && y<=400+7.5) {
  209. direcao_x=-1;
  210. pont=pont+2;
  211. } else if (y>=500-7.5 && y<=550+7.5) {
  212. direcao_x=-1;
  213. pont=pont+5;
  214. }
  215. } else if (x<=2+8) {
  216.  
  217. if (y>=40-7.5 && y<=90+7.5) { // DAR LIMITE MAIOR AO RAIO DA BOLA
  218. direcao_x=1;
  219. pont=pont+5;
  220. } else if (y>=400-7.5 && y<=500+7.5) {
  221. direcao_x=1;
  222. pont=pont+4;
  223. }
  224. } else if (y>=height-2-8) {
  225.  
  226. if (x>=60-8 && x<=110+8) {
  227. direcao_y=-1;
  228. pont=pont+5;
  229. } else if (x>=300-8 && x<=400+8) {
  230. direcao_y=-1;
  231. pont=pont+2;
  232. } else if (x>=700-8 && x<=750+8) {
  233. direcao_y=-1;
  234. pont=pont+5;
  235. }
  236. } else if (y<=2+10) {
  237.  
  238. if (x>=200-7.5 && x<=250+7.5) {
  239. direcao_y=1;
  240. pont=pont+7;
  241. } else if (x>=470-7.5 && x<=570+7.5) {
  242. direcao_y=1;
  243. pont=pont+4;
  244. }
  245. }
  246.  
  247. textSize(40);
  248. fill(255);
  249. text(pont, width/2, height/2);
  250. }
  251.  
  252.  
  253.  
  254.  
  255.  
  256. void rectangulos() { // MUDAR TAMANHO RECTANGULOS PARA 100 OU 50 DE COMPRIMENTO
  257.  
  258. stroke(255);
  259. strokeWeight(1);
  260. fill(#C4EA72);
  261. rect(60, 0, 110, 2);
  262. fill(100, 130, 50);
  263. rect(570, 0, 470, 2);
  264. fill(200, 130, 50);
  265. rect(width-2, 30, width, 80);
  266. fill(100, 130, 50);
  267. rect(width-2, 300, width, 400);
  268. fill(50, 130, 50);
  269. rect(width-2, 500, width, 550);
  270. fill(200, 130, 50);
  271. rect(10, height-2, 60, height);
  272. fill(50, 130, 50);
  273. rect(300, height-2, 400, height);
  274. fill(120, 255, 200);
  275. rect(700, height-2, 750, height);
  276. fill(200, 130, 50);
  277. rect(0, 40, 2, 90);
  278. fill(100, 130, 50);
  279. rect(0, 400, 2, 500);
  280. }
  281.  
  282.  
  283. void movimento() {
  284.  
  285.  
  286.  
  287. if (x>width-7.5) {
  288. direcao_x=-1;
  289. }
  290. if (x<0+7.5) {
  291. direcao_x=1;
  292. }
  293.  
  294. if (y>height-7.5) {
  295. direcao_y=-1;
  296. }
  297. if (y<0+7.5) {
  298. direcao_y=1;
  299. }
  300. }
  301.  
  302.  
  303. void keyPressed() {
  304.  
  305. if (keyCode == LEFT) {
  306.  
  307. inc_x=inc_x-2;
  308. }
  309.  
  310. if (keyCode == DOWN) {
  311.  
  312. inc_y=inc_y+2;
  313. }
  314.  
  315. if (keyCode == RIGHT) {
  316.  
  317. inc_x=inc_x+2;
  318. }
  319.  
  320. if (keyCode == UP) {
  321.  
  322. inc_y=inc_y-2;
  323. }
  324.  
  325. if (inc_x<0) {
  326. direcao_x=-1;
  327. }
  328. if (inc_x>0) {
  329. direcao_x=1;
  330. }
  331.  
  332. if (inc_y<0) {
  333. direcao_y=-1;
  334. }
  335. if (inc_y>0) {
  336. direcao_y=1;
  337. }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement