adventskalender-2009/src/main.c
Aaron Mueller 01147c0d35 Adding game states and menu
* Implement a simple state machine to simulate different game stats
 * Create a generic menu to display different menus
 * Update the Makefile for TTF support
 * Draw a simple diagram to show the stats
2009-12-16 15:37:24 +01:00

54 lines
1.2 KiB
C

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include "SDL.h"
#include "SDL_ttf.h"
#include "config.h"
#include "draw.h"
#include "states.h"
#include "menu.h"
int main(int argc, char **argv) {
// 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);
// Choose right state
stateTable[currentState].drawFun();
stateTable[currentState].handleEventsFun();
// 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;
}