Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //menu.cpp
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_image.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/events.h>
- #include "menu.h"
- using namespace std;
- #define WHITE al_map_rgb(255, 255, 255)
- #define BLACK al_map_rgb(0, 0, 0)
- int menu() {
- //ALLEGRO_COLOR back_color = al_map_rgb(106, 90, 205);
- #define back_color al_map_rgb(230, 230, 25)
- ALLEGRO_DISPLAY* display = NULL;
- if (!al_init()) return -1;
- al_init_image_addon();
- display = al_create_display(1600, 900);
- if (!display)return -1;
- // background = al_load_bitmap(BACKGROUND_FILE);
- // if (!background)return -1;
- al_clear_to_color(al_map_rgb(0, 0, 0));
- al_install_keyboard();
- al_install_mouse();
- al_init_font_addon();
- al_init_ttf_addon();
- //wybór motywu
- int chosen_theme = choose_theme();
- //załadowanie background
- refresh(chosen_theme);
- //wybranie ilości graczy
- int n_players = choose_players(chosen_theme);
- if (n_players == 2) {
- Player player1, player2;
- Player* pl1 = &player1; Player* pl2 = &player2;
- chose_avatar(chosen_theme, pl1); write_nick(chosen_theme, pl1);
- chose_avatar(chosen_theme, pl2); write_nick(chosen_theme, pl2);
- }
- else if (n_players == 3) {
- Player player1, player2, player3;
- Player* pl1 = &player1; Player* pl2 = &player2; Player* pl3 = &player3;
- chose_avatar(chosen_theme, pl1); write_nick(chosen_theme, pl1);
- chose_avatar(chosen_theme, pl2); write_nick(chosen_theme, pl2);
- chose_avatar(chosen_theme, pl3); write_nick(chosen_theme, pl3);
- }
- else {
- Player player1, player2, player3, player4;
- Player* pl1 = &player1; Player* pl2 = &player2;
- Player* pl3 = &player3; Player* pl4 = &player4;
- chose_avatar(chosen_theme, pl1); write_nick(chosen_theme, pl1);
- chose_avatar(chosen_theme, pl2); write_nick(chosen_theme, pl2);
- chose_avatar(chosen_theme, pl3); write_nick(chosen_theme, pl3);
- chose_avatar(chosen_theme, pl4); write_nick(chosen_theme, pl4);
- }
- refresh(chosen_theme);
- al_rest(0.2);
- return n_players;
- }
- int chose_avatar(int chosen_theme, Player* obj) {
- refresh(chosen_theme);
- ALLEGRO_FONT* font_menu = al_load_ttf_font("TYPEWR__.ttf", 50, 0);
- int av1_position[2] = { 50, 400 };
- int av2_postion[2] = { 450, 400 };
- int av3_position[2] = { 850, 400 };
- int av4_position[2] = { 1250, 400 };
- int x = 300;
- int y = 400;
- ALLEGRO_BITMAP* av1 = NULL;
- ALLEGRO_BITMAP* av2 = NULL;
- ALLEGRO_BITMAP* av3 = NULL;
- ALLEGRO_BITMAP* av4 = NULL;
- if (chosen_theme == 1) {
- av1 = al_load_bitmap("Rick.jpg");
- av2 = al_load_bitmap("Morty.jpg");
- av3 = al_load_bitmap("Summer.jpg");
- av4 = al_load_bitmap("Pan_Kupkazpupki.jpg");
- char wybierz[50] = "WYBIERZ AVATARA";
- al_draw_text(font_menu, WHITE, 800, 300, ALLEGRO_ALIGN_CENTRE, wybierz);
- al_draw_bitmap(av1, av1_position[0], av1_position[1], 0);
- al_draw_bitmap(av2, av2_postion[0], av2_postion[1], 0);
- al_draw_bitmap(av3, av3_position[0], av3_position[1], 0);
- al_draw_bitmap(av4, av4_position[0], av4_position[1], 0);
- al_flip_display();
- al_rest(0.5);
- }
- else if (chosen_theme == 2) {
- av1 = al_load_bitmap("Geralt.jpeg");
- av2 = al_load_bitmap("Yen.jpeg");
- av3 = al_load_bitmap("Jaskier.jpeg");
- av4 = al_load_bitmap("Ciri.jpeg");
- char wybierz[50] = "WYBIERZ AVATARA";
- al_draw_text(font_menu, BLACK, 800, 75, ALLEGRO_ALIGN_CENTRE, wybierz);
- al_draw_bitmap(av1, av1_position[0], av1_position[1], 0);
- al_draw_bitmap(av2, av2_postion[0], av2_postion[1], 0);
- al_draw_bitmap(av3, av3_position[0], av3_position[1], 0);
- al_draw_bitmap(av4, av4_position[0], av4_position[1], 0);
- al_flip_display();
- al_rest(0.5);
- }
- else if (chosen_theme == 3) {
- av1 = al_load_bitmap("Frodo.jpeg");
- av2 = al_load_bitmap("Legolas.jpeg");
- av3 = al_load_bitmap("Gollum.jpeg");
- av4 = al_load_bitmap("Gandalf.jpeg");
- char wybierz[50] = "WYBIERZ AVATARA";
- al_draw_text(font_menu, BLACK, 800, 75, ALLEGRO_ALIGN_CENTRE, wybierz);
- al_draw_bitmap(av1, av1_position[0], av1_position[1], 0);
- al_draw_bitmap(av2, av2_postion[0], av2_postion[1], 0);
- al_draw_bitmap(av3, av3_position[0], av3_position[1], 0);
- al_draw_bitmap(av4, av4_position[0], av4_position[1], 0);
- al_flip_display();
- al_rest(0.5);
- }
- ALLEGRO_MOUSE_STATE state;
- bool done = false;
- while (!done) {
- al_get_mouse_state(&state);
- if (state.buttons & 1) {
- printf("Mouse position: (%d, %d)\n", state.x, state.y);
- if ((state.x >= av1_position[0] && state.x <= av1_position[0] + 300) &&
- (state.y >= av1_position[1] && state.y <= av1_position[1] + 400)) {
- obj->avatar = av1;
- al_destroy_bitmap(av2);
- al_destroy_bitmap(av3);
- al_destroy_bitmap(av4);
- return 1;
- }
- else if ((state.x >= av2_postion[0] && state.x <= av2_postion[0] + 300) &&
- (state.y >= av2_postion[1] && state.y <= av2_postion[1] + 400)) {
- obj->avatar = av2;
- al_destroy_bitmap(av1);
- al_destroy_bitmap(av3);
- al_destroy_bitmap(av4);
- return 1;
- }
- else if ((state.x >= av3_position[0] && state.x <= av3_position[0] + 300) &&
- (state.y >= av3_position[1] && state.y <= av3_position[1] + 400)) {
- obj->avatar = av3;
- al_destroy_bitmap(av1);
- al_destroy_bitmap(av2);
- al_destroy_bitmap(av4);
- return 1;
- }
- else if ((state.x >= av4_position[0] && state.x <= av4_position[0] + 300) &&
- (state.y >= av4_position[1] && state.y <= av4_position[1] + 400)) {
- obj->avatar = av4;
- al_destroy_bitmap(av1);
- al_destroy_bitmap(av2);
- al_destroy_bitmap(av3);
- return 1;
- }
- al_rest(0.1);
- }
- }
- return 0;
- }
- int write_nick(int chosen_theme, Player* obj) {
- refresh(chosen_theme);
- ALLEGRO_FONT* font_avatar = al_load_ttf_font("TYPEWR__.ttf", 24, 0);
- ALLEGRO_FONT* font_menu = al_load_ttf_font("TYPEWR__.ttf", 50, 0);
- char napis[50] = "WPISZ SWOJ NICK";
- if (chosen_theme == 1) {
- al_draw_text(font_menu, WHITE, 800, 75, ALLEGRO_ALIGN_CENTRE, napis);
- }else al_draw_text(font_menu, BLACK, 800, 75, ALLEGRO_ALIGN_CENTRE, napis);
- ALLEGRO_BITMAP* av = obj->avatar;
- al_draw_bitmap(av, 650, 200, 0);
- ALLEGRO_BITMAP* white = al_load_bitmap("white_rectangular.jpg");
- al_draw_bitmap(white, 600, 650, 0);
- al_flip_display();
- ALLEGRO_KEYBOARD_STATE keystate;
- ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- bool done = false;
- char nick[20];
- int i = 0;
- while (!done && i<19) {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
- switch (event.keyboard.keycode)
- {
- case ALLEGRO_KEY_A:
- nick[i] = 'a'; i++;
- break;
- case ALLEGRO_KEY_B:
- nick[i] = 'b'; i++;
- break;
- case ALLEGRO_KEY_C:
- nick[i] = 'c'; i++;
- break;
- case ALLEGRO_KEY_D:
- nick[i] = 'd'; i++;
- break;
- case ALLEGRO_KEY_E:
- nick[i] = 'e'; i++;
- break;
- case ALLEGRO_KEY_F:
- nick[i] = 'f'; i++;
- break;
- case ALLEGRO_KEY_G:
- nick[i] = 'g'; i++;
- break;
- case ALLEGRO_KEY_H:
- nick[i] = 'h'; i++;
- break;
- case ALLEGRO_KEY_I:
- nick[i] = 'i'; i++;
- break;
- case ALLEGRO_KEY_J:
- nick[i] = 'j'; i++;
- break;
- case ALLEGRO_KEY_K:
- nick[i] = 'k'; i++;
- break;
- case ALLEGRO_KEY_L:
- nick[i] = 'l'; i++;
- break;
- case ALLEGRO_KEY_M:
- nick[i] = 'm'; i++;
- break;
- case ALLEGRO_KEY_N:
- nick[i] = 'n'; i++;
- break;
- case ALLEGRO_KEY_O:
- nick[i] = 'o'; i++;
- break;
- case ALLEGRO_KEY_P:
- nick[i] = 'p'; i++;
- break;
- case ALLEGRO_KEY_Q:
- nick[i] = 'q'; i++;
- break;
- case ALLEGRO_KEY_R:
- nick[i] = 'r'; i++;
- break;
- case ALLEGRO_KEY_S:
- nick[i] = 's'; i++;
- break;
- case ALLEGRO_KEY_T:
- nick[i] = 't'; i++;
- break;
- case ALLEGRO_KEY_U:
- nick[i] = 'u'; i++;
- break;
- case ALLEGRO_KEY_V:
- nick[i] = 'v'; i++;
- break;
- case ALLEGRO_KEY_W:
- nick[i] = 'w'; i++;
- break;
- case ALLEGRO_KEY_X:
- nick[i] = 'x'; i++;
- break;
- case ALLEGRO_KEY_Y:
- nick[i] = 'y'; i++;
- break;
- case ALLEGRO_KEY_Z:
- nick[i] = 'z'; i++;
- break;
- case ALLEGRO_KEY_BACKSPACE:
- i--; nick[i] = NULL;
- break;
- case ALLEGRO_KEY_ESCAPE:
- done = true;
- break;
- case ALLEGRO_KEY_ENTER:
- done = true;
- break;
- }
- al_draw_bitmap(white, 600, 650, 0);
- al_draw_text(font_avatar, BLACK, 620, 660, ALLEGRO_ALIGN_LEFT, nick);
- al_flip_display();
- al_rest(0.2);
- }
- }
- al_flip_display();
- al_destroy_event_queue(event_queue);
- obj->nick = nick;
- al_rest(0.2);
- return 0;
- }
- void refresh(int chosen_theme) {
- #define rick_morty_b "rick_back2.jpg"
- #define witcher_b "witcher_back2.jpg"
- #define lord_rings_b "lord_back2.jpg"
- ALLEGRO_BITMAP* rick_b = NULL;
- ALLEGRO_BITMAP* witch_b = NULL;
- ALLEGRO_BITMAP* lord_b = NULL;
- rick_b = al_load_bitmap(rick_morty_b);
- witch_b = al_load_bitmap(witcher_b);
- lord_b = al_load_bitmap(lord_rings_b);
- switch (chosen_theme) {
- case 1:
- al_draw_bitmap(rick_b, 0, 0, 0);
- break;
- case 2:
- al_draw_bitmap(witch_b, 0, 0, 0);
- break;
- case 3:
- al_draw_bitmap(lord_b, 0, 0, 0);
- break;
- default: break;
- }
- al_flip_display();
- }
- int choose_players(int chosen_theme) {
- #define B2 "button_2.png"
- #define B3 "button_3.png"
- #define B4 "button_4.png"
- ALLEGRO_BITMAP* b2 = NULL;
- ALLEGRO_BITMAP* b3 = NULL;
- ALLEGRO_BITMAP* b4 = NULL;
- ALLEGRO_FONT* font_menu = al_load_ttf_font("TYPEWR__.ttf", 50, 0);
- b2 = al_load_bitmap(B2);
- b3 = al_load_bitmap(B3);
- b4 = al_load_bitmap(B4);
- int by = 500;
- int b2x = 350;
- int b3x = 750;
- int b4x = 1150;
- char napis[50] = "WYBIERZ ILOSC GRACZY";
- switch (chosen_theme) {
- case 1:
- al_draw_text(font_menu, WHITE, 800, 700, ALLEGRO_ALIGN_CENTRE, napis);
- break;
- case 2:
- al_draw_text(font_menu, BLACK, 800, 75, ALLEGRO_ALIGN_CENTRE, napis);
- break;
- case 3:
- al_draw_text(font_menu, BLACK, 800, 75, ALLEGRO_ALIGN_CENTRE, napis);
- break;
- default: break;
- }
- al_draw_bitmap(b2, b2x, by, 0);
- al_draw_bitmap(b3, b3x, by, 0);
- al_draw_bitmap(b4, b4x, by, 0);
- // szerokość 800, wysokość 600
- al_flip_display();
- ALLEGRO_MOUSE_STATE state;
- bool done = false;
- while (!done) {
- al_get_mouse_state(&state);
- if (state.buttons & 1) {
- printf("Mouse position: (%d, %d)\n", state.x, state.y);
- if ((state.x >= b2x && state.x <= b2x + 100) &&
- (state.y >= by && state.y <= by + 100)) {
- return 2;
- }
- else if ((state.x >= b3x && state.x <= b3x + 100) &&
- (state.y >= by && state.y <= by + 100)) {
- return 3;
- }
- else if ((state.x >= b4x && state.x <= b4x + 100) &&
- (state.y >= by && state.y <= by + 100)) {
- return 4;
- }
- }
- al_rest(0.1);
- }
- return 0;
- }
- int choose_theme() {
- #define rick_morty "rick_and_morty.jpg"
- #define witcher "witcher.jpg"
- #define lord_rings "lord_rings.jpg"
- ALLEGRO_BITMAP* rick = NULL;
- ALLEGRO_BITMAP* witch = NULL;
- ALLEGRO_BITMAP* lord = NULL;
- ALLEGRO_FONT* font_menu = al_load_ttf_font("TYPEWR__.ttf", 50, 0);
- rick = al_load_bitmap(rick_morty);
- witch = al_load_bitmap(witcher);
- lord = al_load_bitmap(lord_rings);
- int rick_position[2] = { 250, 500 };
- int witcher_postion[2] = { 1050, 500 };
- int lord_position[2] = { 650, 500 };
- char wybierz[50] = "WYBIERZ MOTYW GRY";
- al_draw_text(font_menu, WHITE, 800, 300, ALLEGRO_ALIGN_CENTRE, wybierz);
- al_draw_bitmap(rick, rick_position[0], rick_position[1], 0);
- al_draw_bitmap(witch, witcher_postion[0], witcher_postion[1], 0);
- al_draw_bitmap(lord, lord_position[0], lord_position[1], 0);
- // szerokość 800, wysokość 600
- al_flip_display();
- al_destroy_bitmap(rick);
- al_destroy_bitmap(witch);
- al_destroy_bitmap(lord);
- ALLEGRO_MOUSE_STATE state;
- bool done = false;
- while (!done) {
- al_get_mouse_state(&state);
- if (state.buttons & 1) {
- printf("Mouse position: (%d, %d)\n", state.x, state.y);
- if ((state.x >= rick_position[0] && state.x <= rick_position[0] + 300) &&
- (state.y >= rick_position[1] && state.y <= rick_position[1] + 113)) {
- cout << "Wybrano rick and morty";
- return 1;
- }
- else if ((state.x >= witcher_postion[0] && state.x <= witcher_postion[0] + 299) &&
- (state.y >= witcher_postion[1] && state.y <= witcher_postion[1] + 113)) {
- cout << "Wybrano wiedzmin";
- return 2;
- }
- else if ((state.x >= lord_position[0] && state.x <= lord_position[0] + 300) &&
- (state.y >= lord_position[1] && state.y <= lord_position[1] + 92)) {
- cout << "Wybrano lord of the rings";
- return 3;
- }
- }
- al_rest(0.1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement