source: trunk/src/test-map.cpp @ 132

Last change on this file since 132 was 132, checked in by sam, 11 years ago

Add a debug sprite to the scene.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11#include <cmath>
12
13#include <SDL.h>
14
15#include "sdlinput.h"
16#include "debugfps.h"
17#include "debugsprite.h"
18#include "game.h"
19#include "ticker.h"
20#include "profiler.h"
21#include "video.h"
22
23static float const FPS = 30.0f;
24
25int main(int argc, char **argv)
26{
27    /* Initialise SDL */
28    if (SDL_Init(SDL_INIT_VIDEO) < 0)
29    {
30        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
31        return EXIT_FAILURE;
32    }
33
34    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
35    if (!video)
36    {
37        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
38        SDL_Quit();
39        return EXIT_FAILURE;
40    }
41
42    SDL_WM_SetCaption("Deus Hax (SDL)", NULL);
43    SDL_ShowCursor(0);
44    SDL_WM_GrabInput(SDL_GRAB_ON);
45
46    /* Initialise OpenGL */
47    Video::Setup(video->w, video->h);
48
49    /* Create a game */
50    Game *game = new Game("maps/testmap.tmx");
51
52    /* Register an input driver and some debug stuff */
53    new SdlInput(game);
54    new DebugFps();
55    new DebugSprite(game);
56
57    while (!game->Finished())
58    {
59        /* Tick the game */
60        Ticker::TickGame();
61
62        /* Clear the screen, tick the renderer, show the frame and
63         * clamp to desired framerate. */
64        Video::Clear();
65        Ticker::TickRender();
66        SDL_GL_SwapBuffers();
67        Ticker::ClampFps(1.0f / FPS);
68    }
69
70    SDL_Quit();
71
72    return EXIT_SUCCESS;
73}
74
Note: See TracBrowser for help on using the repository browser.