Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created September 29, 2013 09:47
Show Gist options
  • Save darkwave/6751020 to your computer and use it in GitHub Desktop.
Save darkwave/6751020 to your computer and use it in GitHub Desktop.
Simple menu for IndieSpeedRun 2013 entry by SpaghettiCoder
final int GAME_INIT = -1;
final int GAME_MENU = 0;
final int GAME_RUNNING = 1;
final int GAME_WIN = 2;
final int GAME_LOOSE = 3;
int gameState = GAME_INIT;
int gameLoadedTime;
PImage splashScreen, startMenu, youWin, youLoose;
void setup() {
size(526, 710, P3D);
textAlign(CENTER, CENTER);
thread("loadAsset");
//loadAsset();
}
void loadAsset() {
splashScreen = loadImage("splash.png");
startMenu = loadImage("menu.png");
youWin = loadImage("win.png");
youLoose = loadImage("lost.png");
gameLoadedTime = millis();
while(millis() - gameLoadedTime < 4000) {
}
gameLoadedTime = millis();
gameState = GAME_MENU;
}
void draw() {
if (gameState == GAME_RUNNING) {
background(255, 0, 0);
} else if (gameState == GAME_MENU) {
if (millis() - gameLoadedTime > 3000) {
image(startMenu, 0, 0, width, height);
} else {
background(255, 128, 0);
image(splashScreen, 0, 0, width, height);
}
} else if (gameState == GAME_WIN) {
image(youWin, 0, 0, width, height);
}
else if (gameState == GAME_LOOSE) {
image(youLoose, 0, 0, width, height);
}
else if (gameState == GAME_INIT) {
if (millis() - lastDot > 500) {
background(0);
lastDot = millis();
textAlign(LEFT, CENTER);
text(loading[dotCounter++], width / 2, height / 2);
dotCounter %= loading.length;
}
}
}
String[] loading = new String[] {
"Cooking", "Cooking.", "Cooking..", "Cooking..."
};
int dotCounter = 0;
int lastDot;
void mouseClicked() {
if (gameState == GAME_MENU) {
gameState = GAME_RUNNING;
} else if ((gameState == GAME_WIN) || (gameState == GAME_LOOSE)) {
gameState = GAME_MENU;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment