/* void draw_moving_wall() * draw moving wall. */ void draw_moving_wall() { /* x way moving wall difinition */ typedef struct { uint32_t x; uint32_t y; int32_t vx; char str[4]; } x_move_wall_t; static x_move_wall_t s_x_wall = { 4, 3, 1, "---" }; /* movement */ s_x_wall.x += s_x_wall.vx; /* collision judgement */ if (s_x_wall.vx > 0) { /* right edge collison */ if (get_screen_cache(s_x_wall.x + s_x_wall.vx + 2, s_x_wall.y) == '+') s_x_wall.vx *= -1; } else { /* left edge collison */ if (get_screen_cache(s_x_wall.x + s_x_wall.vx, s_x_wall.y) == '+') s_x_wall.vx *= -1; } /* draw */ set_screen_cache(s_x_wall.x, s_x_wall.y, s_x_wall.str[0]); set_screen_cache(s_x_wall.x + 1, s_x_wall.y, s_x_wall.str[1]); set_screen_cache(s_x_wall.x + 2, s_x_wall.y, s_x_wall.str[2]); }
/* void draw_moving_wall(ball_t*) * draw moving wall. */ void draw_moving_wall() { /* x way moving wall difinition */ typedef struct { uint32_t x; uint32_t y; int32_t vx; int32_t vy; char str[4]; } move_wall_t; uint32_t i = 0; static uint8_t s_first_flag = 1; static move_wall_t s_x_walls[X_WALL_NUM]; /* set movement of walls */ for (i = 0; i < X_WALL_NUM; i++) { if (s_first_flag == 1) { s_x_walls[i].x = 5 * i + 5; s_x_walls[i].y = 3 * i + 1; s_x_walls[i].vx = 1; s_x_walls[i].str[0] = g_cache.fg; s_x_walls[i].str[1] = g_cache.fg; s_x_walls[i].str[2] = g_cache.fg; } /* movement */ s_x_walls[i].x += s_x_walls[i].vx; /* collision judgement */ if (s_x_walls[i].vx > 0) { /* right edge collison */ if (get_screen_cache( &g_cache, s_x_walls[i].x + s_x_walls[i].vx + sizeof(s_x_walls[i].str) - 2, s_x_walls[i].y) == g_cache.fg) s_x_walls[i].vx *= -1; } else { /* left edge collison */ if (get_screen_cache( &g_cache, s_x_walls[i].x + s_x_walls[i].vx, s_x_walls[i].y) == g_cache.fg) s_x_walls[i].vx *= -1; } /* draw */ set_screen_cache( &g_cache, s_x_walls[i].x, s_x_walls[i].y, s_x_walls[i].str[0]); set_screen_cache( &g_cache, s_x_walls[i].x + 1, s_x_walls[i].y, s_x_walls[i].str[1]); set_screen_cache( &g_cache, s_x_walls[i].x + 2, s_x_walls[i].y, s_x_walls[i].str[2]); } s_first_flag = 0; }
void set_last_screen(u64 id, screen_t * scr) { screen_cache * cache = get_screen_cache(id); assert((scr == nullptr) || (cache->last_screen != scr)); cache->last_screen = scr; if (scr) { const codepoint_info_s * first_cpinfo; screen_get_first_cpinfo(scr, &first_cpinfo); cache->start_offset = first_cpinfo->offset; } }
/* void control_ball(ball_t*) * draw ball bounding on wall. */ void control_ball() { /* charactor data definition */ typedef struct { uint32_t x; uint32_t y; int32_t vx; int32_t vy; char c; } ball_t; static ball_t s_ball; static uint8_t s_first_flag = 1; /* initialize s_ball */ if (s_first_flag == 1) { s_ball.x = 6; s_ball.y = 4; s_ball.vx = 1; s_ball.vy = -1; s_ball.c = '*'; s_first_flag = 0; } /* movement */ s_ball.x += s_ball.vx; s_ball.y += s_ball.vy; /* collision judgement */ if (get_screen_cache(&g_cache, s_ball.x + s_ball.vx, s_ball.y) == g_cache.fg) s_ball.vx *= -1; if (get_screen_cache(&g_cache, s_ball.x, s_ball.y + s_ball.vy) == g_cache.fg) s_ball.vy *= -1; if (s_ball.vx * s_ball.vy > 0) s_ball.c = '\\'; else s_ball.c = '/'; /* draw */ set_screen_cache(&g_cache, s_ball.x, s_ball.y, s_ball.c); }
screen_t * get_new_screen_by_id(u64 screen_id) { auto cache = get_screen_cache(screen_id); if (!cache) { assert(0); return nullptr; } screen_t * scr = nullptr; screen_alloc_with_dimension(&scr, __PRETTY_FUNCTION__, &cache->dim); assert(scr); screen_set_start_offset(scr, cache->start_offset); return scr; }
screen_t * get_last_screen(u64 id) { screen_cache * cache = get_screen_cache(id); assert(cache); return cache->last_screen; }