adventskalender-2009/src/main.c
2009-12-19 21:57:22 +01:00

71 lines
1.8 KiB
C

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "SDL.h"
#include "SDL_ttf.h"
#include "config.h"
#include "draw.h"
#include "states.h"
#include "menu.h"
/**
* This is the main file for the advent game. The adventgame is an interactive
* tutorial on aaron-mueller.de (winter 2009). YOu can read the whole list of
* articles on http://advent.aaron-mueller.de/.
*/
int main(int argc, char **argv) {
// Check input parameters
if (argc == 2) {
if (strcmp(argv[1], "-v") == 0) DEBUG = true;
if (strcmp(argv[1], "--man") == 0) {
system("man adventgame");
exit(0);
}
if (strcmp(argv[1], "-h") == 0) {
printf("Advent Game 2009\n\n \
-v Verbose output, show debug messages\n \
-h Show this lines and quit\n \
--man Open up the manpage\n\n");
exit(0);
}
}
// Initialize SDL and open up a screen
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
menuFont = TTF_OpenFont("/usr/share/fonts/corefonts/verdana.ttf", 50);
currentState = STATE_MAINMENU;
// Initialize internal game state
srand(time(NULL));
terrain = generateTerrain(150.0, 180.0);
// the main game loop
while (currentState != STATE_EXIT) {
// Check for events
if (SDL_PollEvent(&event)) {
// Make it possible to close the game window
if (event.type == SDL_QUIT) currentState = STATE_EXIT;
stateTable[currentState].handleEventsFun();
}
// Draw the stuff on the screen and "flip" th the next frame
SDL_FillRect(screen, NULL, 0x000000);
stateTable[currentState].drawFun();
SDL_Flip(screen);
}
// Cleanup and quit
free(terrain);
SDL_Quit();
return 0;
}