void Alleg4Surface::setDrawMode(DrawMode mode, int param, const gfx::Color a, const gfx::Color b) { switch (mode) { case DrawMode::Solid: checked_mode(-1); break; case DrawMode::Xor: xor_mode(TRUE); break; case DrawMode::Checked: checked_mode(param, a, b); break; } }
/* moves a sprite along the spline path */ void walk(void) { #define MAX_POINTS 256 int points[8]; int x[MAX_POINTS], y[MAX_POINTS]; int n, i; int npoints; int ox, oy; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); for (i=1; i<node_count-1; i++) draw_node(i); release_screen(); do { poll_mouse(); } while (mouse_b); clear_keybuf(); ox = -16; oy = -16; xor_mode(TRUE); for (n=1; n < node_count-2; n++) { npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4; if (npoints < 1) npoints = 1; else if (npoints > MAX_POINTS) npoints = MAX_POINTS; get_control_points(nodes[n], nodes[n+1], points); calc_spline(points, npoints, x, y); for (i=1; i<npoints; i++) { vsync(); acquire_screen(); circlefill(screen, ox, oy, 6, palette_color[2]); circlefill(screen, x[i], y[i], 6, palette_color[2]); release_screen(); ox = x[i]; oy = y[i]; poll_mouse(); if ((keypressed()) || (mouse_b)) goto getout; } } getout: xor_mode(FALSE); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }
/* what a pointless way to spend my Sunday afternoon :-) */ static int worms() { #define MAX_SIZE 65536 int *xpos = malloc(sizeof(int)*MAX_SIZE); int *ypos = malloc(sizeof(int)*MAX_SIZE); int head, tail, dir, dead, quit, score, counter; int tx, ty, x, y, i, c1, c2, c3; again: head = 0; tail = 0; dir = 0; dead = FALSE; quit = FALSE; score = 0; counter = 0; tx = -100; ty = -100; show_mouse(NULL); if (bitmap_color_depth(screen) <= 8) { PALETTE pal; get_palette(pal); pal[0].r = 0; pal[0].g = 0; pal[0].b = 0; pal[1].r = 31; pal[1].g = 31; pal[1].b = 31; pal[254].r = 31; pal[254].g = 31; pal[254].b = 31; pal[255].r = 63; pal[255].g = 63; pal[255].b = 63; set_palette(pal); c1 = 0; c2 = 1; c3 = 255; } else { c1 = gui_fg_color; c2 = gui_mg_color; c3 = gui_bg_color; } clear_to_color(screen, c1); xor_mode(TRUE); xpos[0] = SCREEN_W/2; ypos[0] = SCREEN_H/2; putpixel(screen, xpos[0], ypos[0], c3); while ((!dead) && (!quit)) { x = xpos[head]; y = ypos[head]; switch (dir) { case 0: x++; break; case 1: y++; break; case 2: x--; break; case 3: y--; break; } if (x >= SCREEN_W) x -= SCREEN_W; else if (x < 0) x += SCREEN_W; if (y >= SCREEN_H) y -= SCREEN_H; else if (y < 0) y += SCREEN_H; head++; if (head >= MAX_SIZE) head = 0; xpos[head] = x; ypos[head] = y; counter++; if (counter & 15) { putpixel(screen, xpos[tail], ypos[tail], c3); tail++; if (tail >= MAX_SIZE) tail = 0; } i = tail; while (i != head) { if ((x == xpos[i]) && (y == ypos[i])) { dead = TRUE; break; } i++; if (i >= MAX_SIZE) i = 0; } if (!(counter % (1+(score+2)/3))) vsync(); putpixel(screen, x, y, c3); if ((tx < 0) || (ty < 0)) { do { tx = 16+random()%(SCREEN_W-32); ty = 16+random()%(SCREEN_H-32); } while ((ABS(x-tx)+ABS(y-ty)) < 64); circle(screen, tx, ty, 8, c2); circle(screen, tx, ty, 5, c2); circle(screen, tx, ty, 2, c2); } if ((ABS(x-tx)+ABS(y-ty)) < 9) { circle(screen, tx, ty, 8, c2); circle(screen, tx, ty, 5, c2); circle(screen, tx, ty, 2, c2); tx = -100; ty = -100; score++; } text_mode(c1); textprintf(screen, font, 0, 0, c2, "Score: %d", score); if (keypressed()) { switch (readkey()>>8) { case KEY_RIGHT: dir = 0; break; case KEY_DOWN: dir = 1; break; case KEY_LEFT: dir = 2; break; case KEY_UP: dir = 3; break; case KEY_ESC: quit = TRUE; break; } } } xor_mode(FALSE); clear_to_color(screen, gui_fg_color); set_palette(datedit_current_palette); do { } while ((key[KEY_ESC]) || (key[KEY_RIGHT]) || (key[KEY_LEFT]) || (key[KEY_UP]) || (key[KEY_DOWN])); clear_keybuf(); show_mouse(screen); if (dead) { char buf[64]; sprintf(buf, "Score: %d", score); if (alert(buf, NULL, NULL, "Play", "Quit", 'p', 'q') == 1) goto again; } free(xpos); free(ypos); return D_REDRAW; }