-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppContris.cpp
121 lines (93 loc) · 2.43 KB
/
AppContris.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Contris Copyright (C) 2009 Aaron Greene
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Pch.h"
#include "AppContris.h"
AppContris::AppContris(): m_screen(0)
{
}
const bool AppContris::Init()
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return false;
}
if(TTF_Init() == -1)
{
return false;
}
m_screen = SDL_SetVideoMode(GAME_WIDTH, GAME_HEIGHT, 32, SDL_SWSURFACE);
if (m_screen == NULL)
{
return false;
}
if (!m_layerControl.Init())
{
return false;
}
SDL_WM_SetCaption("Contris", NULL);
return true;
}
void AppContris::Run()
{
if (!Init())
{
CleanUp();
return;
}
SDL_Event event;
while(true)
{
//
// Process events.
//
while(SDL_PollEvent(&event))
{
m_layerControl.HandleEvent(event);
m_layerGame.HandleEvent(event);
}
//
// Check for button quit, we want to pause before quiting to show button was clicked.
//
if (System::Quited())
{
static int time = SDL_GetTicks();
if ((SDL_GetTicks() - time) > 300)
{
break;
}
}
//
// Check for forced quit, the user clicked on Window "X" to quit.
//
if (event.type == SDL_QUIT)
{
break;
}
//
// Paint black to entire screen.
//
SDL_FillRect(m_screen, &m_screen->clip_rect, SDL_MapRGB(m_screen->format, 0, 0, 0));
//
// Draw layers to screen.
//
m_layerControl.Draw(m_screen);
m_layerGame.Draw(m_screen);
SDL_Flip(m_screen);
}
CleanUp();
}
void AppContris::CleanUp()
{
SDL_FreeSurface(m_screen);
SDL_Quit();
TTF_Quit();
}