Skip to content

Instantly share code, notes, and snippets.

@icq4ever
Last active June 14, 2020 09:17
Show Gist options
  • Save icq4ever/0058785f31cf7b202e358fbf7cb413e2 to your computer and use it in GitHub Desktop.
Save icq4ever/0058785f31cf7b202e358fbf7cb413e2 to your computer and use it in GitHub Desktop.
6/14 미로찾기 질문 소스
int gameScreen;
float timeStart;
float score;
float time;
float duration=5; //게임 시간 60초 설정
boolean isFailed = false;
void setup() {
size(500, 500);
}
void draw() {
// calculate timer\
if (gameScreen != -1) {
time = duration - (millis() - timeStart)/1000;
}
if (time < 0) {
gameScreen = -1;
}
if (gameScreen == 0) {
startScreen();
} else if (gameScreen == 1) {
playScreen();
} else if (gameScreen == 2) {
succedScreen();
} else if (gameScreen == -1) {
failScreen();
}
}
//시작 화면
void startScreen() {
background(0);
textAlign(CENTER);
textSize(32);
fill(255);
text("Click to start", height/2, width/2);
}
//플레이 화면
void playScreen() {
background(255);
textAlign(CENTER);
textSize(20);
text("Press any key if you succeed.", width/2, 360);
textSize(38);
fill(0);
text(time, height/2, width/2);
if (time*1000<0) {
startGame();
}
}
//성공했을 때 뜨는 화면
void succedScreen() {
background(255);
textAlign(CENTER);
textSize(32);
text("Congratulation!", height/2, width/2);
textSize(24);
text("Score:", width/2, 360);
textSize(32);
text(score, width/2, 410);
textSize(24);
}
//실패했을 때 뜨는 화면
void failScreen() {
background(255, 0, 0);
textAlign(CENTER);
textSize(32);
text("YOU ARE LOOSER", height/2, width/2);
textSize(20);
text("Press any key to try again", height/2+30, width/2);
}
void mousePressed() {
if (gameScreen==0) {
startGame();
}
}
void keyPressed() {
if (gameScreen==2) {
initGame();
}
if (gameScreen==1) {
score = duration - (millis() - timeStart)/1000;
println(score);
gameSucced();
}
if(gameScreen == -1){
timeStart = millis();
initGame();
}
}
void initGame() {
score=0;
gameScreen=0;
}
void startGame() {
timeStart = millis();
gameScreen=1;
}
void gameSucced() {
gameScreen=2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment