📄 breakout.cpp
字号:
/*************************************************************************** breakout.cpp - description ------------------- begin : Thu Apr 20 2000 copyright : (C) 2000 by Michael Speck email : kulkanie@gmx.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "breakout.h"#include "level.h"#include <stdlib.h>#include <stdio.h>#include <sys/timeb.h>#include <string.h>#include <math.h>#define TOARC(d) (((float)d/180)*M_PI)#define TODEG(a) (((float)a/M_PI)*180)#define VLEN(x, y) ( sqrt( (x)*(x) + (y)*(y) ) )#define N 0#define E 1#define S 2#define W 3extern Sdl sdl;extern char *home_dir;extern int fast_quit;extern DrawRgn dr_src, dr_dst;extern Level orig_levels[LEVEL_NUM];#ifdef SOUNDextern SndSrv sndsrv;#endif/* egcs 2.91.66 got some problems with pow() in GetTarget so I'll use this function instead*/float Square(float x){ return (x * x);}BreakOut::BreakOut(){ // misc // file_levels = 0; // load font // font = SFnt_LoadFixed("f_yellow.bmp", 32, 96, 10); font->algn = TA_X_CENTER | TA_Y_CENTER; // load hiscore // hiscore = HiScore::CreateComposite("lbreakout.hscr"); // config path // cfg_path = new char[strlen(home_dir) + strlen(".lbreakout.cfg") + 2]; sprintf(cfg_path, "%s/.lbreakout.cfg", home_dir); // load init // FILE *f; if ((f = fopen(cfg_path, "r")) == 0) { strcpy(init_data.name, "Michael"); strcpy(init_data.lvl_file, "test.lbr"); strcpy(init_data.lvl_path, "."); init_data.k_left = SDLK_LEFT; init_data.k_right = SDLK_RIGHT; init_data.k_fire = SDLK_SPACE; init_data.snd_on = 1; init_data.snd_vol = 8;// init_data.key_speed = 0.45;// init_data.key_speed = 0.60; init_data.key_speed = 1.20; init_data.trp = 1;// init_data.anim = 2; init_data.anim = 0; init_data.warp = 0; init_data.control = 2; init_data.diff = 1; init_data.startlevel = 0; init_data.lvls_frm_file = 0; init_data.motion_mod = 100; init_data.bkgnd = 1; init_data.fullscreen = 0; init_data.convex = 0; init_data.invert = 0; init_data.rnd_start = 0; init_data.no_exdisp = 0; } else { fread(&init_data, sizeof(InitData), 1, f); fclose(f); } // background // ss_bkgnd = 0; ss_picture = 0; // frame // ss_fr_luc = SSur_Load("fr_luc.bmp", SDL_HWSURFACE); ss_fr_left = SSur_Load("fr_l.bmp", SDL_HWSURFACE); ss_fr_top = SSur_Load("fr_t.bmp", SDL_HWSURFACE); ss_fr_ruc = SSur_Load("fr_ruc.bmp", SDL_HWSURFACE); ss_fr_right = SSur_Load("fr_r.bmp", SDL_HWSURFACE); ss_fr_rlc = SSur_Load("fr_rlc.bmp", SDL_HWSURFACE); // bricks // brick_w = 32; brick_h = 16; brick_score = 100; if ((ss_bricks = SSur_Load("bricks.bmp", SDL_HWSURFACE)) == 0) exit(1); // club // club_cw = 10; club_ch = 10; if ((ss_club = SSur_Load("club.bmp", SDL_HWSURFACE)) == 0) exit(1); // ball // ball_vhmask = 0.363970234; // twenty degrees // ball_vvmask = 5.67128182; // ten degrees // ball_rad = 5; ball_dia = 11; ball_w = 12; ball_h = 12; if ((ss_ball = SSur_Load("ball.bmp", SDL_HWSURFACE)) == 0) exit(1); DL_Init(&ball_list); ball_list.flags = DL_AUTODELETE | DL_NOCALLBACK; // ball points // int i, j, a; a = -45; for (i = 0; i < 4; i++) { for (j = 0; j < 7; j++) { ball_pnts[i][j][0] = (int)ceil(sin(TOARC(a)) * ball_rad); ball_pnts[i][j][1] = (int)ceil(cos(TOARC(a)) * ball_rad); a += 15; } a -= 15; } // update rects // rect_num = 0; // life // ss_life = SSur_Load("life.bmp", SDL_HWSURFACE); // score // ss_numbers = SSur_Load("numbers.bmp", SDL_HWSURFACE); score_xoff = 44; // substracted from width score_y = 2; // added to 0 score_lw = 8; score_h = 10; score_x = score_w = 0; // extras // ss_extras = SSur_Load("extras.bmp", SDL_HWSURFACE); DL_Init(&extra_list); extra_list.flags = DL_AUTODELETE | DL_NOCALLBACK; // shrapnells // DL_Init(&shrapnell_list); shrapnell_list.flags = DL_AUTODELETE; shrapnell_list.cb_destroy = Shr_Free; // plasma weapon // ss_weapon = SSur_Load("weapon.bmp", SDL_HWSURFACE); wpn_y_off = 4; wpn_w = 14; wpn_h = 15; wpn_sx_off = 2; wpn_sy_off = -3; wpn_fr_num = 6; wpn_fpms = 0.006; wpn_cur = 0; // plasma shots // ss_shot = SSur_Load("shot.bmp", SDL_HWSURFACE); DL_Init(&shot_list); shot_list.flags = DL_AUTODELETE | DL_NOCALLBACK; shot_w = shot_h = 10; shot_fr_num = 4; shot_fpms = 0.01; shot_v_y = -0.2; shot_alpha = 64; max_shots = 6; shot_time = 0; shot_delay = 100; // snapshot // snapshot = 0; // cursor // unsigned char mask = 0; original_cur = SDL_GetCursor(); empty_cur = SDL_CreateCursor(&mask, &mask, 8, 1, 0, 0); // difficulty // // easy diff[0].lives = 5; diff[0].max_lives = 9; diff[0].con_cost = 20000; diff[0].club_size = 7; diff[0].club_max_size = 8; diff[0].score_mod = 1.0; // medium diff[1].lives = 4; diff[1].max_lives = 6; diff[1].con_cost = 20000; diff[1].club_size = 7; diff[1].club_max_size = 9; diff[1].score_mod = 1.1; // hard diff[2].lives = 3; diff[2].max_lives = 4; diff[2].con_cost = 30000; diff[2].club_size = 7; diff[2].club_max_size = 4; diff[2].score_mod = 1.2; // shine // ss_sh = SSur_Load("shine2.bmp", SDL_HWSURFACE); sh_cur = 0; sh_fr = 6; sh_pms = 0.024; sh_x = sh_y = 0; // credit // cr_time = 4000; cr_pms = 0.2; // extra display // ed_y = 40; memset(ed_offsets, 0, sizeof(ed_offsets)); ed_offsets[EX_SLIME] = 20; ed_offsets[EX_METAL] = 40; ed_offsets[EX_WALL] = 60; ed_offsets[EX_WEAPON] = 80; ed_offsets[EX_FAST] = 100; ed_offsets[EX_SLOW] = 100; #ifdef SOUND snd_ref = Wave_Load("reflect.wav"); snd_boom = Wave_Load("exp.wav"); snd_lup = Wave_Load("gainlife.wav"); snd_ldown = Wave_Load("looselife.wav"); snd_exp = Wave_Load("expand.wav"); snd_shr = Wave_Load("shrink.wav"); snd_sco = Wave_Load("score.wav"); snd_fre = Wave_Load("freeze.wav"); snd_shot = Wave_Load("shot.wav"); snd_sli = Wave_Load("slime.wav"); snd_wea = Wave_Load("weapon.wav"); snd_met = Wave_Load("metal.wav"); snd_wal = Wave_Load("wall.wav"); snd_damn1 = Wave_Load("damn.wav"); snd_damn2 = Wave_Load("damnit.wav"); snd_good = Wave_Load("verygood.wav"); snd_exc = Wave_Load("excellent.wav"); snd_click = Wave_Load("click.wav"); snd_wontgiveup = Wave_Load("wontgiveup.wav"); snd_speedup = Wave_Load("speedup.wav"); snd_speeddown = Wave_Load("speeddown.wav");#endif }BreakOut::~BreakOut(){ // save hiscore // if (hiscore) { hiscore->Save(); delete hiscore; } //save init //// FILE *f = fopen(cfg_path, "w");// fwrite(&init_data, sizeof(InitData), 1, f);// fclose(f); if (cfg_path) delete cfg_path; if (ss_bricks) SDL_FreeSurface(ss_bricks); if (ss_ball) SDL_FreeSurface(ss_ball); if (ss_club) SDL_FreeSurface(ss_club); if (ss_bkgnd) SDL_FreeSurface(ss_bkgnd); if (ss_picture) SDL_FreeSurface(ss_picture); if (ss_life) SDL_FreeSurface(ss_life); if (ss_numbers) SDL_FreeSurface(ss_numbers); if (ss_extras) SDL_FreeSurface(ss_extras); if (ss_shot) SDL_FreeSurface(ss_shot); if (ss_weapon) SDL_FreeSurface(ss_weapon); if (font) SFnt_Free(font); if (ss_fr_luc) SDL_FreeSurface(ss_fr_luc); if (ss_fr_left) SDL_FreeSurface(ss_fr_left); if (ss_fr_top) SDL_FreeSurface(ss_fr_top); if (ss_fr_ruc) SDL_FreeSurface(ss_fr_ruc); if (ss_fr_right) SDL_FreeSurface(ss_fr_right); if (ss_fr_rlc) SDL_FreeSurface(ss_fr_rlc); if (ss_sh) SDL_FreeSurface(ss_sh);#ifdef SOUND if (snd_ref) Wave_Free(snd_ref); if (snd_boom) Wave_Free(snd_boom); if (snd_lup) Wave_Free(snd_lup); if (snd_ldown) Wave_Free(snd_ldown); if (snd_exp) Wave_Free(snd_exp); if (snd_shr) Wave_Free(snd_shr); if (snd_sco) Wave_Free(snd_sco); if (snd_fre) Wave_Free(snd_fre); if (snd_shot) Wave_Free(snd_shot); if (snd_sli) Wave_Free(snd_sli); if (snd_wea) Wave_Free(snd_wea); if (snd_met) Wave_Free(snd_met); if (snd_wal) Wave_Free(snd_wal); if (snd_damn1) Wave_Free(snd_damn1); if (snd_damn2) Wave_Free(snd_damn2); if (snd_good) Wave_Free(snd_good); if (snd_exc) Wave_Free(snd_exc); if (snd_click) Wave_Free(snd_click); if (snd_wontgiveup) Wave_Free(snd_wontgiveup); if (snd_speedup) Wave_Free(snd_speedup); if (snd_speeddown) Wave_Free(snd_speeddown);#endif DL_Clear(&ball_list); DL_Clear(&extra_list); DL_Clear(&shrapnell_list); DL_Clear(&shot_list); // cursor // SDL_FreeCursor(empty_cur);}InitData* BreakOut::Setup(){ return &init_data;}int BreakOut::Run(){ int leave = 0, ask_for_con = 0, restart = 0, disappear = 0, appear = 0, con_bought = 0; SDL_Event event; int call, last_call; int ms = 0; float ca = 0; DL_Entry *e; // motion modifier if using relative mouse motion // motion_mod = (float)init_data.motion_mod / 100; // check if path of own levels is ok // if (init_data.lvls_frm_file) Levels_LoadFromFile(); else UseOrigLevels(); // init game // InitGame(); // cursor ? // if (init_data.warp || init_data.control == 0 || (!init_data.warp && fullscreen)) SDL_SetCursor(empty_cur); SDL_UNDIM(); // set time // call = SDL_GetTicks(); last_call = call; // shine // Sh_New(); // main loop // while (1) { // clear input states // while (SDL_PollEvent(&event)); // game loop // while (!fast_quit && !leave && !new_level && !restart) { // reset // mouse_moved = 0; // check key/mousestate // if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: fast_quit = 1; break; case SDL_MOUSEBUTTONDOWN: buttonstate[event.button.button] = 1; break; case SDL_MOUSEBUTTONUP: buttonstate[event.button.button] = 0; fire_shot = 0; shot_time = 0; break; case SDL_KEYDOWN: if( event.key.keysym.sym < SDLK_LAST ) keystate[event.key.keysym.sym] = 1; break; case SDL_KEYUP: if( event.key.keysym.sym >= SDLK_LAST ) break; keystate[event.key.keysym.sym] = 0; if (!keystate[init_data.k_fire]) { fire_shot = 0; shot_time = 0; } // screenshot if (event.key.keysym.sym == SDLK_TAB) SnapShot(); // quit if (event.key.keysym.sym == SDLK_ESCAPE|| event.key.keysym.sym == SDLK_RETURN /* kdhong */ ) { if (ConfirmQuit()) leave = 1; else last_call = SDL_GetTicks(); } // restart if (event.key.keysym.sym == SDLK_r) disappear = 1; // turn on/off sound#ifdef SOUND if (event.key.keysym.sym == SDLK_s) { init_data.snd_on = !init_data.snd_on; SndSrv_SetActive(init_data.snd_on); } #endif // turn on/off transparancy if (event.key.keysym.sym == SDLK_t) init_data.trp = !init_data.trp; // animation level if (event.key.keysym.sym == SDLK_a) { init_data.anim++; if (init_data.anim >= 3) init_data.anim = 0; } // set fullscreen if (event.key.keysym.sym == SDLK_f) { fullscreen = !fullscreen; if (fullscreen) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -