-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallegroSetup.cpp
More file actions
148 lines (123 loc) · 5.64 KB
/
Copy pathallegroSetup.cpp
File metadata and controls
148 lines (123 loc) · 5.64 KB
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
#include "declarations.h"
/// This function initializes Allegro
/// Int return type - returns an error code if something is wrong
/// Refer to the constants for what the error codes mean
int Allegro::initializeAllegro() {
// Initialize Allegro, image and audio add ons
if (!al_init()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize Allegro5!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_ALLEGRO;
}
if (!al_init_image_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize image addon!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_IMAGE_ADDON;
}
if (!al_install_audio()) {
al_show_native_message_box(display, "Error", "Error", "Failed to install audio!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_INSTALL_AUDIO;
}
if (!al_init_acodec_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize acodec addon!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_ACODEC_ADDON;
}
// Reserve space and load music files
al_reserve_samples(NUMBER_OF_MUSIC_SAMPLES);
gameMusic = al_load_sample("gameMusic.wav");
buttonClick = al_load_sample("buttonClick.wav");
// Check that the music files loaded
if (!gameMusic) {
al_show_native_message_box(display, "Error", "Error", "Failed to load gameMusic.wav!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_MUSIC_FILE_GAMEMUSIC;
}
if (!buttonClick) {
al_show_native_message_box(display, "Error", "Error", "Failed to load buttonClick.wav!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_MUSIC_FILE_BUTTONCLICK;
}
// Initialize display
display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);
if (!display) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_DISPLAY;
}
// Need to add image processor
if (!al_init_image_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize image add on!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_IMG_ADDON;
}
// Initialize primative add on
if (!al_init_primitives_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize primatives add on!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_PRIMATIVE_ADDON;
}
// Install mouse
if (!al_install_mouse()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize mouse add on!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_MOUSE_ADDON;
}
// Font add on
if (!al_init_font_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize font add on!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_FONT_ADDON;
}
// initialize the ttf (True Type Font) addon
if (!al_init_ttf_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize font ttf on!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_TTF_ADDON;
}
timer = al_create_timer(1.0 / FPS);
if (!timer) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize fps timer!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_FPSTIMER;
}
// Load the fonts
arial = al_load_ttf_font("C:/Windows/Fonts/arial.ttf", LARGE_FONT_SIZE, 0);
smallArial = al_load_ttf_font("C:/Windows/Fonts/arial.ttf", SMALL_FONT_SIZE, 0);
// Check that the fonts were creates
if (!arial) {
al_show_native_message_box(display, "Error", "Error", "Could not load arial.ttf", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_ARIAL_FONT;
}
if (!smallArial) {
al_show_native_message_box(display, "Error", "Error", "Could not create a small version of arial.ttf", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_SMALL_ARIAL_FONT;
}
// Set up event queue
eventQueue = al_create_event_queue();
if (!eventQueue) {
al_show_native_message_box(display, "Error", "Error", "Failed to create event_queue!", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_EVENT_QUEUE;
}
background = al_load_bitmap("background.png");
if(background == NULL) {
al_show_native_message_box(display, "Error", "Error", "Failed to load disk images! Make sure to inclue that background image.", nullptr, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return ERROR_LOAD_BITMAP;
}
// Start FPS timer
al_start_timer(timer);
// Register Events
al_register_event_source(eventQueue, al_get_display_event_source(display));
al_register_event_source(eventQueue, al_get_timer_event_source(timer));
al_register_event_source(eventQueue, al_get_mouse_event_source());
// Title the window
al_set_window_title(display, "Graphical Sorting - Eric Karpovits");
// Play game sound
al_play_sample(gameMusic, 1.0, 0, 1.0, ALLEGRO_PLAYMODE_LOOP, 0);
return 0;
}