📄 breakout.cpp
字号:
Sdl_SetVideoMode(lev_w * brick_w, lev_h * brick_h, 16, SDL_HWSURFACE | SDL_FULLSCREEN); SDL_SetCursor(empty_cur); } else { Sdl_SetVideoMode(lev_w * brick_w, lev_h * brick_h, 16, SDL_HWSURFACE); if (!init_data.warp && !init_data.control == 0) SDL_SetCursor(original_cur); } DR_SETFULLDST(sdl.scr); DR_SETFULLSRC(ss_bkgnd); SSur_Blit(); Sdl_FullUpdate(); last_call = SDL_GetTicks(); } // pause if (event.key.keysym.sym == SDLK_p) { Pause(); last_call = SDL_GetTicks(); } break; } if (!disappear) switch (event.type) { case SDL_KEYDOWN: if (cur_extras[EX_WEAPON] && event.key.keysym.sym == init_data.k_fire) { fire_shot = 1; shot_time = shot_delay; } break; case SDL_MOUSEBUTTONDOWN: if (cur_extras[EX_WEAPON]) { fire_shot = 1; shot_time = shot_delay; } break; case SDL_MOUSEMOTION: mouse_moved = 1; if (init_data.warp) { mx = (int)(motion_mod * event.motion.xrel); if (init_data.invert) mx = -mx; } else mx = event.motion.x; break; } } if (leave) break; // hide // Life_Hide(); Club_Hide(); Balls_Hide(); Shots_Hide(); Wall_Hide(); Extras_Hide(); Shr_Hide(); Score_Hide(); ExDisp_Hide(); if ( init_data.anim ) Sh_Hide(); Credit_Hide(); // compute time // call = SDL_GetTicks(); ms = call - last_call; last_call = call;// if (ms <= 0) { // ms = 1; SDL_Delay(20);// } // update // if (!disappear && !appear) { Club_Update(ms); if (Balls_Update(ms)) disappear = 1; } Shots_Update(ms); Wall_Update(ms); Wpn_Update(ms); Extras_Update(ms); Shr_Update(ms); Score_Update(ms); if ( init_data.anim ) Sh_Update(ms); Credit_Update(ms); // update club alpha // if (appear) { ca -= 0.5 * ms; if (ca < 0) { restart = 1; appear = 0; ca = 0; } } else if (disappear) { ca += 0.5 * ms; if (ca > 255) { appear = 1; disappear = 0; ca = 255; Club_Reset(); Balls_Reset(); cur_extras[EX_SLIME] = cur_extras[EX_METAL] = cur_extras[EX_WEAPON] = cur_extras[EX_FROZEN] = cur_extras[EX_SLOW] = cur_extras[EX_FAST] = 0; } } // increase and adjust ball's speed // if ( !cur_extras[EX_SLOW] && !cur_extras[EX_FAST] ) { if (ball_v < ball_vm && !(ball_list.counter == 1 && ((Ball*)(ball_list.head.next->data))->attached)) { ball_v += ball_v_add * ms; e = ball_list.head.next; while (e != &ball_list.tail) { Ball_AdjustSpeed((Ball*)e->data, ball_v); e = e->next; } } } // update lifes // if (!con_bought && ( (restart && player.lives-- == 0) || (disappear && player.lives == 0) ) ) ask_for_con = 1; // show // Life_Show(); Shots_Show(); if (disappear || appear) { Balls_AlphaShow(ca); Club_AlphaShow(ca); } else { Balls_Show(); Club_Show(); } Wall_Show(); Extras_Show(); if ( init_data.anim ) Sh_Show(); Score_Show(); ExDisp_Show(); Shr_Show(); Credit_Show(); // refresh // Refresh(); if (ask_for_con) { if (BuyContinue()) { last_call = SDL_GetTicks(); con_bought = 1; } else leave = 1; ask_for_con = 0; } } if (!fast_quit && !leave) { if (new_level) { if (++level >= lev_num) break; SDL_DIM(); InitLevel(level); SDL_UNDIM(); } else {#ifdef SOUND SndSrv_Play(snd_ldown, 0);#endif // reset event stuff // mx = 0; memset(buttonstate, 0, sizeof(buttonstate)); memset(keystate, 0, sizeof(keystate)); ball_v = levels[level].v; con_bought = 0; } new_level = 0; restart = 0; } else break; } fullscreen = 0; // cursor ? // SDL_SetCursor(original_cur); // delete file levels // if (levels == file_levels) Levels_Delete(); // modify score // player.score = (int)(player.score * diff[init_data.diff].score_mod); SDL_DIM(); if (!fast_quit) GameOver(); Sdl_SetVideoMode(450, 325, 16, SDL_HWSURFACE); return hiscore->CheckEntry(&player);}void BreakOut::InitGame(){ // reset player // player.score = 0; cur_score = 0; player.lives = diff[init_data.diff].lives; strcpy(player.name, init_data.name); player.level = init_data.startlevel; // fullscreen ? // fullscreen = init_data.fullscreen; // int first level // lev_w = lev_h = 0; level = init_data.startlevel; InitLevel(level);}void BreakOut::InitLevel(int l){ char str[256]; SDL_Surface *pic; int flgs = SDL_HWSURFACE; int old_w = lev_w, old_h = lev_h; // load map // LoadLevel(l); // set new resolution // if (lev_w != old_w || lev_h != old_h) { if (fullscreen) flgs = flgs | SDL_FULLSCREEN; Sdl_SetVideoMode(lev_w * brick_w, lev_h * brick_h, 16, flgs); } // reset background // if (ss_bkgnd) SDL_FreeSurface(ss_bkgnd); ss_bkgnd = SSur_Create(sdl.scr->w, sdl.scr->h, SDL_HWSURFACE); SDL_SetColorKey(ss_bkgnd, 0, 0); if (ss_picture) SDL_FreeSurface(ss_picture); ss_picture = SSur_Create(sdl.scr->w, sdl.scr->h, SDL_HWSURFACE); SDL_SetColorKey(ss_picture, 0, 0); if (init_data.bkgnd) { sprintf(str, "bkgnd%i.bmp", level / 10); if ((pic = SSur_Load(str, SDL_HWSURFACE)) == 0) if ((pic = SSur_Load("bkgnd0.bmp", SDL_HWSURFACE)) == 0) { pic = SSur_Create(sdl.scr->w, sdl.scr->h, SDL_HWSURFACE); DR_SETFULLDST(pic); SSur_Fill(0x0); } SDL_SetColorKey(pic, 0, 0); DR_SETDST(ss_picture, (ss_picture->w - pic->w) / 2, (ss_picture->h - pic->h) / 2, pic->w, pic->h); DR_SETFULLSRC(pic); SSur_Blit(); DR_SETFULLDST(ss_bkgnd); DR_SETFULLSRC(ss_picture); SSur_Blit(); SDL_FreeSurface(pic); } else { DR_SETFULLDST(ss_bkgnd); SSur_Fill(0x0); } // draw frame to background // int i, j; for (i = 1; i < lev_w - 1; i++) for (j = 1; j < lev_h - 1; j++) if (lev_map[i][j].type == MAP_WALL) { DR_SETDST(ss_bkgnd, i * brick_w, j * brick_h, brick_w, brick_h); DR_SETSRC(ss_bricks, lev_map[i][j].id * brick_w, 0); SSur_Blit(); } // left upper corner DR_SETDST(ss_bkgnd, 0, 0, ss_fr_luc->w, ss_fr_luc->h); DR_SETFULLSRC(ss_fr_luc); SSur_Blit(); // life lights // for (j = 11; j < lev_h; j++) { DR_SETDST(ss_bkgnd, 0, j * brick_h, brick_w, brick_h); DR_SETFULLSRC(ss_fr_left); SSur_Blit(); } // top tiles for (i = 4; i < lev_w - 4; i++) { DR_SETDST(ss_bkgnd, i * brick_w, 0, brick_w, brick_h); DR_SETFULLSRC(ss_fr_top); SSur_Blit(); } // right upper corner DR_SETDST(ss_bkgnd, (lev_w - 4) * brick_w, 0, ss_fr_ruc->w, ss_fr_ruc->h); DR_SETFULLSRC(ss_fr_ruc); SSur_Blit(); // right tiles for (j = 1; j < lev_h - 4; j++) { DR_SETDST(ss_bkgnd, (lev_w - 1) * brick_w, j * brick_h, brick_w, brick_h); DR_SETFULLSRC(ss_fr_right); SSur_Blit(); } // right lower corner DR_SETDST(ss_bkgnd, (lev_w - 1) * brick_w, (lev_h - 4) * brick_h, ss_fr_rlc->w, ss_fr_rlc->h); DR_SETFULLSRC(ss_fr_rlc); SSur_Blit(); // draw lifes // max_lives = lev_h - 11; if (diff[init_data.diff].max_lives <= max_lives) life_y = (lev_h - diff[init_data.diff].max_lives) * brick_h; else life_y = (lev_h - max_lives) * brick_h; for (j = life_y; j < sdl.scr->h; j += brick_h) { DR_SETDST(ss_bkgnd, 0, j, brick_w, brick_h); DR_SETSRC(ss_life, 0, 0); SSur_Blit(); } // draw bricks to background // for (int i = 0; i < lev_w; i++) for (int j = 0; j < lev_h; j++) if (lev_map[i][j].type > MAP_WALL) { DR_SETDST(ss_bkgnd, i * brick_w, j * brick_h, brick_w, brick_h); DR_SETSRC(ss_bricks, lev_map[i][j].id * brick_w, 0); SSur_Blit(); } // copy background to screen // DR_SETFULLDST(sdl.scr); DR_SETFULLSRC(ss_bkgnd); SSur_Blit(); // reset // Club_Reset(); Balls_Reset(); DL_Clear(&extra_list); DL_Clear(&shrapnell_list); DL_Clear(&shot_list); new_level = 0; memset(cur_extras, 0, sizeof(cur_extras)); player.level = level; // reset event stuff // mx = 0; memset(buttonstate, 0, sizeof(buttonstate)); memset(keystate, 0, sizeof(keystate)); // credit init // Credit_Init();}void BreakOut::LoadLevel(int l){ int i, j; strcpy(lev_author, levels[l].author); strcpy(lev_name, levels[l].name); lev_w = levels[l].w + 2; lev_h = levels[l].h + 2; ball_v = levels[l].v; ball_v_add = levels[l].v_pms; ball_vm = levels[l].vm; // build walls // for (i = 0; i < lev_w; i++) { lev_map[i][0].type = MAP_WALL; lev_map[i][0].id = 0; lev_map[i][lev_h - 1].type = MAP_EMPTY; lev_map[i][lev_h - 1].id = -1; } for (j = 0; j < lev_h; j++) { lev_map[0][j].type = MAP_WALL; lev_map[lev_w - 1][j].type = MAP_WALL; lev_map[0][j].id = 0; lev_map[lev_w - 1][j].id = 0; } // load map // for (i = 0; i < levels[l].w; i++) for (j = 0; j < levels[l].h; j++) { // create map // switch (levels[l].map[j * levels[l].w + i]) { case '#': // wall // lev_map[i + 1][j + 1].type = MAP_WALL; lev_map[i + 1][j + 1].id = 0; lev_map[i + 1][j + 1].score = brick_score; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': // brick // lev_map[i + 1][j + 1].type = MAP_BRICK; lev_map[i + 1][j + 1].id = levels[l].map[j * levels[l].w + i] - 96; lev_map[i + 1][j + 1].dur = 1; // some bricks need more shots // if (lev_map[i + 1][j + 1].id < 4) lev_map[i + 1][j + 1].dur = lev_map[i + 1][j + 1].id + 1; lev_map[i + 1][j + 1].score = brick_score * lev_map[i + 1][j + 1].dur; break; default: // empty // lev_map[i + 1][j + 1].type = MAP_EMPTY; lev_map[i + 1][j + 1].id = -1; break; } // create extras // switch (levels[l].extras[j * levels[l].w + i]) { case '0': lev_map[i + 1][j + 1].extra = EX_SCORE200; break; case '1': lev_map[i + 1][j + 1].extra = EX_SCORE500; break; case '2': lev_map[i + 1][j + 1].extra = EX_SCORE1000; break; case '3': lev_map[i + 1][j + 1].extra = EX_SCORE2000; break; case '4': lev_map[i + 1][j + 1].extra = EX_SCORE5000; break; case '5': lev_map[i + 1][j + 1].extra = EX_SCORE10000; break; case '+': lev_map[i + 1][j + 1].extra = EX_LENGTHEN; break; case '-': lev_map[i + 1][j + 1].extra = EX_SHORTEN; break; case 'l': lev_map[i + 1][j + 1].extra = EX_LIFE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -