source: trunk/monsterz/monsterz.cpp @ 253

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

Add preliminary support for sound samples. Implement click.

  • Property svn:keywords set to Id
File size: 1.9 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 "game.h"
25#include "sdlinput.h"
26#include "board.h"
27
28#include "debugfps.h"
29
30static float const FPS = 60.0f;
31
32int main(int argc, char **argv)
33{
34    /* Initialise SDL */
35    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
36    {
37        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
38        return EXIT_FAILURE;
39    }
40
41    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
42    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
43    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
44    if (!video)
45    {
46        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
47        SDL_Quit();
48        return EXIT_FAILURE;
49    }
50
51    SDL_WM_SetCaption("Monsterz", NULL);
52    SDL_ShowCursor(0);
53
54    /* Initialise OpenGL */
55    Video::Setup(video->w, video->h);
56    Audio::Setup(2);
57
58    /* Create a game */
59#if defined _WIN32
60    _chdir(".."); /* Temporary Win32 hack */
61#endif
62    Game *game = new Game();
63
64    /* Register an input driver and some debug stuff */
65    new SdlInput();
66    new Board(game);
67    new DebugFps(460, 20);
68
69    while (!Ticker::Finished())
70    {
71        /* Tick the game */
72        Ticker::TickGame();
73
74        /* Clear the screen, tick the renderer, show the frame and
75         * clamp to desired framerate. */
76        Video::Clear();
77        Ticker::TickDraw();
78        SDL_GL_SwapBuffers();
79        Ticker::ClampFps(1000.0f / FPS);
80    }
81
82    SDL_Quit();
83
84    return EXIT_SUCCESS;
85}
86
Note: See TracBrowser for help on using the repository browser.