void gfx_draw_rect(rect_t rect) { draw_horiz_line(rect.x, rect.y, rect.width-1); draw_horiz_line(rect.x, rect.y + rect.height-1, rect.width-1); draw_vert_line(rect.x, rect.y, rect.height); draw_vert_line(rect.x + rect.width-1, rect.y, rect.height); }
void draw_rectangle(screen_t screen,int x, int y,int x2, int y2, char col) { int x_count,y_count; if(col&FILLED) { for(y_count=y;y_count<=y2;y_count++) for(x_count=x;x_count<=x2;x_count++) put_pixel(screen,x_count,y_count,col); } else { draw_horiz_line(screen,x,y,x2,col); draw_horiz_line(screen,x,y2,x2,col); draw_vert_line(screen,x,y,y2,col); draw_vert_line(screen,x2,y,y2,col); } }
/* * redraw_room * DESCRIPTION: Draw all lines on the screen. * INPUTS: none * OUTPUTS: none * RETURN VALUE: none * SIDE EFFECTS: Draws the entire screen (but not the status bar). */ static void redraw_room () { int32_t i; /* index over rows */ /* Draw all lines in the scroll region. */ for (i = 0; i < SCROLL_Y_DIM; i++) { (void)draw_horiz_line (i); } }
/* * move_up * DESCRIPTION: Move the player up one pixel (assumed to be a legal move) * INPUTS: ypos -- pointer to player's y position (pixel) in the maze * OUTPUTS: *ypos -- reduced by one from initial value * RETURN VALUE: none * SIDE EFFECTS: pans display by one pixel when appropriate */ static void move_up (int* ypos) { /* * Move player by one pixel and check whether display should be panned. * Panning is necessary when the player moves past the upper pan border * while the top pixels of the maze are not on-screen. */ if (--(*ypos) < game_info.map_y + BLOCK_Y_DIM * PAN_BORDER && game_info.map_y > SHOW_MIN) { /* * Shift the logical view upwards by one pixel and draw the * new line. */ set_view_window (game_info.map_x, --game_info.map_y); (void)draw_horiz_line (0); } }
/* * move_photo_down * DESCRIPTION: Move background photo down one or more pixels. Amount of * motion depends on game_info.y_speed. Movement stops at * upper edge of photo. * INPUTS: none * OUTPUTS: none * RETURN VALUE: none * SIDE EFFECTS: shifts view window */ static void move_photo_down () { int32_t delta; /* Number of pixels by which to move. */ int32_t idx; /* Index over rows to redraw. */ /* Calculate the number of pixels by which to move. */ delta = (game_info.y_speed > game_info.map_y ? game_info.map_y : game_info.y_speed); /* Shift the logical view upward. */ game_info.map_y -= delta; set_view_window (game_info.map_x, game_info.map_y); /* Draw the newly exposed lines. */ for (idx = 0; delta > idx; idx++) { (void)draw_horiz_line (idx); } }
/* * prepare_maze_level * DESCRIPTION: Prepare for a maze of a given level. Fills the game_info * structure, creates a maze, and initializes the display. * INPUTS: level -- level to be used for selecting parameter values * OUTPUTS: none * RETURN VALUE: 0 on success, -1 on failure * SIDE EFFECTS: writes entire game_info structure; changes maze; * initializes display */ static int prepare_maze_level (int level) { int i; /* loop index for drawing display */ /* * Record level in game_info; other calculations use offset from * level 1. */ game_info.number = level--; /* Set per-level parameter values. */ if ((game_info.maze_x_dim = MAZE_MIN_X_DIM + 2 * level) > MAZE_MAX_X_DIM) game_info.maze_x_dim = MAZE_MAX_X_DIM; if ((game_info.maze_y_dim = MAZE_MIN_Y_DIM + 2 * level) > MAZE_MAX_Y_DIM) game_info.maze_y_dim = MAZE_MAX_Y_DIM; if ((game_info.initial_fruit_count = 1 + level / 2) > 6) game_info.initial_fruit_count = 6; if ((game_info.time_to_first_fruit = 300 - 30 * level) < 120) game_info.time_to_first_fruit = 120; if ((game_info.time_between_fruits = 300 - 60 * level) < 60) game_info.time_between_fruits = 60; if ((game_info.tick_usec = 20000 - 1750 * level) < 5000) game_info.tick_usec = 5000; /* Initialize dynamic values. */ game_info.map_x = game_info.map_y = SHOW_MIN; /* Create a maze. */ if (make_maze (game_info.maze_x_dim, game_info.maze_y_dim, game_info.initial_fruit_count) != 0) return -1; /* Set logical view and draw initial screen. */ set_view_window (game_info.map_x, game_info.map_y); for (i = 0; i < SCROLL_Y_DIM; i++) (void)draw_horiz_line (i); /* Return success. */ return 0; }
/* * move_photo_up * DESCRIPTION: Move background photo up one or more pixels. Amount of * motion depends on game_info.y_speed. Movement stops at * lower edge of photo. * INPUTS: none * OUTPUTS: none * RETURN VALUE: none * SIDE EFFECTS: shifts view window */ static void move_photo_up () { int32_t delta; /* Number of pixels by which to move. */ int32_t idx; /* Index over rows to redraw. */ /* Calculate the number of pixels by which to move. */ delta = room_photo_height (game_info.where) - SCROLL_Y_DIM - game_info.map_y; delta = (game_info.y_speed > delta ? delta : game_info.y_speed); /* Shift the logical view upward. */ game_info.map_y += delta; set_view_window (game_info.map_x, game_info.map_y); /* Draw the newly exposed lines. */ for (idx = 1; delta >= idx; idx++) { (void)draw_horiz_line (SCROLL_Y_DIM - idx); } }
/* * move_down * DESCRIPTION: Move the player right one pixel (assumed to be a legal move) * INPUTS: ypos -- pointer to player's y position (pixel) in the maze * OUTPUTS: *ypos -- increased by one from initial value * RETURN VALUE: none * SIDE EFFECTS: pans display by one pixel when appropriate */ static void move_down (int* ypos) { /* * Move player by one pixel and check whether display should be panned. * Panning is necessary when the player moves past the right pan border * while the bottom pixels of the maze are not on-screen. */ if (++(*ypos) > game_info.map_y + SCROLL_Y_DIM - BLOCK_Y_DIM * (PAN_BORDER + 1) && game_info.map_y + SCROLL_Y_DIM < (2 * game_info.maze_y_dim + 1) * BLOCK_Y_DIM - SHOW_MIN) { /* * Shift the logical view downwards by one pixel and draw the * new line. */ set_view_window (game_info.map_x, ++game_info.map_y); (void)draw_horiz_line (SCROLL_Y_DIM - 1); } }
void gfx_draw_line(int x1, int y1, int x2, int y2) { double delta, tx, ty; if (((x2 - x1) < 0)) { swap(int, x1, x2); swap(int, y1, y2); } if (((y2 - y1) < 0)) { swap(int, x1, x2); swap(int, y1, y2); } if (y1 == y2) { if (x1 > x2) { swap(int, x1, x2); } draw_horiz_line(x1, y1, x2 - x1); } else if (x1 == x2) { if (y1 > y2) { swap(int, y1, y2); } draw_vert_line(x1, y1, y2 - y1); } else if (abs(x2 - x1) > abs(y2 - y1)) { delta = ((double) (y2 - y1)) / ((double) (x2 - x1)); ty = (double) (y1); if (x1 > x2) { int i; for (i = x1; i >= x2; i--) { gfx_set_cursor(i, (int) (ty + 0.5), i, (int) (ty + 0.5)); lcd_write_data(ctx->fcolor); ty = ty - delta; } } else { int i; for (i = x1; i <= x2; i++) { gfx_set_cursor(i, (int) (ty + 0.5), i, (int) (ty + 0.5)); lcd_write_data(ctx->fcolor); ty = ty + delta; } } } else { delta = ((float) (x2 - x1)) / ((float) (y2 - y1)); tx = (float) (x1); if (y1 > y2) { int i; for (i = y2 + 1; i > y1; i--) { gfx_set_cursor((int) (tx + 0.5), i, (int) (tx + 0.5), i); lcd_write_data(ctx->fcolor); tx = tx + delta; } } else { int i; for (i = y1; i < y2 + 1; i++) { gfx_set_cursor((int) (tx + 0.5), i, (int) (tx + 0.5), i); lcd_write_data(ctx->fcolor); tx = tx + delta; } } } lcd_clr_cursor(); }