Skip to content

Instantly share code, notes, and snippets.

@creikey
Created April 7, 2018 07:53
Show Gist options
  • Save creikey/35a9c08ff3a726a80ff2b912f1da7568 to your computer and use it in GitHub Desktop.
Save creikey/35a9c08ff3a726a80ff2b912f1da7568 to your computer and use it in GitHub Desktop.
#include <allegro5/allegro.h>
#include <iostream>
class Vector {
public:
Vector(int x, int y);
Vector();
Vector operator+(Vector &);
private:
int x;
int y;
};
class Drawable {
public:
virtual void draw() = 0;
virtual void update() = 0;
};
class ALSystem {
private:
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *queue = NULL;
ALLEGRO_COLOR clearcol;
public:
ALSystem(int xres, int yres, ALLEGRO_COLOR col);
ALSystem();
~ALSystem();
void MainLoop();
};
class Square : public Drawable {
public:
void draw();
void update();
private:
Vector pos;
Vector size;
};
ALSystem::ALSystem(int xres, int yres, ALLEGRO_COLOR col) {
// Make allegro functions available
al_init();
// Create a display for future drawing
this->display = al_create_display(xres, yres);
if (!this->display) {
throw "Failed to create display";
}
// To detect events such as closing the window
this->queue = al_create_event_queue();
if (!this->queue) {
throw "Failed to create event queue";
}
// To have the same color bg
this->clearcol = col;
al_clear_to_color(this->clearcol);
}
ALSystem::~ALSystem() {
al_destroy_display(this->display);
al_destroy_event_queue(this->queue);
}
void ALSystem::MainLoop() {}
int main(int argc, char **argv) {
try {
ALSystem sys(500, 500, al_map_rgb(0, 0, 0));
} catch (const char *errmsg) {
std::cerr << "ERROR WHILE INITIALIZING SYSTEM: " << errmsg << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment