2009-12-01 22:55:38 +01:00
|
|
|
|
2009-12-01 23:02:55 +01:00
|
|
|
#include <stdio.h>
|
2009-12-07 16:57:30 +01:00
|
|
|
#include <stdbool.h>
|
2009-12-14 14:22:28 +01:00
|
|
|
#include <stdlib.h>
|
2009-12-19 21:57:22 +01:00
|
|
|
#include <string.h>
|
2009-12-16 15:37:24 +01:00
|
|
|
#include <time.h>
|
2009-12-07 16:57:30 +01:00
|
|
|
#include "SDL.h"
|
2009-12-16 15:37:24 +01:00
|
|
|
#include "SDL_ttf.h"
|
2009-12-07 16:57:30 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "draw.h"
|
2009-12-16 15:37:24 +01:00
|
|
|
#include "states.h"
|
|
|
|
#include "menu.h"
|
|
|
|
|
2009-12-01 23:02:55 +01:00
|
|
|
|
2009-12-19 21:57:22 +01:00
|
|
|
/**
|
|
|
|
* 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/.
|
|
|
|
*/
|
2009-12-01 22:55:38 +01:00
|
|
|
int main(int argc, char **argv) {
|
2009-12-19 21:57:22 +01:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-07 16:57:30 +01:00
|
|
|
// Initialize SDL and open up a screen
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
2009-12-16 15:37:24 +01:00
|
|
|
TTF_Init();
|
2009-12-07 16:57:30 +01:00
|
|
|
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
2009-12-16 15:37:24 +01:00
|
|
|
menuFont = TTF_OpenFont("/usr/share/fonts/corefonts/verdana.ttf", 50);
|
|
|
|
|
|
|
|
currentState = STATE_MAINMENU;
|
2009-12-07 16:57:30 +01:00
|
|
|
|
2009-12-14 00:28:06 +01:00
|
|
|
// Initialize internal game state
|
2009-12-14 14:22:28 +01:00
|
|
|
srand(time(NULL));
|
2009-12-14 00:28:06 +01:00
|
|
|
terrain = generateTerrain(150.0, 180.0);
|
2009-12-16 15:37:24 +01:00
|
|
|
|
2009-12-07 16:57:30 +01:00
|
|
|
// the main game loop
|
2009-12-16 15:37:24 +01:00
|
|
|
while (currentState != STATE_EXIT) {
|
2009-12-07 16:57:30 +01:00
|
|
|
// Check for events
|
|
|
|
if (SDL_PollEvent(&event)) {
|
|
|
|
// Make it possible to close the game window
|
2009-12-16 15:37:24 +01:00
|
|
|
if (event.type == SDL_QUIT) currentState = STATE_EXIT;
|
|
|
|
stateTable[currentState].handleEventsFun();
|
2009-12-07 16:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the stuff on the screen and "flip" th the next frame
|
2009-12-10 23:23:02 +01:00
|
|
|
SDL_FillRect(screen, NULL, 0x000000);
|
2009-12-16 15:37:24 +01:00
|
|
|
stateTable[currentState].drawFun();
|
2009-12-07 16:57:30 +01:00
|
|
|
SDL_Flip(screen);
|
|
|
|
}
|
|
|
|
|
2009-12-14 00:28:06 +01:00
|
|
|
// Cleanup and quit
|
|
|
|
free(terrain);
|
|
|
|
|
2009-12-07 16:57:30 +01:00
|
|
|
SDL_Quit();
|
2009-12-01 22:55:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|