2004-07-26 05:42:30 UTC
previous
next
#include "allegro.h"
#include "time.h"
BITMAP *buffer;
int main(void)
{
allegro_init();
install_keyboard();
install_mouse();
set_color_depth(desktop_color_depth());
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}
// set_palette(desktop_palette);
buffer = create_bitmap_ex(desktop_color_depth(),1024,768);
srand(time(0));
BITMAP *depthsbitmap = load_bitmap("level1.bmp", NULL);
BITMAP *topviewbitmap = create_bitmap_ex(desktop_color_depth(),500,500);
BITMAP *sideviewbitmap = create_bitmap_ex(desktop_color_depth(),500,300);
for (int i = 0; i < 500; i++)
for (int j = 0; j < 500; j++)
putpixel(topviewbitmap, i, j, makecol(0, getpixel(depthsbitmap, i, j) & 0xFF, 0));
int base_x = rand() % 500;
int base_y = rand() % 500;
rectfill(topviewbitmap, base_x-5, base_y-5, base_x+5, base_y+5, makecol(0, 0, 255));
base_x += 10; base_y += 10;
for(;;) {
if (keypressed()) {
int key_code = readkey() >> 8;
if (key_code == KEY_ESC) break;
}
clear_to_color(buffer, makecol(0, 0, 0));
rect(buffer, 9, 9, 510, 510, makecol(255, 255, 255));
blit(topviewbitmap, buffer, 0, 0, 10, 10, 500, 500);
rect(buffer, 513, 457, 1014, 758, makecol(255, 255, 255));
blit(sideviewbitmap, buffer, 0, 0, 514, 458, 500, 300);
if (mouse_b & 1) {
fixed slope = fixdiv(base_y - mouse_y,base_x - mouse_x);
textprintf_ex(buffer, font, 0, 0, makecol(255, 255, 255), -1, "base: %i, %i, mouse: %i, %i, slope: %i/%i, %f", base_x, base_y, mouse_x, mouse_y, base_y - mouse_y, base_x - mouse_x, slope);
// for (int i = base_x; i == mouse
line(buffer, base_x, base_y, mouse_x, mouse_y, makecol(255, 255, 255));
circle(buffer, mouse_x, mouse_y, 7, makecol(255, 255, 255));
circlefill(buffer, mouse_x, mouse_y, 3, makecol(255, 0, 0));
} else {
circlefill(buffer, mouse_x, mouse_y, 3, makecol(255, 255, 255));
}
blit(buffer,screen,0,0,0,0,1024,768);
rest(20);
}
}
END_OF_MAIN();