Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // (C) 2009-2011 Tim Gurto, Jacqui Hawkins
- #include <cassert>
- #include <fstream>
- #include <ctime>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <cmath>
- #ifdef __APPLE__
- #include "SDLMain.h"
- #endif
- #include "SDL.h"
- #include "SDL_ttf.h"
- #include "SDL_mixer.h"
- #include "Building.h"
- #include "Cursor.h"
- #include "game.h"
- #include "globals.h"
- #include "Debug.h"
- #include "Screen.h"
- #include "Surface.h"
- #include "Point.h"
- #include "ScreenElement.h"
- #include "Sound.h"
- #include "Surface.h"
- #include "Human.h"
- #include "Flower.h"
- #include "Tree.h"
- #include "Bunny.h"
- #include "main.h"
- #include "globals.h"
- #include "util.h"
- #include "misc.h"
- namespace GameJam {
- //global screen buffer
- Surface screenBuf; //uninitialized
- //general debug messages
- Debug debug(YELLOW, 0, 0, 59);
- //can be reused for whichever screens; the useful bit is the name
- enum ButtonID {
- //ScreenElement::NO_ID = -1
- BUTTON_QUIT = 0,
- BUTTON_NEW,
- BUTTON_CREDITS,
- };
- }
- int main(int argc, char *argv[]) {
- try {
- //seed random generator
- srand(unsigned(time(0)));
- //SDL initialization
- int sdlInit(SDL_Init(SDL_INIT_VIDEO));
- assert(sdlInit == 0);
- int ttfInit(TTF_Init());
- assert(ttfInit >= 0);
- int mixInit(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 256)); //256));
- assert(mixInit >= 0);
- GameJam::debug.initFont(GameJam::FONT_DEBUG, 0);
- //initialize screen buffer
- GameJam::screenBuf = GameJam::Surface(GameJam::SUR_SCREEN);
- {//new scope for surfaces
- //init with surfaces
- GameJam::Screen::init();
- GameJam::Screen mainMenu(GameJam::BUTTON_NEW, GameJam::BUTTON_QUIT);
- GameJam::Surface background(GameJam::IMAGE_PATH + "titlescreen2.png", false);
- mainMenu.setBackground(background);
- GameJam::Screen game(&GameJam::gameMode);
- GameJam::Screen credits(GameJam::BUTTON_QUIT, GameJam::BUTTON_QUIT);
- GameJam::buildScreens(mainMenu, credits);
- //statics
- GameJam::Cursor::surface = GameJam::Surface(GameJam::IMAGE_PATH + "cursor.png", true);
- GameJam::Flower::surface = GameJam::Surface(GameJam::IMAGE_PATH + "flowers.png", true);
- GameJam::Flower::futureSurface = GameJam::Surface(GameJam::IMAGE_PATH + "flowerclusters_scale.png", true);
- GameJam::Human::surface = GameJam::Surface(GameJam::IMAGE_PATH + "human.png", true);
- GameJam::Building::surface = GameJam::Surface(GameJam::IMAGE_PATH + "hut.png", true);
- GameJam::Building::futureSurface = GameJam::Surface(GameJam::IMAGE_PATH + "skyscraper.png", true);
- GameJam::Tree::surface = GameJam::Surface(GameJam::IMAGE_PATH + "tree.png", true);
- GameJam::Tree::futureSurface = GameJam::Surface(GameJam::IMAGE_PATH + "treeclump_scale.png", true);
- GameJam::Bunny::surface = GameJam::Surface(GameJam::IMAGE_PATH + "bunny.png", true);
- GameJam::Bunny::futureSurface = GameJam::Surface(GameJam::IMAGE_PATH + "bunny_scale.png", true);
- // skip main menu
- if (!DEBUG) {
- //main menu
- bool loop = true;
- do {
- switch (mainMenu()) {
- case GameJam::BUTTON_QUIT:
- loop = false;
- break;
- case GameJam::BUTTON_CREDITS:
- credits();
- break;
- case GameJam::BUTTON_NEW:
- {
- GameJam::GameOutcome outcome;
- while ((outcome = (GameJam::GameOutcome)game()) == GameJam::RESTART)
- ;
- if (outcome == GameJam::ALT_F4)
- loop = false;
- }
- break;
- }
- }
- while (loop);
- }
- else {
- while (game() == GameJam::RESTART);
- }
- }
- //Quit
- //TTF_Quit() happens at debug dtor
- Mix_CloseAudio();
- SDL_Quit();
- //TODO GameJam::Surface::quit();
- GameJam::Sound::quit();
- }
- catch (std::string& e) {
- std::cerr << e << std::endl;
- }
- catch (...) {
- std::cerr << "Unknown exception" << std::endl;
- }
- return 0;
- }
- namespace GameJam {
- void buildScreens(Screen &mainMenu,
- Screen &credits) {
- //Main menu
- //mainMenu.addElement(
- // ScreenElement(ELEM_LABEL,
- // GAME_TITLE,
- // ANCHOR_CENTER,
- // Point(0, -150))
- //);
- mainMenu.addElement(
- ScreenElement(ELEM_BUTTON,
- "Begin",
- ANCHOR_BOTTOM_LEFT,
- Point(885, -125),
- BUTTON_NEW)
- );
- mainMenu.addElement(
- ScreenElement(ELEM_BUTTON,
- "Credits",
- ANCHOR_BOTTOM_LEFT,
- Point(885, -65),
- BUTTON_CREDITS)
- );
- mainMenu.addElement(
- ScreenElement(ELEM_BUTTON,
- "Quit",
- ANCHOR_BOTTOM_LEFT,
- Point(885, -5),
- BUTTON_QUIT)
- );
- //Credits
- credits.addElement(
- ScreenElement(ELEM_BUTTON,
- "Back",
- ANCHOR_TOP_RIGHT,
- Point(-30, 30),
- BUTTON_QUIT)
- );
- int yPos = CREDITS_OFFSET;
- addCreditTitle(credits, yPos, "Programming");
- addCredit(credits, yPos, "Tim Gurto");
- addCredit(credits, yPos, "Jacqui Hawkins");
- addCreditGap(yPos);
- addCreditTitle(credits, yPos, "Art and Graphic Design");
- addCredit(credits, yPos, "Katherine Primrose");
- addCreditGap(yPos);
- addCreditTitle(credits, yPos, "Sound and Music");
- addCredit(credits, yPos, "Wade Clarke");
- addCreditGap(yPos);
- addCreditTitle(credits, yPos, "Game Design");
- addCredit(credits, yPos, "All of the above");
- addCreditGap(yPos);
- addCreditGap(yPos);
- addCredit(credits, yPos, "Created in 48 hours during the 2011 Sydney Game Jam");
- }
- void addCreditTitle(Screen &creditsScreen,
- int &yPos,
- std::string text) {
- creditsScreen.addElement(
- ScreenElement(ELEM_LABEL,
- text,
- ANCHOR_CENTER,
- Point(CREDITS_X_OFFSET, yPos),
- ScreenElement::NO_ID,
- 0,
- 0,
- 22,
- CREDITS_HEADING_COLOR)
- );
- yPos += CREDITS_INCREMENT;
- }
- void addCredit(Screen &creditsScreen,
- int &yPos,
- std::string text) {
- creditsScreen.addElement(
- ScreenElement(ELEM_LABEL,
- text,
- ANCHOR_CENTER,
- Point(CREDITS_X_OFFSET, yPos),
- ScreenElement::NO_ID,
- 0,
- 0,
- 18)
- );
- yPos += CREDITS_INCREMENT;
- }
- void addCreditGap(int &yPos) {
- yPos += CREDITS_GAP;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement