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_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <allegro5/allegro_primitives.h>
- #include <cstdlib>
- #include <time.h>
- #include <stdio.h>
- #include <iostream>
- #include "I:\Software Stuff\C++ Code\Allegro\Game\Game\old.h"
- //#include "old.h"
- using namespace std;
- #define xDisplay 1000
- #define yDisplay 600
- #define maxFrameRate 60
- #define windowFrameMode ALLEGRO_NOFRAME
- class Core
- {
- private:
- ALLEGRO_DISPLAY *mainDisplay; // This is a pointer for the display!
- public:
- void makeWindow(int);
- void drawShit();
- void testKeys();
- };
- void Core::makeWindow(int mode)
- {
- // Use mode 1 to make and mode 0 to break window
- if(mode == 1)
- {
- // This is a catch of sorts to grab errors
- if(!al_init()) // This if statment is needed for some fucking real cuz yeah it is fucked and shit like that
- {
- al_show_native_message_box(NULL,NULL,NULL,"ERROR",NULL,NULL);
- }
- al_set_new_display_flags(windowFrameMode); // Uses the windowFrameModes
- mainDisplay = al_create_display(xDisplay,yDisplay); // This sets the size of the windows and uses the defines
- al_set_new_display_refresh_rate(maxFrameRate); // This is the FPS thing
- al_set_window_title(mainDisplay,"Atton's Testing Ground");
- }
- if(mode == 0)
- {
- al_destroy_display(mainDisplay);
- }
- }
- void Core::drawShit()
- {
- int x1(400);
- int y1(400);
- int x2(450);
- int y2(500);
- al_init_primitives_addon(); // This calls the draw functions
- ALLEGRO_COLOR electricBlue = al_map_rgb(44,117,255);
- while(true)
- {
- cin >> x1 >> y1 >> x2 >> y2;
- //cout << x1 << y1 << x2 << y2 << endl;
- //al_draw_rectangle(400,400,450,500,electricBlue,1.0);
- al_draw_rectangle(x1,y1,x2,y2,electricBlue,1.0);
- al_draw_line(x1,y1,x2,y2,electricBlue,1.0);
- al_flip_display();
- al_rest(0.016);
- }
- }
- void Core::testKeys()
- {
- al_install_keyboard();
- al_init_primitives_addon();
- ALLEGRO_COLOR electricBlue = al_map_rgb(44,117,255);
- ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
- ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60);
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- al_register_event_source(event_queue, al_get_timer_event_source(timer));
- enum Direction{UP,DOWN,LEFT,RIGHT};
- bool done = false;
- bool draw = false;
- int x = 10;
- int y = 10;
- int moveSpeed = 5;
- int dir = DOWN;
- al_start_timer(timer);
- while(!done)
- {
- ALLEGRO_EVENT events;
- al_wait_for_event(event_queue, &events);
- if(events.type == ALLEGRO_EVENT_KEY_DOWN)
- {
- switch(events.keyboard.keycode)
- {
- case ALLEGRO_KEY_DOWN:
- dir = DOWN;
- break;
- case ALLEGRO_KEY_UP:
- dir = UP;
- break;
- case ALLEGRO_KEY_RIGHT:
- dir = RIGHT;
- break;
- case ALLEGRO_KEY_LEFT:
- dir = LEFT;
- case ALLEGRO_KEY_ESCAPE:
- //done = true;
- break;
- }
- if(events.type == ALLEGRO_EVENT_TIMER)
- {
- switch(dir)
- {
- case DOWN:
- y+= moveSpeed;
- break;
- case UP:
- y -= moveSpeed;
- break;
- case RIGHT:
- x+= moveSpeed;
- break;
- case LEFT:
- x-= moveSpeed;
- break;
- draw = true;
- }
- }
- }
- if(draw)
- {
- draw = false;
- al_draw_rectangle(x,y,x + 20,y + 20,electricBlue,2.0);
- al_flip_display();
- //al_clear_to_color(al_map_rgb(0,0,0));
- }
- }
- makeWindow(0);
- al_destroy_event_queue(event_queue);
- }
- int main(int argc, char **argv)
- {
- Core Function;
- Function.makeWindow(1);
- //getSystemInfo();
- //getSystemInfo();
- Function.testKeys();
- cout << "OP DONE" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment