void screen_draw() { int x, y; int i; unsigned long top; int halfwin = WIN_W*T_SIZE/2; if (gPlayers == 1) { blit((BITMAP *)gData[BACK_1PLAYER].dat, gBuff, 0, 0, 0, 0, gBuff->w, gBuff->h); // information textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 77, 15, "LEVEL: %d", gDifficulty + 1); textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 109, 15, "LINES: %d", p[0].total_lines); textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 141, 15, "SCORE: %ld", p[0].total_score); if (p[0].total_score > gTable[0].score) top = p[0].total_score; else top = gTable[0].score; textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 173, 15, "TOP : %ld", top); } else blit((BITMAP *)gData[BACK_2PLAYER].dat, gBuff, 0, 0, 0, 0, gBuff->w, gBuff->h); for (i = 0; i != gPlayers; ++i) { // draw game area // grid for (y = 0; y != WIN_H; ++y) { hline(gBuff, p[i].win_x, p[i].win_y + y*T_SIZE, p[i].win_x + WIN_W*T_SIZE, 4); for (x = 0; x != WIN_W; ++x) vline(gBuff, p[i].win_x + x*T_SIZE, p[i].win_y, p[i].win_y + WIN_H*T_SIZE, 4); } // next piece box next_draw(); // the stack player_stack_draw(i); // the deleting line effect if (p[i].process == DELETING_LINES) { for (y = 0; y != 4; ++y) { if (p[i].full_lines[y] != -1) rectfill(gBuff, p[i].win_x + halfwin - halfwin * gDeleteCounter[i]/cDeleteTime, p[i].win_y + p[i].full_lines[y]*T_SIZE, p[i].win_x + halfwin + halfwin * gDeleteCounter[i]/cDeleteTime, p[i].win_y + p[i].full_lines[y]*T_SIZE + T_SIZE - 1, 0); } } // the current piece set_clip(gBuff, p[i].win_x, p[i].win_y, p[i].win_x + WIN_W*T_SIZE, p[i].win_y + WIN_H*T_SIZE); piece_draw(p[i].win_x + p[i].piece_x*T_SIZE, p[i].win_y + p[i].piece_y*T_SIZE, p[i].piece_r, p[i].current); set_clip(gBuff, 0, 0, gBuff->w, gBuff->h); //textprintf(gBuff, font, SCREEN_W/2*i, 0, 15, "(%d, %d, %d)", p[i].piece_x, p[i].piece_y, p[i].piece_r); } }
int main(int argc, char* argv[]) { bool now = false; clock_t begin, end; // °ÔÀÓÀ» ÁøÇà ÇÒ ‹š ½Ã°£À» Àç´Â º¯¼ö ¼±¾ð begin = clock(); // °ÔÀÓ ½ÃÀÛ double all_clock; // °ÔÀÓ ÁøÇà ÈÄ ÃÑ ½Ã°£ Ãâ·Â º¯¼ö ¼±¾ð rotate_tetris(); srand(clock()); Cursor(0); board_draw(true); now_tetris = rand() % 7; next_tetris = rand() % 7; // ÇöÀç Å×Æ®¸®½º, ´ÙÀ½ Å×Æ®¸®½º ·£´ý next_draw(); char keyvalue; clock_t s_time = clock(); clock_t e_time; // ½Ã°£¿¡ °üÇÑ ÇÔ¼ö cx = 4; cy = -1; cr = 0; while(1) { if(_kbhit()) //Å°º¸µå À̺¥Æ® ó¸® { keyvalue = _getch(); switch(keyvalue) { case SPACE: // spsce bar ¸¦ ´©¸¦ ½Ã ¸ð¾çÀÌ ³»·Á°£´Ù. cy = point_get()-1; preview_cp(); now_cp(); cy++; now = true; break; case LEFT: //¹æÇâÅ° ¿ÞÂÊÀ» ´©¸¦ ½Ã µµÇü ¿ÞÂÊ À̵¿ cx--; if(move_ck(LEFT)) cx++; else now = true; break; case RIGHT:// ¹æÇâÅ° ¿À¸¥ÂÊ À» ´©¸¦ ½Ã µµÇü ¿À¸¥ÂÊ À̵¿ cx++; if(move_ck(RIGHT))cx--; else now = true; break; case UP: // ¹æÇâÅ° À§·Î¸¦ ´©¸¦ ½Ã µµÇüÀÌ È¸Àü //ȸÀü °¡´ÉÇÑÁö Á¶»çÇÏ°í //°¡´ÉÇϸé ȸÀüÇÑ´Ù. cr = (cr+1) % 4; if(move_ck(UP)) cr = (cr-1) % 4; else now = true; break; case ',': // ¾Æ·¡·Î ÇÑÄ À̵¿ cy++; now = true; break; } } e_time = clock(); if((float)(e_time - s_time) / (float)CLOCKS_PER_SEC >=0.5 ^ now == true) { // Á¤ÇØÁø ½Ã°£°ú now Áß Çϳª¸¸ trueÀÏ ¶§ ÁøÀÔ s_time=clock(); if(!now) cy++; // Ãæµ¹ °Ë»ç now = false; if(!move_ck(DOWN)) now_cp(); else { now_tetris = next_tetris; next_tetris = rand() % 7; next_draw(); cx = 4; cy = -1; cr=0; join_down(); clear_line(); if(check()) { gotoxy(20, 10); setColor(0,15); printf("========== Game Over =========="); setColor(7,0); end = clock(); // °ÔÀÓ Á¾·á ½Ã°£ all_clock = (double)(end-begin)/(double)CLOCKS_PER_SEC; // ÃÑ °ÔÀӽð£ Ãâ·Â gotoxy(0,0); printf(" ÃÑ Ç÷¹ÀÌ ½Ã°£Àº %lf ÃÊ ÀÔ´Ï´Ù. ", all_clock); gotoxy(40, 23); // printf("\n"); exit(0); } store = true; now_cp(); } board_draw(false); shadow_draw(point_get()); } } return 0; }
void game_frame(SDL_Surface *screen) { game_handle_keys(); switch(game_state) { case TS_FALLING: curr_piece.y += 4; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) { curr_piece.y = _bx(_py(curr_piece.y)-1); ++curr_piece.lock; } if(game_get_key_DAS(TK_DOWN)) curr_piece.y += 0xFF; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) { curr_piece.y = _bx(_py(curr_piece.y)-1); curr_piece.lock = T_LOCKDELAY+1; } if(game_get_key(TK_UP)) { while(!collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) curr_piece.y += 0xFF; curr_piece.y -= 0xFF; } if(game_get_key_DAS(TK_RIGHT)) { curr_piece.x += 1; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) curr_piece.x -= 1; } if(game_get_key_DAS(TK_LEFT)) { curr_piece.x -= 1; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) curr_piece.x += 1; } int init_rot = curr_piece.rot; if(game_get_key(TK_A)||game_get_key(TK_B)||game_get_key(TK_C)) { if(game_get_key(TK_A)||game_get_key(TK_C)) { curr_piece.rot -= 1; if(curr_piece.rot < 0) curr_piece.rot = curr_piece.t->frames-1; } else if(game_get_key(TK_B)) { curr_piece.rot += 1; if(curr_piece.rot >= curr_piece.t->frames) curr_piece.rot = 0; } if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) { curr_piece.x -= 1; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) { curr_piece.x += 2; if(collision_check(curr_piece.t, f, curr_piece.x, _py(curr_piece.y), curr_piece.rot)) { curr_piece.x -= 1; curr_piece.rot = init_rot; } } } } if(curr_piece.lock >= T_LOCKDELAY) { game_state = TS_LINECLEAR; clear_time = T_CLEARDELAY; lock_piece(); } break; case TS_LINECLEAR: if(clear_time == T_CLEARDELAY) { int x,y,numclear=0,empty; for(y=f->h-1; y>=0; --y) { empty = 0; for(x=f->w-1; x>=0; --x) { if(f->field[y*f->w + x] == 0) { empty = 1; break; } } if(empty == 0) { for(x=f->w-1; x>=0; --x) f->field[y*f->w + x] = 0xFE; ++numclear; } } if(numclear == 0) { game_state = TS_ENTRY; break; } } --clear_time; if(clear_time == 0) { int y,cy,cx; for(y=0; y<f->h; ++y) { if((unsigned char)f->field[y*f->w+0] == 0xFE) { printf("clearing line %i\n", y); for(cy=y; cy>0; --cy) for(cx=f->w-1; cx>=0; --cx) f->field[cy*f->w+cx] = f->field[(cy-1)*f->w+cx]; } } game_state = TS_ENTRY; } break; case TS_ENTRY: --are_time; if(are_time == 0) { are_time = T_ENTRYDELAY; game_next_piece(); game_state = TS_FALLING; } break; } SDL_Rect rect = { (SCREEN_WIDTH) / 2 - (10 * BLOCK_SIZE) / 2, (SCREEN_HEIGHT) - (20 * BLOCK_SIZE) - 20, BLOCK_SIZE * 10 + 1, BLOCK_SIZE * 20 + 1}; SDL_Rect next_rect = { (rect.x) + ((BLOCK_SIZE * 10/2) - (BLOCK_SIZE * 4/2)), rect.y - (4 * BLOCK_SIZE) - 10, 4 * BLOCK_SIZE+1, 4 * BLOCK_SIZE+1}; SDL_FillRect(screen, &rect, block_color[0xFF]); field_draw(f, screen, rect.x, rect.y); next_draw(next_piece, screen, next_rect.x, next_rect.y + (4-next_piece->mask_size)*BLOCK_SIZE); if(game_state == TS_FALLING) drop_draw(curr_piece, screen, rect.x, rect.y); }