Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage dinosaur1;
- PImage dinosaur2;
- PImage cactus1;
- PImage cactus2;
- //PImage dinoGame tital screen
- int x = 600;
- int state =0;
- final int MENU_SCREEN =0;
- final int GAME_SCREEN =1;
- int timer = 0;
- int y = 150;
- boolean jumping = false;
- int jumpingSpeed = 1;
- void setup() {
- size(600, 400);
- dinosaur1 = loadImage("dinosaur1.png");
- dinosaur2 = loadImage("dinosaur2.png");
- cactus1 = loadImage( "cactus1.png");
- cactus2 = loadImage( "cactus2.png");
- //dino game tital screen = load
- }
- void draw() {
- if (keyPressed) {
- state = GAME_SCREEN;
- }
- switch(state) {
- case MENU_SCREEN:
- background(255);
- fill(0);
- textSize(40);
- text("No internet connection...", 50, 100);
- textSize(10);
- image(dinosaur1, 50, y, 50, 50);
- strokeWeight(4);
- stroke(70);
- line(0,200,600,200);
- break;
- case GAME_SCREEN:
- background(255);
- timer++;
- if (timer < 50) {
- image(dinosaur1, 50, y, 50, 50);
- } else if (timer >+100) {
- timer = 0;
- } else if (timer >=50) {
- image(dinosaur2, 50, y, 50, 50);
- }
- //jump
- if (keyCode == UP && keyPressed&& jumping == false) {
- jumping= true;
- jumpingSpeed = 2;
- }
- if (jumping) {
- y-= jumpingSpeed;
- }
- if (y <= 50) {
- jumpingSpeed = -2;
- }
- if (y == 150) {
- jumpingSpeed = 0;
- jumping = false;
- }
- //cactus1
- image(cactus1, x, 136, 40, 60);
- x-= 3;
- //image(cactus2,200,50);
- strokeWeight(4);
- stroke(70);
- line(0,200,600,200);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement