Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_native_dialog.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_primitives.h>
- #include <allegro5/allegro_image.h>
- #include <allegro5/allegro_audio.h>
- #include <allegro5/allegro_acodec.h>
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <cmath>
- #include <stdlib.h>
- using namespace std;
- #define ScreenWidth 1366
- #define ScreenHeight 768
- unsigned int dist(int a, int b,int c,int d)
- {
- return sqrt(pow(a - c, 2) + pow(b - d, 2));
- }
- int main() {
- if (!al_init())
- {
- al_show_native_message_box(NULL, NULL, NULL, "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR);
- return -1;
- }
- al_set_new_display_flags(ALLEGRO_FULLSCREEN);
- char c[32] = "caca";
- char c2[32];
- bool redraw = true;
- ALLEGRO_DISPLAY *display;
- //song
- display = al_create_display(ScreenWidth, ScreenHeight);
- if (!display)
- {
- al_show_native_message_box(display, "Sample Title", "Display Settings", "Display problems", NULL, ALLEGRO_MESSAGEBOX_ERROR);
- return -1;
- }
- al_init_font_addon();
- al_init_ttf_addon();
- ALLEGRO_FONT *font = al_load_font("orange juice.ttf", 72, NULL);
- ALLEGRO_FONT *font2 = al_load_font("beer money.ttf", 72, NULL);
- long sec = 0;
- long score = 0;
- long clicked = 0;
- //keyboard
- al_init_primitives_addon();
- al_install_keyboard();
- al_install_mouse();
- al_install_audio();
- al_init_image_addon();
- al_init_acodec_addon();
- //
- //image
- ALLEGRO_BITMAP *player = al_load_bitmap("Aim.png");
- ALLEGRO_BITMAP *player2 = al_load_bitmap("Like.png");
- //timer
- bool done = false, draw = true;
- int x = 10, y = 10, moveSpeed = 5, x2=rand()%1200,y2=rand()%700;
- ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
- ALLEGRO_TIMER *timer = al_create_timer(1.0 / 30);
- ALLEGRO_TIMER *timer2 = al_create_timer(1.0);
- al_reserve_samples(1);
- ALLEGRO_SAMPLE *song = al_load_sample("salam.ogg");
- ALLEGRO_SAMPLE_INSTANCE *songInstance = al_create_sample_instance(song);
- al_set_sample_instance_playmode(songInstance, ALLEGRO_PLAYMODE_LOOP);
- al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer());
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- al_register_event_source(event_queue, al_get_mouse_event_source());
- al_register_event_source(event_queue, al_get_timer_event_source(timer));
- al_register_event_source(event_queue, al_get_timer_event_source(timer2));
- int dir = 0;
- al_play_sample_instance(songInstance);
- al_start_timer(timer);
- al_start_timer(timer2);
- al_hide_mouse_cursor(display);
- while (!done) {
- ALLEGRO_EVENT events;
- al_wait_for_event(event_queue, &events);
- switch (events.keyboard.keycode) {
- case ALLEGRO_KEY_DOWN:
- dir = 1; break;
- case ALLEGRO_KEY_UP:
- dir = 2; break;
- case ALLEGRO_KEY_RIGHT:
- dir = 3; break;
- case ALLEGRO_KEY_LEFT:
- dir = 4; break;
- case ALLEGRO_KEY_ESCAPE:
- {done = true; break; }
- }
- if (events.type == ALLEGRO_EVENT_MOUSE_AXES)
- {
- x = events.mouse.x;
- y = events.mouse.y;
- }
- if (events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
- {
- if (events.mouse.button & 1)
- {
- if (dist(x, y, x2, y2) < 20)
- score++;
- }
- if (events.mouse.button & 2)
- {
- if (dist(x, y, x2, y2) < 20)
- score += 2;
- }
- }
- if (events.type == ALLEGRO_EVENT_TIMER)
- {
- if (events.timer.source == timer)
- {
- sprintf_s(c, "%d/%d", sec, dist(x, y, x2, y2));
- sprintf_s(c2, "Score: %d", score);
- al_draw_bitmap(player2, x2, y2, ALLEGRO_FLIP_HORIZONTAL);
- al_draw_bitmap(player, x, y, ALLEGRO_FLIP_HORIZONTAL);
- al_draw_text(font, al_map_rgb(44, 127, 255), ScreenWidth / 2, ScreenHeight / 2, ALLEGRO_ALIGN_CENTER, c);
- al_draw_text(font2, al_map_rgb(44, 127, 255), ScreenWidth / 2, (ScreenHeight / 2)-200, ALLEGRO_ALIGN_CENTER, c2);
- }
- if (events.timer.source == timer2)
- {
- sec++;
- if (sec >= 5)
- {
- x2 = rand() % 1200;
- y2 = rand() % 700;
- sec = 0;
- clicked = 0;
- }
- }
- redraw = true;
- }
- else if (events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
- break;
- }
- if (redraw&&al_is_event_queue_empty(event_queue)) {
- redraw = false;
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- }
- //
- }
- al_destroy_timer(timer);
- al_destroy_bitmap(player);
- al_destroy_bitmap(player2);
- al_destroy_font(font);
- al_destroy_font(font2);
- al_destroy_sample(song);
- al_destroy_sample_instance(songInstance);
- al_destroy_display(display);
- al_destroy_event_queue(event_queue);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement