Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage backgroundImage;
- PImage playerImage;
- PImage tanniImage;
- float tanniY;
- float tanniX;
- int score;
- int state;
- void setup() {
- size(1280, 720, P2D);
- backgroundImage = loadImage("school.jpg");
- backgroundImage.resize(width, height);
- playerImage = loadImage("chimpanzee.png");
- playerImage.resize(200, 200);
- tanniImage = loadImage("tanni.png");
- tanniImage.resize(100, 100);
- imageMode(CENTER);
- tanniY = -50;
- tanniX = random(50, width - 50);
- fill(0);
- score = 0;
- state = 0;
- }
- void draw() {
- background(backgroundImage);
- switch(state) {
- case 0:
- titleScene();
- break;
- case 1:
- gameScene();
- break;
- case 2:
- resultScene();
- break;
- }
- }
- void resetTanni() {
- tanniY = -50;
- tanniX = random(50, width - 50);
- }
- void titleScene() {
- textSize(70);
- textAlign(CENTER, CENTER);
- text("Title Scene", width / 2, height / 2);
- textSize(30);
- text("ENTER to Start", width / 2, height / 2 + 80);
- if (keyCode == ENTER) {
- state = 1;
- }
- }
- void gameScene() {
- textSize(50);
- textAlign(RIGHT, TOP);
- tanniY += 8;
- image(playerImage, mouseX, 520);
- tanniY += 8;
- image(tanniImage, tanniX, tanniY);
- if (height < tanniY - 50) {
- resetTanni();
- }
- if (dist(mouseX, 520, tanniX, tanniY) < 80) {
- resetTanni();
- score++;
- }
- text("score: " + score, width, 0);
- if (10 <= score) {
- state = 2;
- }
- }
- void resultScene() {
- textSize(70);
- textAlign(CENTER, CENTER);
- text("Result Scene", width / 2, height / 2);
- textSize(30);
- text("ENTER to play again / ESC to exit", width / 2, height / 2 + 80);
- if (keyCode == ENTER) {
- score = 0;
- state = 0;
- } else if (keyCode == ESC) {
- exit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement