int main(void) { initscr(); cbreak(); curs_set(0); nodelay(stdscr, TRUE); sleep(1); int y, x; getmaxyx(stdscr, y, x); /* _shape *box = create_shape_box(5, 5, y/2, x/2); draw_stuff(box);*/ _shape_book *s_book = create_box_system(5, 2); draw_stuff(s_book); while (getch() != 'q') { move_shape(s_book); draw_stuff(s_book); usleep(95000); } endwin(); return 0; }
int main(void) { allegro_init(); install_timer(); install_keyboard(); rgb_map = malloc(sizeof(RGB_MAP)); create_rgb_table(rgb_map, desktop_palette, NULL); set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0); buffer = create_bitmap(SCREEN_W, SCREEN_H); set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); init_shape(); while (!key[KEY_ESC]) { move_shape(); translate_shape(); vsync(); draw(); } destroy_bitmap(buffer); free(rgb_map); allegro_exit(); return 0; }
gint timeout(gpointer data) { if (!(move_shape(0, 1, 0))) { detect_lines(); if (!new_shape()) { return 0; } } g_timeout_add(500, timeout, NULL); return 0; }
gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data) { switch (event->keyval) { case GDK_Left: move_shape(-1, 0, 0); break; case GDK_Right: move_shape(1, 0, 0); break; case GDK_Up: move_shape(0, 0, 1); break; case GDK_Down: move_shape(0, 1, 0); break; case GDK_KEY_space: move_shape_to_bottom(); break; } return TRUE; }
void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode) { GdkScreen *screen = gdk_screen_get_default(); gint n_monitors = gdk_screen_get_n_monitors(screen); gint pick = get_int_option("monitor"); if (pick < 0 || pick >= n_monitors) pick = random() % n_monitors; GdkRectangle geom; gdk_screen_get_monitor_geometry(screen, pick, &geom); xcowsay.screen_width = geom.width; xcowsay.screen_height = geom.height; g_assert(xcowsay.cow_pixbuf); xcowsay.cow = make_shape_from_pixbuf(xcowsay.cow_pixbuf); switch (mode) { case COWMODE_NORMAL: case COWMODE_THINK: normal_setup(text, debug, mode); break; case COWMODE_DREAM: dream_setup(text, debug); break; default: fprintf(stderr, "Error: Unsupported cow mode %d\n", mode); exit(1); } xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf); int total_width = shape_width(xcowsay.cow) + get_int_option("bubble_x") + xcowsay.bubble_width; int total_height = max(shape_height(xcowsay.cow), xcowsay.bubble_height); int bubble_off = max((xcowsay.bubble_height - shape_height(xcowsay.cow))/2, 0); int area_w = xcowsay.screen_width - total_width; int area_h = xcowsay.screen_height - total_height; // Fit the cow on the screen as best as we can // The area can't be be zero or we'd get an FPE if (area_w < 1) area_w = 1; if (area_h < 1) area_h = 1; int cow_x = get_int_option("at_x"); if (cow_x < 0) cow_x = random() % area_w; else if (cow_x >= area_w) cow_x = area_w - 1; int cow_y = get_int_option("at_y"); if (cow_y < 0) cow_y = random() % area_h; else if (cow_y >= area_h) cow_y = area_h - 1; if (get_bool_option("left")) { move_shape(xcowsay.cow, geom.x + cow_x + xcowsay.bubble_width, geom.y + bubble_off + cow_y); show_shape(xcowsay.cow); int bx = shape_x(xcowsay.cow) - xcowsay.bubble_width + get_int_option("bubble_x"); int by = shape_y(xcowsay.cow) + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2 + get_int_option("bubble_y"); move_shape(xcowsay.bubble, bx, by); } else { move_shape(xcowsay.cow, geom.x + cow_x, geom.y + bubble_off + cow_y); show_shape(xcowsay.cow); int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow) + get_int_option("bubble_x"); int by = shape_y(xcowsay.cow) + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2 + get_int_option("bubble_y"); move_shape(xcowsay.bubble, bx, by); } xcowsay.state = csLeadIn; xcowsay.transition_timeout = get_int_option("lead_in_time"); g_timeout_add(TICK_TIMEOUT, tick, NULL); close_when_clicked(xcowsay.cow); if (run_main) gtk_main(); g_object_unref(xcowsay.bubble_pixbuf); xcowsay.bubble_pixbuf = NULL; }
void move_shape_to_bottom(void) { while (move_shape(0, 1, 0)); }