Arkanoid kolejna wersja xD

Główny plik:

PVector location, velocity, paddle;

float d;

Coin c1;

int radius, score;

void setup(){
size(600, 400);
score = 0;
c1 = new Coin(40, 40, 20);
radius = 10;
location = new PVector(0.5*width, 0.5*height);
velocity = new PVector(2, 5);
paddle = new PVector(100, 20);
}

void draw(){
background(0, 0, 0);
noStroke();
fill(0, 180, 0);
ellipse(location.x, location.y, radius, radius);
rect(mouseX, height - paddle.y, paddle.x, paddle.y);
location.add(velocity);
c1.display();


if(location.y < 0){
velocity.y = - 1 * velocity.y;
}

if(location.x > width || location.x < 0){
velocity.x = - 1 * velocity.x;
}

if(location.x > mouseX && location.x < (mouseX + paddle.x) && location.y + radius/2 > (height - paddle.y))
{
velocity.y = - 1 * velocity.y;
}


 if (keyPressed == true && key == 'c')
  {
    setup();
    println("wcisnieto klawisz c");
  }
  
  fill(255);
  textSize(20);
  text("punkty: ", 10, 20);
  text(score, 100, 20);
  
  if(location.y > height){
   fill(255, 0, 0);
   textSize(40);
   text("GAME OVER", 200, 180); 
   noLoop();
  }
  
  d = pow((location.x - c1.x), 2) + pow((location.y - c1.y), 2);
  
  if (d<400){
    c1.is_live = 0;
    score = score + 10;
  }
  
}
Klasa Coin:

class Coin{
int x, y, r, is_live;
Coin(int x_, int y_, int r_){
x = x_;
y = y_;
r = r_;
is_live = 1;
}
void display(){
if(is_live == 1){
ellipse(x, y, r, r);
}
}
}
Udostępnij znajomym

Zostaw komentarz