Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float y;
- float x;
- float inc_x=1;
- float inc_y=1;
- float lim_x=0;
- float lim_y=0;
- int direcao_x=-1;
- int direcao_y=1;
- int pont=0;
- int tempo=0;
- int parar=0;
- int bolas=0;
- int contagem=0;
- int contagem1=61000;
- int pontmax=0;
- int comeco=1;
- int tempojogo=0;
- PImage img;
- int n=1;
- void setup() {
- size(800, 600);
- x = 100; // POSIÇÃO INICIAL DA BOLA
- y = 100;
- img = loadImage("fundo3.jpg");
- PFont font;
- font = createFont("font.vlw", 60);
- textFont(font, 60);
- rectMode(CORNERS);
- textSize(20);
- textAlign(CENTER);
- }
- void draw() {
- tempo=millis(); // INICIAR O TEMPO COM O PROGRAMA A CORRER
- inicio(); // DESENHA MENU INICIAL
- if (comeco==0) {
- background(img);
- contagem=(contagem1-tempo)/1000; // CODIGO QUE CALCULA O TEMPO RESTANTE DE JOGO -> CONTAGEM1 -> DESTINO(TEMPO ACTUAL + 1 MINUTO) // TEMPO -> TEMPO ACTUAL DO PROGRAMA
- fill(255); // DESENHA INFORMAÇÕES
- textSize(14);
- text("CLOCK", 50, height-80);
- text(contagem, 50, height-50);
- text("MAXIMUM SCORE", width-100, 50);
- text(pontmax, width-100, 80);
- fill(10);
- textSize(12);
- if (direcao_x==-1 && inc_x>0) { // RESOLUÇÃO PARA MOVIMENTO FUNCIONAR BEM::: TECLAS FAZEM SEMPRE O SUPOSTO
- inc_x=-inc_x;
- }
- if (direcao_x==1 && inc_x<0) {
- inc_x=-inc_x;
- }
- if (direcao_y==-1 && inc_y>0) {
- inc_y=-inc_y;
- }
- if (direcao_y==1 && inc_y<0) {
- inc_y=-inc_y;
- }
- float lim_x=abs(constrain(inc_x, -9, 9)); // MUDAR VELOCIDADE MAXIMA E MINIMA EM X
- float lim_y=abs(constrain(inc_y, -9, 9)); // MUDAR VELOCIDADE MAXIMA E MINIMA EM Y
- if (lim_x<9 && lim_x>-9) { // ESCREVE MAXIMO QUANDO ATINGE LIMITE
- text(abs(lim_x), width-30, height-50);
- }
- if ((lim_x==9) || (lim_x==-9)) {
- text("Max", width-30, height-50); // ABS() TORNA OS VALORES SEMPRE POSITIVOS E CONSTRAIN() LIMITA OS VALORES
- }
- if ((lim_y==9) || (lim_y==-9)) {
- text("Max", width-30, height-30);
- }
- if (lim_y<9 && lim_y>-9) {
- text(abs(lim_y), width-30, height-30);
- }
- noStroke();
- fill(#C4EA72);
- ellipse(x, y, 15, 15);
- x = x+(lim_x*direcao_x); // MOVIMENTO DA BOLA -> LIM_X E LIM_Y INCREMENTO AO MOVIMENTO COM AS TECLAS
- y = y+(lim_y*direcao_y);
- rectangulos(); // FUNÇÕES DE MOVIMENTO PONTUAÇÃO E DESENHO DOS RECTANGULOS
- movimento();
- pontuacao();
- if (tempo>=contagem1-1000) { // MENU QUANDO O JOGO PARA
- parar=1;
- if (pont>pontmax) {
- pontmax=pont;
- }
- x=width/2;
- y=height/2;
- background(img);
- float x= random(800);
- float y= random(600);
- if (x<width/2) {
- if (y<height/2)
- fill(219, 240, 206, 200);
- else fill(random(200),random(200), random(200));
- } else {
- if (y<height/2)
- fill(random(255),random(255), random(255));
- else fill(random(100),random(100), random(100));
- }
- ellipse(x-100, y-100, 20, 20);
- stroke(255);
- rect(800/2-60, 600/2+100, 800/2+60, 600/2+150);
- fill(255);
- textSize(20);
- text("NEW GAME", 800/2, 600/2+125);
- fill(255);
- text("END!", width/2, height/2-100);
- text("SCORE:", width/2, height/2-50);
- text(pont, width/2, height/2);
- textSize(14);
- text("MAXIMUM SCORE", width-100, height-100);
- text(pontmax, width-100, height-80);
- println(contagem);
- }
- }
- }
- void inicio() {
- if (comeco==1) {
- background(img);
- stroke(255);
- strokeWeight(5);
- fill(#0C145F);
- ellipse(width/2, height/2+90, 100, 100);
- fill(255);
- strokeWeight(20);
- textSize(40);
- stroke(#0C145F);
- text("-Floating Point-", width/2, height/2-200);
- textSize(30);
- text("Start", width/2, height/2+100);
- }
- }
- void mousePressed() {
- if (mouseX<width/2+60 && mouseX>width/2-60) { // QUANDO O JOGO PARA
- if (mouseY<height/2+150 && mouseY>height/2+100) {
- if (parar==1) {
- inc_x=1;
- inc_y=1;
- pont=0;
- bolas=0;
- comeco=0;
- tempojogo=0;
- contagem1=60000+tempo;
- parar=0;
- }
- }
- }
- if (mouseY<height/2+110 && mouseY>height/2+80) { // QUANDO O JOGO INICIA
- if (mouseX>width/2-60 && mouseX<width/2+60) {
- if (comeco==1) {
- tempojogo=0;
- contagem1=60000+tempo;
- comeco=0;
- parar=0;
- }
- }
- }
- }
- void pontuacao() {
- if (x>=width-2-10) {
- if (y>=30-7.5 && y<=80+7.5) {
- direcao_x=-1;
- pont=pont+6;
- } else if (y>=300-7.5 && y<=400+7.5) {
- direcao_x=-1;
- pont=pont+2;
- } else if (y>=500-7.5 && y<=550+7.5) {
- direcao_x=-1;
- pont=pont+5;
- }
- } else if (x<=2+8) {
- if (y>=40-7.5 && y<=90+7.5) { // DAR LIMITE MAIOR AO RAIO DA BOLA
- direcao_x=1;
- pont=pont+5;
- } else if (y>=400-7.5 && y<=500+7.5) {
- direcao_x=1;
- pont=pont+4;
- }
- } else if (y>=height-2-8) {
- if (x>=60-8 && x<=110+8) {
- direcao_y=-1;
- pont=pont+5;
- } else if (x>=300-8 && x<=400+8) {
- direcao_y=-1;
- pont=pont+2;
- } else if (x>=700-8 && x<=750+8) {
- direcao_y=-1;
- pont=pont+5;
- }
- } else if (y<=2+10) {
- if (x>=200-7.5 && x<=250+7.5) {
- direcao_y=1;
- pont=pont+7;
- } else if (x>=470-7.5 && x<=570+7.5) {
- direcao_y=1;
- pont=pont+4;
- }
- }
- textSize(40);
- fill(255);
- text(pont, width/2, height/2);
- }
- void rectangulos() { // MUDAR TAMANHO RECTANGULOS PARA 100 OU 50 DE COMPRIMENTO
- stroke(255);
- strokeWeight(1);
- fill(#C4EA72);
- rect(60, 0, 110, 2);
- fill(100, 130, 50);
- rect(570, 0, 470, 2);
- fill(200, 130, 50);
- rect(width-2, 30, width, 80);
- fill(100, 130, 50);
- rect(width-2, 300, width, 400);
- fill(50, 130, 50);
- rect(width-2, 500, width, 550);
- fill(200, 130, 50);
- rect(10, height-2, 60, height);
- fill(50, 130, 50);
- rect(300, height-2, 400, height);
- fill(120, 255, 200);
- rect(700, height-2, 750, height);
- fill(200, 130, 50);
- rect(0, 40, 2, 90);
- fill(100, 130, 50);
- rect(0, 400, 2, 500);
- }
- void movimento() {
- if (x>width-7.5) {
- direcao_x=-1;
- }
- if (x<0+7.5) {
- direcao_x=1;
- }
- if (y>height-7.5) {
- direcao_y=-1;
- }
- if (y<0+7.5) {
- direcao_y=1;
- }
- }
- void keyPressed() {
- if (keyCode == LEFT) {
- inc_x=inc_x-2;
- }
- if (keyCode == DOWN) {
- inc_y=inc_y+2;
- }
- if (keyCode == RIGHT) {
- inc_x=inc_x+2;
- }
- if (keyCode == UP) {
- inc_y=inc_y-2;
- }
- if (inc_x<0) {
- direcao_x=-1;
- }
- if (inc_x>0) {
- direcao_x=1;
- }
- if (inc_y<0) {
- direcao_y=-1;
- }
- if (inc_y>0) {
- direcao_y=1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement