Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage
- dino,
- cactus,
- gameover;
- int
- score = 0,
- road,
- dinoX,
- dinoY,
- dinoStep,
- dinoMaxStep = 0,
- cactusX,
- cactusY,
- cactusSpeed;
- void setup() {
- size (1200, 600);
- fill (0);
- dino = loadImage("dino.png");
- cactus = loadImage("cactus.png");
- gameover = loadImage("gameover.jpg");
- road = int(height * 0.6);
- dinoX = dino.width;
- dinoY = road - dino.height - cactus.height;
- cactusX = width + cactus.width;
- cactusY = road - cactus.height;
- cactusSpeed = width / 70;
- }
- void cactus() {
- image(cactus, cactusX, cactusY);
- cactusX -= cactusSpeed;
- if (cactusX < -cactus.width) {
- ++score;
- cactusX = width + cactus.width;
- }
- }
- void dino () {
- image(dino, dinoX, dinoY);
- dinoY += dinoStep;
- dinoStep += 2;
- if (dinoY > road - dino.height) {
- dinoY = road - dino.height;
- if (dinoMaxStep == 0)
- dinoMaxStep = dinoStep;
- }
- }
- boolean gameOver () {
- if ((dinoY > road - cactus.height) && (dinoX + dino.width / 2 > cactusX) && (dinoX < cactusX + cactus.width/2))
- return true;
- else
- return false;
- }
- void keyPressed () {
- if (key == ' ' && dinoY == road - dino.height)
- dinoStep = -dinoMaxStep;
- }
- void mouseClicked() {
- if (gameOver()) {
- score = 0;
- cactusX = width + cactus.width;
- dinoX = dino.width;
- }
- }
- void draw() {
- background(255);
- rect(0, road, width, height * 0.001);
- text("Score: " + score, width * 0.9, height * 0.05);
- if (!gameOver()) {
- dino ();
- cactus();
- } else
- image(gameover, 0, 0, width, height);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement