如何为游戏创建开始屏幕?

时间:2019-06-13 00:23:33

标签: processing

我正在尝试为自己制作的游戏设置2个屏幕。程序打开时,我想有一个启动屏幕,显示单击以启动。取而代之的是,我在游戏的开始画面中显示了开始画面。单击时游戏确实开始,但没有带有标题图像或“要在任何地方开始单击”的开始屏幕 我尝试将其拆分为代码中的不同屏幕,但无法正常工作。 我想要一个在文件中打开游戏时带有图像的开始屏幕,以及一个“要开始单击任何指向实际游戏本身的标题。

int gameScreen = 0;
int moveX = 300;
int moveY = 370;
int down = 0;
int volX = 600;
float number = 250;
float number2 = 100;
float number1;
float volY = 370;
float volY2 = 370;
boolean ground = true;
boolean air = false;
guy man = new guy();
volcano vol = new volcano();

void initScreen() {
    background(0);
    textAlign(CENTER);
    text("Click to start", height / 2, width / 2);
}

void gameScreen() {}

void setup() {
    size(960, 540);
    int score = 0;

    import ddf.minim.*;
    Minim minim;  
    AudioPlayer music;  

    minim = new Minim(this);   
    music = minim.loadFile("Lava Boiling,Relaxing Bubbling Lava sound,Lava Sound Effect ,Nature sounds..mp3");    
    music.play();  
}

void draw() {
    PImage hopper2;
    background(hopper2 = loadImage("mineescapestartscreen.png"));
    image(hopper2, 0, 0);
    if (gameScreen == 0) {
        initScreen();
    } else if (gameScreen == 1) {
        gameScreen();
    } else if (gameScreen == 2) {
        gameOverScreen();
    }

    PImage hopper;
    background(hopper = loadImage("image.png"));
    image(hopper, 0, 0);
    gameScreen();
    man.drawguy();
    vol.drawvolcano();
    man.checkguy();
    if (keyPressed) {
        man.up();
    }

    if (moveY <= 370) {
        man.down();
    }
}

class guy {

    guy() {
        int moveX = 300;
        int moveY = 370;
    }

    void drawguy() {
        PImage guy = loadImage("cptminerrr.png");
        image(guy, moveX, moveY, guy.width / 2, guy.height / 2);
    }

    void keyPressed() {

        if (keyCode == 32) {
            up();
        }
    }

    void keyReleased() {
        println("released " + int(key) + " " + keyCode);
        down();
    }

    void up() {
        if (air == false) {
            while (moveY >= 270) {
                moveY -= 100;
            }
        }
    }

    void down() {
        moveY += 8;
    }

    void checkguy() {
        if (moveY < 370) {
            air = true;
            if (moveY > 350) {
                air = false;
            }
        }
    }
}

class volcano {
    void drawvolcano() {
        PImage vol = loadImage("cptvolcanoo.png");

        image(vol, volX, volY, vol.width, volY);
        volX -= 8;
        if (volX <= 0) {
            volX = 960 ;

            volY = random(280, 360);
        }
    }
}

void gameOverScreen() {
    // codes for game over screen
}

public void mousePressed() {
    // if we are on the initial screen when clicked, start the game
    if (gameScreen == 0) {
        startGame();
    }
}

void startGame() {
    gameScreen = 1;
}

0 个答案:

没有答案