1bool Setup
()
2{
3
4 if(al_init())
5 {
6 InitLog
(); // Rude log system for debugging
7 Log
("Allegro Initialized");
8
9 g_pSavePath
= al_get_standard_path(ALLEGRO_RESOURCES_PATH
);
10 al_append_path_component(g_pSavePath,
"Save");
11 g_pScreenshotPath
= al_get_standard_path(ALLEGRO_RESOURCES_PATH
);;
12 al_append_path_component(g_pScreenshotPath,
"screenshot");
13
14#ifdef _DEBUG
15 strcpy(g_szSector,
"");
16#endif // DEBUG
17
18 g_nScreenWidth
= 1024;
19 g_nScreenHeight
= 768;
20 //al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
21#ifdef _DEBUG
22 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS,
1, ALLEGRO_REQUIRE
);
23 al_set_new_display_option(ALLEGRO_SAMPLES,
8, ALLEGRO_SUGGEST
);
24 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR
| ALLEGRO_MAG_LINEAR
);
25 al_set_new_display_flags(ALLEGRO_WINDOWED
);
26 g_pDisplay
= al_create_display(g_nScreenWidth, g_nScreenHeight
);
27#else
28 if ( al_show_native_message_box(g_pDisplay,
29 "SETUP",
30 "Screen Mode",
31 "Go Fullscreen ?",
32 NULL,
33 ALLEGRO_MESSAGEBOX_YES_NO
) == 1)
34 {
35 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS,
1, ALLEGRO_REQUIRE
);
36 al_set_new_display_option(ALLEGRO_SAMPLES,
8, ALLEGRO_SUGGEST
);
37 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR
| ALLEGRO_MAG_LINEAR
);
38 al_set_new_display_flags(ALLEGRO_FULLSCREEN
);
39 g_pDisplay
= al_create_display(g_nScreenWidth, g_nScreenHeight
);
40
41 /*
42 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
43 g_pDisplay = al_create_display(g_nWindowWidth, g_nWindowHeight);
44
45 g_nWindowWidth = al_get_display_width(g_pDisplay);
46 g_nWindowHeight = al_get_display_height(g_pDisplay);
47
48 float sx = g_nWindowWidth / (float)g_nScreenWidth;
49 float sy = g_nWindowHeight / (float)g_nScreenHeight;
50
51 ALLEGRO_TRANSFORM trans;
52 al_identity_transform(&trans);
53 al_scale_transform(&trans, sx, sy);
54 al_use_transform(&trans);
55 */
56 }
57 else
58 {
59 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS,
1, ALLEGRO_REQUIRE
);
60 al_set_new_display_option(ALLEGRO_SAMPLES,
8, ALLEGRO_SUGGEST
);
61 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR
| ALLEGRO_MAG_LINEAR
);
62 al_set_new_display_flags(ALLEGRO_WINDOWED
);
63 g_pDisplay
= al_create_display(g_nScreenWidth, g_nScreenHeight
);
64 }
65#endif
66
67 if (g_pDisplay
!= NULL
)
68 {
69 Log
("Display created");
70
71 // Install allegro modules
72 al_init_primitives_addon();
73 al_init_image_addon();
74 al_install_keyboard();
75 al_install_mouse();
76 Log
("Add ons installed");
77
78 // Init Sound manager
79 SoundManager::Init_SoundManager
(RESERVED_SAMPLES
);
80 Log
("SoundManager Initializes");
81 // Load the sounds
82 SoundManager::LoadSounds
();
83 Log
("Sounds loaded");
84
85
86 // install event queue
87 g_pEventQueue
= al_create_event_queue();
88 al_register_event_source(g_pEventQueue,
al_get_keyboard_event_source());
89 al_register_event_source(g_pEventQueue,
al_get_mouse_event_source());
90 al_register_event_source(g_pEventQueue,
al_get_display_event_source(g_pDisplay
));
91 Log
("Event sources registered");
92
93
94 // Init Fontmanager
95 FontManager::Init_FontManager
();
96 Log
("Fontmanager Initializes");
97 FontManager::LoadFonts
();
98
99
100 CStatement::INIT
( FontManager::GetFont
(FONT::TEXT
),
101 al_map_rgb(61,
134,
200),
102 al_map_rgb(1,
150,
10),
103 al_map_rgb(55,
255,
100) );
104
105 // Initialize the Sprite Object classes
106 if (!InitObjects
())
107 {
108 Log
("Could not init Objects");
109 return false;
110 }
111
112
113 // set quit to false
114 g_blQuit
= false;
115
116 // create the menu
117 g_pMenu
= new TMenu
();
118 if (g_pMenu
!= NULL
)
119 {
120 g_pMenu->AddMenuItem
("New Game",NewGame
);
121 g_pMenu->AddMenuItem
("Load",SetupLoadScreen
);
122 g_pMenu->AddMenuItem
("Map Keys",DoKeymap
);
123 g_pMenu->AddMenuItem
("Quit",Quit
);
124 }
125 else
126 {
127 Log
("Could not create menu");
128 return false;
129 }
130
131
132
133
134
135 // Create game engine
136 g_pEngine
= new TEngine
(g_nScreenWidth,g_nScreenHeight
);
137 Log
("Game engine created");
138
139 // create Paralax system
140 g_pParalax
= new Paralax
(g_nScreenWidth,g_nScreenHeight,
300,
5);
141 Log
("Paralax created");
142
143
144 // create the keymapper
145 g_pKeyMapper
= new TKeyMapper
(g_pEngine->m_clGREEN, g_pEngine->m_clYELLOW,FontManager::GetFont
(FONT::KEYS
));
146 Log
("Key Mapper created");
147
148 // push gamestate GS_GAME on the gamestate stack
149 g_vGameState.push_back
(GS_MENU
);
150 Log
("GAME STATE TO MENU");
151
152
153
154 // Get rid of the mouse
155 al_show_mouse_cursor(g_pDisplay
);
156
157 // Initialize DeltaTime, and create the timer
158 g_dLastTime
= al_get_time();
159 g_pTimer
=al_create_timer(1.
000/g_nCyclesPerSecond
);
160 al_register_event_source(g_pEventQueue,
al_get_timer_event_source(g_pTimer
));
161
162
163 LoadMapping
();
164 // start the timer
165 al_start_timer(g_pTimer
);
166 }
167 else
168 {
169 // Display creation failed
170 return false;
171 }
172 }
173 else
174 {
175 // Allegro could not be initialized
176 return false;
177 }
178
179 // all went well
180 return true;
181}