Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int canvasWidth = 320;
- int canvasHeight = 480;
- boolean onScreen = false;
- int foodX;
- int foodY;
- int obstacleX;
- int obstacleY;
- int obstacleHeight;
- int obstacleWidth;
- int score = 0;
- void setup() {
- size(320, 480);
- textSize(32);
- }
- void draw() {
- if (!onScreen) {
- foodY = int(random(canvasHeight));
- foodX = int(random(canvasWidth));
- obstacleX = int(random(canvasHeight));
- obstacleY = int(random(canvasWidth));
- obstacleHeight = int(random(canvasHeight));
- obstacleWidth = int(random(canvasWidth));
- onScreen = true;
- }
- if (mouseX > obstacleX & mouseX < (obstacleX + obstacleWidth) & mouseY > obstacleY & mouseY < (obstacleY + obstacleHeight)) {
- score--;
- onScreen = false;
- }
- background(204);
- text(("Score: " + str(score)), 10, 30);
- color c = color(255, 0, 0);
- fill(c);
- noStroke();
- rect(obstacleX, obstacleY, obstacleHeight, obstacleWidth);
- color d = color(255, 255, 255);
- fill(d);
- noStroke();
- rect(foodX, foodY, 10, 10);
- }
- void mouseClicked() {
- if (mouseX > foodX & mouseX < (foodX + 10) & mouseY > foodY & mouseY < (foodY + 10)) {
- score++;
- onScreen = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement