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
|
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_native_dialog.h>
int main(int argc, char *argv[]) {
ALLEGRO_DISPLAY *screen = al_create_display(640, 640);
al_install_keyboard();
al_set_window_title(screen, "Box Color Changer Game v1.0");
ALLEGRO_BITMAP *buffer = al_create_bitmap(640, 640), *stone_light = al_load_bitmap("stone_bmp.bmp"), *stone_dark = al_load_bitmap("dark_stone_bmp.bmp");
ALLEGRO_COLOR bgColor = al_map_rgb(51, 51, 51);
al_clear_to_color(bgColor);
al_set_target_bitmap(buffer);
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 48) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 296x312 // block #1
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 48) / 2, 0); // 312x296 // block #2
al_draw_bitmap(stone_light, (al_get_display_width(screen) + 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 328x312 // block #3
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) + 16) / 2, 0); // 312x328 // block #4
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 312x312 // block #5
al_draw_bitmap(buffer, 0, 0, 0);
char stone[5] = {'l', 'l', 'l', 'l', 'l'};
ALLEGRO_EVENT event;
bool overBox[5] = {false, false, false, false, false};
while(event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
if (event.type == ALLEGRO_EVENT_MOUSE_AXES && event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
if (event.mouse.x >= 296 && event.mouse.x <= 312 && event.mouse.y >= 312 && event.mouse.y <= 328) {
overBox[0] = true;
} else if (event.mouse.x >= 312 && event.mouse.x <= 328 && event.mouse.y >= 296 && event.mouse.y <= 312) {
overBox[1] = true;
} else if (event.mouse.x >= 328 && event.mouse.x <= 344 && event.mouse.y >= 312 && event.mouse.y <= 328) {
overBox[2] = true;
} else if (event.mouse.x >= 312 && event.mouse.x <= 328 && event.mouse.y >= 328 && event.mouse.y <= 344) {
overBox[3] = true;
} else if (event.mouse.x >= 312 && event.mouse.x <= 328 && event.mouse.y >= 312 && event.mouse.y <= 328) {
overBox[4] = true;
}
if(event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
if (overBox[0] == true) {
if (stone[0] == 'l') {
al_draw_bitmap(stone_dark, (al_get_display_width(screen) - 48) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 296x312 // block #1
stone[0] = 'd';
} else if (stone[0] == 'd') {
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 48) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 296x312 // block #1
stone[0] = 'l';
}
} else if (overBox[1] == true) {
if (stone[1] == 'l') {
al_draw_bitmap(stone_dark, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 48) / 2, 0); // 312x296 // block #2
stone[1] = 'd';
} else if (stone[1] == 'd') {
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 48) / 2, 0); // 312x296 // block #2
stone[1] = 'l';
}
} else if (overBox[2] == true) {
if (stone[2] == 'l') {
al_draw_bitmap(stone_dark, (al_get_display_width(screen) + 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 328x312 // block #3
stone[2] = 'd';
} else if (stone[2] == 'd') {
al_draw_bitmap(stone_light, (al_get_display_width(screen) + 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 328x312 // block #3
stone[2] = 'l';
}
} else if (overBox[3] == true) {
if (stone[3] == 'l') {
al_draw_bitmap(stone_dark, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) + 16) / 2, 0); // 312x328 // block #4
stone[3] = 'd';
} else if (stone[3] == 'd') {
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) + 16) / 2, 0); // 312x328 // block #4
stone[3] = 'l';
}
} else if (overBox[4] == true) {
if (stone[4] == 'l') {
al_draw_bitmap(stone_dark, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 312x312 // block #5
stone[4] = 'd';
} else if (stone[4] == 'd') {
al_draw_bitmap(stone_light, (al_get_display_width(screen) - 16) / 2, (al_get_display_height(screen) - 16) / 2, 0); // 312x312 // block #5
stone[4] = 'l';
}
}
}
}
al_clear_to_color(al_map_rgb(0,0,0));
al_draw_bitmap(buffer, 0, 0, 0);
al_flip_display();
}
al_destroy_display(screen);
al_destroy_bitmap(buffer);
al_destroy_bitmap(stone_light);
al_destroy_bitmap(stone_dark);
return 0;
}
|