Commit 7c00b52f authored by Gabriel's avatar Gabriel
Browse files

Primeiro Commit - Ora Bolas! Processing 3 e Classes!

parents
Loading
Loading
Loading
Loading

Ora_Bolas.pde

0 → 100644
+31 −0
Changes for Ora_Bolas.pde: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
int wow = 300;
PImage img;
Personagem[] fulanos = new Personagem[wow]; 

void iniciarSistema() {
  for (int i = 0; i < wow; i++) {
    fulanos[i] = new Personagem(100,width/2,height/2);
    fulanos[i].imagem = img;
  }
}

void setup() { 
  size(600,600); 
  img = loadImage("box.png");
  img.resize(40, 40);  
  iniciarSistema();
}
void draw() { 

  //clear();
  background(80);

  for (int i = 0; i < wow; i++) {
    fulanos[i].meDesenhe();
  }
  
}

void mouseClicked() {
  iniciarSistema();
}
 No newline at end of file

Personagem.pde

0 → 100644
+52 −0
Changes for Personagem.pde: 52 added lines, 0 removed lines.
Original line number Diff line number Diff line
class Personagem {
  int vida, x, y, velocidade, opiniao = 100;
  float dX, dY, r,g,b, ang;
  PImage imagem;
  
  Personagem(int v, int posx, int posy) {
    initBase();
    vida = v;
    x = posx; y = posy;    
  }
  
  Personagem(int v) {
    initBase();
    vida = v;
    x = round(random(width)); 
    y = round(random(height));    
  }
  
  void initBase() {
    ang = random(2*PI);
    velocidade = 3; 
    r = random(255); g = random(255); b = random(255);
  }
  
  void meDesenhe()   { 
    if (vida > 0) {
      sejaInteligente();
      fill(r,g,b);
      //ellipse(x,y,30,30); 
      image(imagem, x, y);
      fill(255);
      textSize(12);
      text(vida,x-10,y);
    }
  }  
  int  minhaVida()   { return vida;        }
  void moverX(int v) { if (x+v > 0 && x+v < width-30) { x += v; } else { dX = -dX; vida-=10; ang -= PI; } }
  void moverY(int v) { if (y+v > 0 && y+v < height-30) { y += v; } else { dY = -dY; vida-=10; ang -= PI; } }
  void sejaInteligente() {
      opiniao++;
      if (opiniao > 5) {
        //float anguloGraus = random(2*PI);
        
        ang += random(-PI*0.2,PI*0.2);
        dX = cos(ang)*velocidade;
        dY = sin(ang)*velocidade;        
        opiniao = 0;
      }
      moverX(round(dX));
      moverY(round(dY));
  }
}
 No newline at end of file

box.png

0 → 100644
+89.9 KiB
Loading image diff...