/
blit.cpp
304 lines (251 loc) · 7.89 KB
/
blit.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//////////////////////////////////////////////////////////////////////////////
//
// PocketFrog - The Game Library for Pocket PC Devices
// Copyright 2002 Thierry Tremblay
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. Thierry Tremblay makes no representations
// about the suitability of this software for any purpose.
// It is provided "as is" without express or implied warranty.
//
//////////////////////////////////////////////////////////////////////////////
#include "blit.h"
#include "resource.h"
#include <HSS.h>
using namespace Frog;
//////////////////////////////////////////////////////////////////////////////
//
// _Module : This is needed to use ATL Windows
//
//////////////////////////////////////////////////////////////////////////////
CComModule _Module;
//////////////////////////////////////////////////////////////////////////////
//
// BlitSample
//
//////////////////////////////////////////////////////////////////////////////
BlitSample::BlitSample()
{
introscreen = 1;
buttonpressed= 0;
m_config.szWindowName = _T( "Prototype" );
m_config.orientation = ORIENTATION_NORMAL;
}
bool BlitSample::GameInit()
{
Display* display = GetDisplay();
i_loading = LoadImage(display, IDB_LOADING);
return true;
}
void BlitSample::ManualInit() {
int i;
timerdiff = secsperframe = movement = moveThisMuch = 0;
timer = PocketPC::GetTickCount();
// Initialize random seed
srand( PocketPC::GetTickCount() );
// Initialize video stuff
Display* display = GetDisplay();
beforeSurface = new Surface(240,320);
afterSurface = new Surface(240,320);
module[MAINMENU] = new MainMenu();
//module[1] = new MainGame();
//module[2] = new Options();
module[TRANSITION] = new Transition();
module[TUTORIAL] = new Tutorial();
module[HIGHSCORES] = new HighScores();
//module[DODGE] = new Dodge();
module[EXIT] = new MainMenu();
/*module[MEMORY] = new Memory();
module[HANGMAN] = new Hangman();
module[ANAGRAM] = new Anagram();
module[WHAC] = new Whac();
module[LOWTOHIGH] = new LowToHigh();
module[WORDFINDER] = new WordFinder();*/
module[JOGGLE] = new Joggle();
//module[SUDOKU] = new Sudoku();
// link shared
shared = new Shared();
shared->Init(display, &m_keys);
shared->file->ErrorWrite("initialized shared structure");
// init modules
for (i = 0; i < NUM_MODULES; i++) {
module[i]->LinkShared(shared);
module[i]->GameInit(display);
}
shared->file->ErrorWrite("linked shared structure");
shared->file->ErrorWrite("initialized modules");
//images
i_numbers = LoadImage( display, IDB_NUMBERS );
m_FPSCounter = 0;
m_lastTime = 0;
}
void BlitSample::GameEnd()
{
if (introscreen)
return;
int i;
for (i = 0; i < NUM_MODULES; i++)
module[i]->GameEnd();
shared->End();
delete i_numbers;
}
void BlitSample::GameLoop()
{
if (introscreen == 2) {
ManualInit();
introscreen = 0;
}
else if (introscreen == 1) {
Display* display = GetDisplay();
display->GetBackBuffer();
display->Clear(Color(255,255,255));
display->Blit(82,146,i_loading);
display->Update();
introscreen++;
return;
}
shared->input->Process();
if (shared->gamestate == EXIT)
return;
// Render
Display* display = GetDisplay();
display->GetBackBuffer();
display->Clear(Color(0,0,0));
before = shared->gamestate;
module[shared->gamestate]->GameLoop(display);
after = shared->gamestate;
/**/
// DrawFPS(display);
//DrawDebug(display);
//TCHAR paused3[200];
//_stprintf(paused3, TEXT("%d %d %d"), buttonpressed, m_keys.vkUp, m_keys.vkDown);
// shared->bigfont->DisplayText(display,10,30,paused3,Color(255,0,255));
display->Update();
// transition
if (before != after && before != TRANSITION) {
if (after == EXIT) {
Shutdown();
return;
}
//display = GetDisplay();
display->SetRenderTarget(beforeSurface);
module[before]->Render(display);
display->Update();
// display = GetDisplay();
display->SetRenderTarget(afterSurface);
if (shared->newgame && after == JOGGLE)
module[JOGGLE]->StartAnimation();
module[after]->Render(display);
display->Update();
display->SetRenderTarget(NULL);
shared->SetFromSurface(beforeSurface);
shared->SetToSurface(afterSurface);
shared->gamestate = TRANSITION;
shared->nextstate = after;
module[before]->FinishAnimation();
}
if (before == TRANSITION) {
module[after]->StartAnimation();
}
// timing
timerdiff = PocketPC::GetTickCount()-timer;
secsperframe=(timerdiff/1000.0f);
movement = secsperframe;
moveThisMuch = fabs(secsperframe);// framerate independent movement
if (moveThisMuch > 0)
shared->delta_time = moveThisMuch;
timer = PocketPC::GetTickCount();
}
void BlitSample::StylusDown( Point stylus )
{
if (introscreen)
return;
shared->input->StylusDown(stylus);
module[shared->gamestate]->StylusDown(stylus);
}
void BlitSample::StylusUp( Point stylus )
{
if (introscreen)
return;
shared->input->StylusUp(stylus);
module[shared->gamestate]->StylusUp(stylus);
}
void BlitSample::StylusMove( Point stylus )
{
if (introscreen)
return;
shared->input->StylusMove(stylus);
module[shared->gamestate]->StylusMove(stylus);
}
void BlitSample::ButtonDown(int button) {
if (introscreen)
return;
if(m_keys.vkUp == button || m_keys.vkDown == button ||
m_keys.vkLeft == button || m_keys.vkRight == button || m_keys.vkStart ==
button || m_keys.vkA == button || m_keys.vkB == button || m_keys.vkC ==
button || m_keys.vkAux1 == button || m_keys.vkAux2 == button ||
m_keys.vkAux3 == button || m_keys.vkAux4 == button || m_keys.vkAux5 ==
button || m_keys.vkAux6 == button || m_keys.vkAux7 == button ||
m_keys.vkAux8 == button){
buttonpressed=button;
shared->input->ButtonDown(button);
module[shared->gamestate]->ButtonDown(button);
}
}
void BlitSample::ButtonUp(int button) {
if (introscreen)
return;
if(m_keys.vkUp == button || m_keys.vkDown == button ||
m_keys.vkLeft == button || m_keys.vkRight == button || m_keys.vkStart ==
button || m_keys.vkA == button || m_keys.vkB == button || m_keys.vkC ==
button || m_keys.vkAux1 == button || m_keys.vkAux2 == button ||
m_keys.vkAux3 == button || m_keys.vkAux4 == button || m_keys.vkAux5 ==
button || m_keys.vkAux6 == button || m_keys.vkAux7 == button ||
m_keys.vkAux8 == button) {
buttonpressed=button;
shared->input->ButtonUp(button);
module[shared->gamestate]->ButtonUp(button);
}
}
//////////////////////////////////////////////////////////////////////////////
//
// WinMain - Entry point
//
//////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
_Module.Init( 0, hInstance );
BlitSample game;
game.Run();
return 0;
}
void BlitSample::DrawFPS(Display *display) {
// Update FPS
m_FPSTicks[ m_FPSCounter & 15 ] = PocketPC::GetTickCount();
if (m_FPSCounter > 15)
{
uint32_t totalTime = m_FPSTicks[ m_FPSCounter & 15 ] - m_FPSTicks[ (m_FPSCounter+1) & 15 ];
if (totalTime == 0) totalTime = 1;
uint32_t fps = 16000 / totalTime;
uint32_t n100 = fps / 100; fps -= n100 * 100;
uint32_t n10 = fps / 10; fps -= n10 * 10;
uint32_t n1 = fps;
if (n100 > 9) { n100 = 9; n10 = 9; n1 = 9; }
// Display fps
display->Blit( 0, 0, i_numbers, &Rect( n100 * 8, 0, (n100+1)*8, 11 ) );
display->Blit( 8, 0, i_numbers, &Rect( n10 * 8, 0, (n10+1)*8, 11 ) );
display->Blit( 16, 0, i_numbers, &Rect( n1 * 8, 0, (n1+1)*8, 11 ) );
}
++m_FPSCounter;
}
void BlitSample::DrawDebug(Display *display) {
/*//debugging
TCHAR debug[30];
_stprintf(debug,"%f",moveThisMuch);
shared->bigfont->DisplayText(display,50,70,debug, Color(255,0,255));
shared->file->ErrorWrite(debug);
/**/
}