/* draws everything else */ void draw_1dtetris (TWidget *wid, ttk_surface srf) { char buffer[8]; if (score == 0) snprintf(buffer, 8, "%d", score); else snprintf(buffer, 8, "%d00", score); // draw playfield ttk_fillrect (srf, 0, 0, w, HWH, ttk_makecol(BLACK)); ttk_rect (srf, pf_x, 6, pf_x+pf_w, 6+pf_h, ttk_makecol(WHITE)); ttk_line (srf, pf_x+1, 6, pf_x+pf_w-2, 6, ttk_makecol(BLACK)); // draw next frame ttk_rect (srf, nf_x, nf_y, nf_x+nf_w, nf_y+nf_h, ttk_makecol(WHITE)); ttk_text (srf, ttk_textfont, nf_x+1, nf_y-ttk_text_height(ttk_textfont), ttk_makecol(WHITE), "next"); // draw score frame ttk_rect (srf, sf_x, nf_y, sf_x+sf_w, nf_y+nf_w, ttk_makecol(WHITE)); ttk_text (srf, ttk_textfont, sf_x+1, nf_y-ttk_text_height(ttk_textfont), ttk_makecol(WHITE), "score"); ttk_text (srf, ttk_textfont, sf_x+sf_w-ttk_text_width(ttk_textfont, buffer)-3, nf_y + (nf_w/2 - ttk_text_height(ttk_textfont)/2), ttk_makecol(WHITE), buffer); // draw moving brick draw_brick(srf, pf_x, 7-(sq_size*brick_length), brick_length, brick_depth); // draw next brick draw_brick(srf, nf_x+sq_size/2, nf_y+sq_size/2, next_length, 0); // hide bad programming skills for users eyes :) ttk_fillrect (srf, pf_x, 0, pf_x+pf_w, 6, ttk_makecol(BLACK)); }
void draw_brick(t_list *bricks) { t_brick *elem; if (bricks != NULL) { draw_brick(bricks->next); elem = bricks->content; if (elem->type == BRICK_STD) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (elem->solidity == 3) glColor4f(0.1f, 0.1f, 0.1f, 0.1f); else if (elem->solidity == 2) glColor4f(elem->red, elem->green, elem->blue, 0.4f); else glColor4f(elem->red, elem->green, elem->blue, 1.0f); } else glColor3f(elem->red, elem->green, elem->blue); glRecti(elem->x, elem->y, elem->x + BRICK_WIDTH, elem->y + BRICK_HEIGHT); bricks = bricks->next; } }
void draw_level(t_level *level) { t_list_node *cursor; t_brick *cur_brick; cursor = level->brick_list; while (cursor) { cur_brick = (t_brick *)cursor->value; if (cur_brick->val > 0) draw_brick(cur_brick); cursor = cursor->next; } update_ball(level->ball, level->brick_list); draw_ball(level->ball); update_pad(level->pad, level->ball); draw_pad(level->pad); draw_level_border(); draw_lives(level->lives); draw_score(level->score); }
/* Called whenever the ball collides with a brick, and handles such things as * destroying the brick if appropriate, redrawing it with more transparency * if appropriate, incrementing to the next level when we destroy the last brick * (actually, that's done by destroy_brick() which is called from * brick_collision()), etc. Returns 0 if the level was not incremented and 1 * if it was. */ int brick_collision(nbstate *state, grid *g) { /* If either the PowerBall power-up or the NoBounce cheat is active, * simply destroy the brick in one hit even if it is immutable. */ if(state->powertimes.powerball || state->flags.nb) return destroy_brick(state, g); /* If this is an immutable brick and PowerBall and NoBounce are not * active, it can't be destroyed so return normally: */ if(g->b->flags & BRICK_FLAG_IMMUTABLE) return 0; /* Increment the number of hits on this brick. This is used to keep * track of when to destroy a "2 hits or "3 hits" brick, and also how * transparent to draw those bricks as: */ g->hits++; /* If this is a 2-hit brick and it has only been hit once or it is a * 3 hit brick that has been hit either once or twice: */ if(((g->b->flags & BRICK_FLAG_2_HITS) && g->hits < 2) || ((g->b->flags & BRICK_FLAG_3_HITS) && g->hits < 3)) { /* Clear the area where the brick is: */ draw_background(state, g->x, g->y, state->brickwidth, state->brickheight); /* Redraw the brick (with additional transparency to indicate * that it has been hit): */ draw_brick(state, g, 0, 0, state->brickwidth, state->brickheight); /* Redraw any powers we may just have accidentally erased: */ redraw_powers(state, g->x, g->y, state->brickwidth, state->brickheight); /* Copy the changed area to the output window: */ draw_canvas(state, g->x, g->y, state->brickwidth, state->brickheight); /* Otherwise, destroy the brick: */ } else return destroy_brick(state, g); return 0; /* Level was not incremented. */ }
enum plugin_status plugin_start(const void* parameter) { int i; int f_width, f_height; int score_x; bool quit = false; int button; int cycletime = 300; int end; int pos_cur_brick = 0; int type_cur_brick = 0; int type_next_brick = 0; unsigned long int score = 34126; (void)parameter; #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); rb->lcd_set_background(LCD_BLACK); rb->lcd_set_foreground(LCD_WHITE); #endif rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_getstringsize("100000000", &f_width, &f_height); rb->lcd_clear_display(); /*********** ** Draw EVERYTHING */ /* Playing filed box */ rb->lcd_vline(CENTER_X-2, CENTER_Y, CENTER_Y + (WIDTH*TILES+TILES)); rb->lcd_vline(CENTER_X + WIDTH + 1, CENTER_Y, CENTER_Y + (WIDTH*TILES+TILES)); rb->lcd_hline(CENTER_X-2, CENTER_X + WIDTH + 1, CENTER_Y + (WIDTH*TILES+TILES)); /* Score box */ #if (LCD_WIDTH > LCD_HEIGHT) rb->lcd_drawrect(SCORE_X-4, SCORE_Y-5, f_width+8, f_height+9); rb->lcd_putsxy(SCORE_X-4, SCORE_Y-6-f_height, "score"); #else rb->lcd_hline(0, LCD_WIDTH, SCORE_Y-5); rb->lcd_putsxy(2, SCORE_Y-6-f_height, "score"); #endif score_x = SCORE_X; /* Next box */ rb->lcd_getstringsize("next", &f_width, NULL); #if (LCD_WIDTH > LCD_HEIGHT) && !(LCD_WIDTH > 132) rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10); rb->lcd_putsxy(score_x-4, NEXT_Y-5, "next"); #else rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10); rb->lcd_putsxy(NEXT_X-5, NEXT_Y-5-f_height-1, "next"); #endif /*********** ** GAMELOOP */ rb->srand( *rb->current_tick ); type_cur_brick = 2 + mrand(3); type_next_brick = 2 + mrand(3); do { end = *rb->current_tick + (cycletime * HZ) / 1000; draw_brick(pos_cur_brick, type_cur_brick); /* Draw next brick */ rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); rb->lcd_fillrect(NEXT_X, NEXT_Y, WIDTH, WIDTH * 4 + 4); rb->lcd_set_drawmode(DRMODE_SOLID); for (i = 0; i < type_next_brick; ++i) { rb->lcd_fillrect(NEXT_X, NEXT_Y + ((type_next_brick % 2) ? (int)(WIDTH/2) : ((type_next_brick == 2) ? (WIDTH+1) : 0)) + (WIDTH*i) + i, WIDTH, WIDTH); } /* Score box */ rb->lcd_putsxyf(score_x, SCORE_Y, "%8ld0", score); rb->lcd_update(); button = rb->button_status(); switch(button) { case ONEDROCKBLOX_DOWN: case (ONEDROCKBLOX_DOWN|BUTTON_REPEAT): cycletime = 100; break; case ONEDROCKBLOX_QUIT: quit = true; break; default: cycletime = 300; if(rb->default_event_handler(button) == SYS_USB_CONNECTED) { quit = true; } } if ((pos_cur_brick + type_cur_brick) > 10) { type_cur_brick = type_next_brick; type_next_brick = 2 + mrand(3); score += (type_cur_brick - 1) * 2; pos_cur_brick = 1 - type_cur_brick; } else { ++pos_cur_brick; } if (TIME_BEFORE(*rb->current_tick, end)) rb->sleep(end-*rb->current_tick); else rb->yield(); } while (!quit); return PLUGIN_OK; }