void board_redraw(const Board *self) { int idx, y, x; for (y = 0; y < self->h; ++y) for (x = 0; x < self->w; ++x) { idx = y*self->w+x; if (self->slots[idx].it == FOOD) { food_draw(self->slots[idx].f); } else { screen_putItem(self->screen, y, x, self->slots[idx].it); } } }
void board_set(Board *self, int y, int x, Item item) { int idx; if (y<0 || y>=self->h || x<0 || x>=self->w) return; idx = y*self->w+x; self->slots[idx].it = item; if (item == FOOD) { self->slots[idx].f = food_create(self, self->screen, y, x); food_draw(self->slots[idx].f); } else { food_destroy(self->slots[idx].f); self->slots[idx].f = 0; screen_putItem(self->screen, y, x, item); } }
static void disc_layer_update_callback(Layer *me, GContext *ctx) { disc_draw(ctx, &disc); food_draw(ctx, &food); }