Created
May 30, 2012 05:26
-
-
Save SpaceManiac/2833937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <vector> | |
#include <utility> | |
#include <allegro.h> | |
using namespace std; | |
volatile bool close_button_pressed = false; | |
void close_button_callback() { close_button_pressed = true; } | |
volatile int ticks = 0; | |
void tick() { ++ticks; } | |
END_OF_FUNCTION(tick); | |
int main(int argc, char* argv[]) { | |
allegro_init(); | |
install_mouse(); | |
set_color_depth(32); | |
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 300, 0, 0); | |
set_window_title("Towlrdf"); | |
enable_hardware_cursor(); | |
select_mouse_cursor(MOUSE_CURSOR_ARROW); | |
show_mouse(screen); | |
set_close_button_callback(close_button_callback); | |
// ported directly from SDL | |
vector<pair<int, int> > dots; | |
int score = 0, timer = 0; | |
int bg = makecol32(255, 255, 255); | |
BITMAP* buffer = create_bitmap(400, 300); | |
LOCK_FUNCTION(tick); | |
install_int_ex(tick, MSEC_TO_TIMER(20)); | |
while(true) { | |
if (close_button_pressed) break; | |
if (score >= 20) break; | |
if (++timer % 40 == 0) { | |
dots.push_back(make_pair(0, (3*timer+521+7*(timer%31))%300)); | |
bg = makecol32(255, 255, 255); | |
} | |
clear_to_color(buffer, bg); | |
for (size_t i = 0; i < dots.size(); ++i) { | |
putpixel(buffer, dots[i].first, dots[i].second, makecol32(0, 0, 0)); | |
dots[i].first += 1; | |
if (dots[i].first >= 400) { | |
score = 0; | |
dots.clear(); | |
bg = makecol32(0, 0, 0); | |
} | |
if(abs(dots[i].first - mouse_x) < 3 && abs(dots[i].second - mouse_y) < 3) { | |
dots.erase(dots.begin() + i); | |
++score; --i; | |
} | |
} | |
for (int a = -3; a <= 3; ++a) { | |
putpixel(buffer, mouse_x + a, mouse_y, makecol32(0, 0, 0)); | |
putpixel(buffer, mouse_x, mouse_y + a, makecol32(0, 0, 0)); | |
} | |
blit(buffer, screen, 0, 0, 0, 0, 400, 300); | |
--ticks; | |
while (ticks <= 0);// rest(0); | |
} | |
return 0; | |
} | |
END_OF_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment