bool RenderDetails_render( Context * context, RenderDetails * details, BitmapBgra * source, BitmapBgra * canvas) { bool destroy_source = false; Renderer * r = Renderer_create(context, source, canvas, details); if (r == NULL) { CONTEXT_add_to_callstack (context); if (destroy_source) { BitmapBgra_destroy(context, source); } return false; } r->destroy_details = false; r->destroy_source = destroy_source; bool result = Renderer_perform_render(context, r); if (!result) { CONTEXT_add_to_callstack (context); } Renderer_destroy(context, r); return result; }
Tetris *Tetris_create(void) { srand((unsigned int) time(NULL)); init_screen(); Tetris *tetris = malloc(sizeof(Tetris)); tetris->renderer = Renderer_create(12, 24); tetris->current_block = Block_create(); tetris->ghost_block = Block_create(); tetris->current_block->x = 5; tetris->current_block->y = 0; Block_set_type(tetris->current_block, get_random_block_type(), 0); tetris->enable_ghost_block = 1; tetris->movement_frame_counter = 0; tetris->movement_frame_delay = 10; tetris->lines_completed = 0; tetris->lines_until_level_up = 10; tetris->score = 0; tetris->level = 1; tetris->gravity_frame_counter = 0; if (tetris->level < 16) { tetris->gravity_frame_delay = (uint8_t) (16 - tetris->level); } else { tetris->gravity_frame_delay = 1; } tetris->key_left = 0; tetris->key_right = 0; tetris->key_down = 0; tetris->key_drop = 0; tetris->key_rotate = 0; tetris->key_quit = 0; tetris->key_pause = 0; tetris->key_ghost_block = 0; tetris->game_state = RUNNING; Renderer_draw_game_border(tetris->renderer); Renderer_draw_panel_labels(tetris->renderer); Renderer_draw_panel_line_counter(tetris->renderer, tetris->lines_completed); Renderer_draw_panel_score(tetris->renderer, tetris->score); Renderer_draw_panel_level(tetris->renderer, tetris->level); if (tetris->enable_ghost_block == 1) { set_ghost_block(tetris); } tetris->renderer->buffer->dirty = 1; return tetris; }