Kod wykonany z sobotnią grupą w Wolsztynie xD

PVector head, speed, apple;
int score;
void setup(){
frameRate(12);
size(600, 400);
head = new PVector(300, 300);
speed = new PVector(20, 20);
apple = new PVector(random(width), random(height));
score = 0;
}

void draw(){
background(0, 0, 0);
fill(0, 255, 0);
rect(head.x, head.y, speed.x, speed.y);

fill(255, 0, 0);
rect(apple.x, apple.y, speed.x, speed.y);

fill(255, 255, 255);
textSize(40);
text(score, width/2, 50);

if(keyPressed == true && keyCode == RIGHT){
head.x = head.x + speed.x;
}

if(keyPressed == true && keyCode == LEFT){
head.x = head.x - speed.x;
}

if(keyPressed == true && keyCode == DOWN){
head.y = head.y + speed.y;
}

if(keyPressed == true && keyCode == UP){
head.y = head.y - speed.y;
}

//Zaproponowac warunek do zjadania jablka

head.x = (width + head.x) % width;
head.y = (height + head.y) % height;

}
Udostępnij znajomym

Zostaw komentarz