Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_image.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/allegro_primitives.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- const int SCREEN_W = 640;
- const int SCREEN_H = 480;
- const float FPS = 60.0;
- const int yVel = 50;
- int main()
- {
- int fps = 0, fps_accum = 0;
- double fps_time = 0;
- int lvlX = SCREEN_W / 2 - 24, lvlY = 0, lvlNum = 1;
- string level = "Level ";
- ofstream outfile;
- outfile.open("level.out");
- if(!al_init())
- {
- cout << "Failed to init allegro\n";
- }
- if(!al_install_keyboard())
- {
- cout << "Failed to install keyboad\n";
- }
- if(!al_init_primitives_addon())
- {
- cout << "Failed to init primitives addon\n";
- }
- if(!al_init_image_addon())
- {
- cout << "Failed to init image addon\n";
- }
- al_init_font_addon();
- al_init_ttf_addon();
- ALLEGRO_DISPLAY *display;
- ALLEGRO_EVENT_QUEUE *event_queue;
- ALLEGRO_TIMER *timer;
- ALLEGRO_FONT *fnt, *lvltxt;
- fnt = al_load_ttf_font("pirulen.ttf", 12, 0);
- lvltxt = fnt;
- bool doexit = false;
- bool redraw = false;
- timer = al_create_timer(1.0/FPS);
- display = al_create_display(SCREEN_W, SCREEN_H);
- event_queue = al_create_event_queue();
- //al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, 1);
- al_set_window_title(display, "Scrolling Text");
- al_set_window_position(display, 20, 20);
- al_register_event_source(event_queue, al_get_display_event_source(display));
- al_register_event_source(event_queue, al_get_timer_event_source(timer));
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- al_clear_to_color(al_map_rgb(0, 0, 0));
- al_flip_display();
- al_start_timer(timer);
- while(!doexit)
- {
- ALLEGRO_EVENT ev;
- al_wait_for_event(event_queue, &ev);
- if(ev.type == ALLEGRO_EVENT_TIMER)
- {
- // logic
- if(lvlY < 0 || lvlY > SCREEN_H)
- {
- lvlY = 0;
- outfile << level << " " << lvlNum << endl;
- lvlNum++;
- }
- else lvlY += yVel;
- redraw = true;
- }
- else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
- {
- break;
- }
- else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
- {
- switch(ev.keyboard.keycode)
- {
- break;
- }
- }
- else if(ev.type == ALLEGRO_EVENT_KEY_UP)
- {
- switch(ev.keyboard.keycode)
- {
- case ALLEGRO_KEY_ESCAPE:
- doexit = true;
- break;
- }
- }
- if(redraw && al_is_event_queue_empty(event_queue))
- {
- redraw = false;
- al_clear_to_color(al_map_rgb(0, 0, 0));
- double t = al_get_time();
- // draw map code here
- al_draw_filled_rounded_rectangle(4, 4, 100, 22, 8, 8, al_map_rgb(255, 0, 255));
- al_draw_textf(fnt, al_map_rgb(255, 255, 255), 8, 8, 0, "FPS: %d", fps);
- al_draw_textf(lvltxt, al_map_rgb(255, 255, 255), lvlX, lvlY, 0, "Level %d", lvlNum);
- al_flip_display();
- fps_accum++;
- if(t - fps_time >= 1)
- {
- fps = fps_accum;
- fps_accum = 0;
- fps_time = t;
- }
- }
- }
- outfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment