source: trunk/monsterz/monsterz.cpp @ 331

Last change on this file since 331 was 331, checked in by sam, 10 years ago

Add an Interface class that displays the general interface.

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1//
2// Monsterz
3//
4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16#include <cmath>
17#if defined _WIN32
18#   include <direct.h>
19#endif
20
21#include <SDL.h>
22
23#include "core.h"
24#include "sdlinput.h"
25#include "title.h"
26#include "board.h"
27#include "interface.h"
28
29#include "debugfps.h"
30
31static float const FPS = 60.0f;
32
33int main(int argc, char **argv)
34{
35    /* Initialise SDL */
36    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
37    {
38        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
39        return EXIT_FAILURE;
40    }
41
42    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
43    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
44    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
45    if (!video)
46    {
47        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
48        SDL_Quit();
49        return EXIT_FAILURE;
50    }
51
52    SDL_WM_SetCaption("Monsterz", NULL);
53    SDL_ShowCursor(0);
54
55    /* Initialise OpenGL */
56    Video::Setup(video->w, video->h);
57    Audio::Setup(2);
58
59    /* Create a game */
60#if defined _WIN32
61    _chdir(".."); /* Temporary Win32 hack */
62#endif
63
64    /* Register an input driver and some debug stuff */
65    new SdlInput();
66    new Board(int2(8, 8), 9);
67    //new Title();
68    new Interface();
69    new DebugFps(460, 20);
70
71    while (!Ticker::Finished())
72    {
73        /* Tick the game */
74        Ticker::TickGame();
75
76        /* Clear the screen, tick the renderer, show the frame and
77         * clamp to desired framerate. */
78        Video::Clear();
79        Ticker::TickDraw();
80        SDL_GL_SwapBuffers();
81        Ticker::ClampFps(1000.0f / FPS);
82    }
83
84    SDL_Quit();
85
86    return EXIT_SUCCESS;
87}
88
Note: See TracBrowser for help on using the repository browser.