1 /*************************************************************************** 2 breakout.h - description 3 ------------------- 4 begin : Thu Apr 20 2000 5 copyright : (C) 2000 by Michael Speck 6 email : kulkanie@gmx.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef BREAKOUT_H 19 #define BREAKOUT_H 20 21 /** 22 *@author Michael Speck 23 */ 24 25 #include "sdl.h" 26 #include "sndsrv.h" 27 #include "hiscore.h" 28 #include "dynlist.h" 29 30 // how many small rects before update full screen // 31 #define UPDATERECTS 200 32 33 #define MAX_MAP_W 20 34 #define MAX_MAP_H 30 35 struct InitData{ 36 // game // 37 char name[12]; 38 int diff; 39 int startlevel; 40 int lvls_frm_file; 41 char lvl_path[32]; 42 char lvl_file[20]; 43 // controls // 44 int k_left; 45 int k_right; 46 int k_fire; 47 int control; 48 int warp; 49 int motion_mod; 50 // sound // 51 int snd_on; 52 int snd_vol; 53 // move with key_speed pix per sec when keys are used // 54 float key_speed; 55 // graphics // 56 int trp; 57 int anim; 58 int bkgnd; 59 int fullscreen; 60 int convex; 61 // new // 62 int invert; 63 int rnd_start; 64 int no_exdisp; 65 }; 66 67 // mouse buttons // 68 #define MB_LEFT 1 69 #define MB_MIDDLE 2 70 #define MB_RIGHT 3 71 72 struct Vector { 73 float x, y; 74 }; 75 76 // shrapnell // 77 struct Shrapnell { 78 SDL_Surface *ss_pic; 79 Vector v; 80 float x, y; 81 float alpha; 82 }; 83 84 // extra // 85 enum ExtraType { 86 EX_NONE = 0, 87 EX_SCORE200, 88 EX_SCORE500, 89 EX_SCORE1000, 90 EX_SCORE2000, 91 EX_SCORE5000, 92 EX_SCORE10000, 93 EX_SHORTEN, 94 EX_LENGTHEN, 95 EX_LIFE, 96 EX_SLIME, 97 EX_METAL, 98 EX_BALL, 99 EX_WALL, 100 EX_FROZEN, 101 EX_WEAPON, 102 EX_RANDOM, 103 EX_FAST, 104 EX_SLOW, 105 EX_NUMBER 106 }; 107 struct Extra { 108 float x, y; 109 float alpha; 110 int extra; 111 }; 112 113 // brick // 114 #define MAP_EMPTY 0 115 #define MAP_WALL 1 116 #define MAP_BRICK 2 117 struct MapBrick { 118 int type; 119 int id; 120 int dur; // durability // 121 ExtraType extra; // extra released when destroyed // 122 int score; 123 }; 124 125 // corner // 126 #define NONE 0 127 #define UPPERLEFT 4 128 #define UPPERRIGHT 5 129 #define LOWERLEFT 6 130 #define LOWERRIGHT 7 131 struct Corner { 132 int x, y; 133 int type; 134 }; 135 136 // target // 137 #define TOP 0 138 #define RIGHT 1 139 #define BOTTOM 2 140 #define LEFT 3 141 struct Target { 142 int exists; // is there a target // 143 int mx, my; // position in map // 144 float x, y; // reset position of ball // 145 int time; // time till contact // 146 int cur_tm; // current time // 147 int side; // contact with which side? // 148 Vector a; // reflection vector // 149 }; 150 151 // ball // 152 struct Ball { 153 float cur_x, cur_y; 154 int x, y; 155 float v_x, v_y; // vector components // 156 int attached; // attached to club ? // 157 int club_con; // contact with club // 158 int ign_club; // ignore club // 159 Target t; // target in map // 160 Target t2; // possible second brick // 161 }; 162 163 // club // 164 struct Club { 165 float cur_x; 166 int x, y; 167 float v_x; 168 int w, h; 169 int len; // how many middle components ? // 170 int max_len; // limit 171 float friction; // how much relative speed is given to balls ? 172 int time; 173 }; 174 175 // plasma shot // 176 struct Shot { 177 float x, y; 178 float cur_fr; 179 Target t; 180 int next_too; 181 }; 182 183 // difficulty // 184 struct Difficulty { 185 int lives, max_lives; 186 int con_cost; 187 int club_size; 188 int club_max_size; 189 float score_mod; 190 }; 191 192 struct Level; 193 194 class BreakOut { 195 public: 196 BreakOut(); 197 ~BreakOut(); 198 InitData* Setup(); 199 int Run(); 200 void InitGame(); 201 void InitLevel(int l); 202 void LoadLevel(int l); 203 HiScore* GetHiScore(); 204 int BuyContinue(); 205 int ConfirmQuit(); 206 void GameOver(); 207 char* NextLine(char *buf, char *cp, char *l); 208 char* ParseEntry(char *buf, char *cp, char *l); 209 void UseOrigLevels(); 210 // club // 211 void Club_Reset(); 212 void Club_Hide(); 213 void Club_Update(int ms); 214 void Club_Show(); 215 void Club_AlphaShow(int a); 216 int Club_Resize(int c); 217 void Club_CheckBallReflection(int old_x); 218 void Club_HandleContact(Ball *b, Vector a); 219 // ball // 220 Ball* Ball_Create(int x, int y, float a, float v); 221 void Ball_ComputeVec(Ball *b, float a, float v); 222 void Ball_CheckBrickReflection(Ball *b); 223 void Ball_NewTargets(int mx, int my); 224 void Ball_CheckConvexReflection(Ball *b, float old_x, float old_y); 225 void Ball_CheckClubReflection(Ball *b, float old_x, float old_y); 226 void Ball_AdjustSpeed(Ball *b, float v); 227 void Ball_GetTarget(Ball *b); 228 void Ball_ClearTarget(Target *t); 229 void Ball_MaskV(Ball *b, float old_vx); 230 void Balls_Reset(); 231 void Balls_Hide(); 232 int Balls_Update(int ms); 233 void Balls_Show(); 234 void Balls_AlphaShow(int a); 235 // brick // 236 void Brick_Remove(int mx, int my, int shot); 237 void Brick_CreateShrapnells(int x, int y, int shot); 238 // update // 239 void AddRefreshRect(int x, int y, int w, int h); 240 void Refresh(); 241 // life // 242 void Life_Hide(); 243 void Life_Show(); 244 // score // 245 void Score_Hide(); 246 void Score_Update(int ms); 247 void Score_Show(); 248 // extra // 249 void Extra_Create(ExtraType extra, int x, int y); 250 void Extra_Use(int extra); 251 void Extras_Hide(); 252 void Extras_Update(int ms); 253 void Extras_Show(); 254 // shrapnells // 255 void Shr_Create(int x, int y, int w, int h, float vx, float vy); 256 void Shr_Hide(); 257 void Shr_Update(int ms); 258 void Shr_Show(); 259 // wall // 260 void Wall_Hide(); 261 void Wall_Update(int ms); 262 void Wall_Show(); 263 // plasma weapon // 264 void Wpn_Update(int ms); 265 // plasma shot // 266 void Shots_Hide(); 267 void Shots_Update(int ms); 268 void Shots_Show(); 269 void Shots_NewTargets(int mx, int my); 270 Shot* Shot_Create(); 271 void Shot_GetTarget(Shot *s); 272 // pause // 273 void Pause(); 274 // snap shot // 275 void SnapShot(); 276 // corner // 277 void Corner_Check(Corner *c, float v_x, float v_y); 278 // levels // 279 FILE* Levels_OpenFile(char *str); 280 void Levels_LoadFromFile(); 281 int Levels_ParseFile(FILE *f); 282 void Levels_Delete(); 283 // shine // 284 void Sh_Hide(); 285 void Sh_Update(int ms); 286 void Sh_Show(); 287 void Sh_New(); 288 // credit // 289 void Credit_Hide(); 290 void Credit_Update(int ms); 291 void Credit_Show(); 292 void Credit_Init(); 293 // extra display // 294 void ExDisp_Hide(); 295 void ExDisp_Show(); 296 private: 297 // misc // 298 int fullscreen; 299 SDL_Surface *ss_bkgnd; 300 SDL_Surface *ss_picture; 301 SDL_Surface *ss_fr_luc; 302 SDL_Surface *ss_fr_left; 303 SDL_Surface *ss_fr_top; 304 SDL_Surface *ss_fr_right; 305 SDL_Surface *ss_fr_ruc; 306 SDL_Surface *ss_fr_rlc; 307 InitData init_data; 308 char *cfg_path; 309 SFnt *font; 310 Level *levels; 311 Level *file_levels; 312 float motion_mod; 313 // level // 314 int lev_num; 315 char lev_author[32], lev_name[32]; 316 int level; 317 int lev_w, lev_h; 318 MapBrick lev_map[MAX_MAP_W][MAX_MAP_H]; 319 int lev_bricks; 320 int new_level; 321 // brick // 322 SDL_Surface *ss_bricks; 323 int brick_score; 324 int brick_w, brick_h; 325 // club // 326 SDL_Surface *ss_club; 327 int club_cw, club_ch; // size of component // 328 Club club; 329 // ball // 330 SDL_Surface *ss_ball; 331 int ball_rad; // radius // 332 int ball_dia; // diameter // 333 int ball_w, ball_h; // size of a sprite // 334 DList ball_list; 335 float ball_vm; // v max // 336 float ball_v; // ball's speed // 337 float ball_old_v; // old speed (before extra used) // 338 float ball_vhmask, ball_vvmask; // velocity masks // 339 float ball_v_add; 340 int ball_pnts[4][7][2]; // points from the ball's surface // 341 // hiscore // 342 HiScoreEntry player; 343 HiScore *hiscore; 344 // events // 345 int keystate[SDLK_LAST]; 346 int buttonstate[4]; 347 int mouse_moved; 348 int mx; 349 // draw rects // 350 SDL_Rect rects[UPDATERECTS]; 351 int rect_num; 352 // life // 353 SDL_Surface *ss_life; 354 int life_y; 355 int max_lives; // maximum that can be dsiplayed // 356 // score // 357 SDL_Surface *ss_numbers; 358 float cur_score; 359 int score_x, score_y, score_w, score_h; 360 int score_xoff, score_lw; 361 // extras // 362 SDL_Surface *ss_extras; 363 DList extra_list; 364 int cur_extras[EX_NUMBER]; 365 // shrapnells // 366 DList shrapnell_list; 367 // wall // 368 float wall_alpha; 369 int wall_time; 370 // plasma weapon // 371 SDL_Surface *ss_weapon; 372 int wpn_time; 373 int wpn_y_off; 374 int wpn_x, wpn_y, wpn_w, wpn_h, wpn_fr_num; 375 int wpn_sx_off, wpn_sy_off; // shot position offset when created // 376 float wpn_cur, wpn_fpms; 377 // plasma shot // 378 DList shot_list; 379 SDL_Surface *ss_shot; 380 float shot_fpms, shot_v_y; 381 int shot_w, shot_h, shot_fr_num, shot_alpha; 382 int fire_shot; 383 int max_shots; 384 int shot_time, shot_delay; 385 // snapshot // 386 int snapshot; 387 // extra times // 388 int metal_time; 389 int frozen_time; 390 int slime_time; 391 int fast_time; 392 int slow_time; 393 // extra display // 394 int ed_x, ed_y; // offset releative to 0,0 395 int ed_offsets[EX_NUMBER]; 396 // cursor // 397 SDL_Cursor *original_cur; 398 SDL_Cursor *empty_cur; 399 // difficulty // 400 Difficulty diff[3]; 401 // shine // 402 SDL_Surface *ss_sh; 403 float sh_pms; 404 int sh_fr; 405 float sh_cur; 406 int sh_x, sh_y; 407 // credit // 408 float cr_alpha; 409 float cr_pms; 410 int cr_cur; 411 int cr_time; 412 int cr_x, cr_y, cr_w, cr_h; 413 char cr_str[32]; 414 int cr_status; 415 #ifdef SOUND 416 Wave *snd_ref, *snd_boom, *snd_lup, *snd_ldown, *snd_exp, *snd_shr; 417 Wave *snd_sco, *snd_fre, *snd_shot, *snd_sli, *snd_wea, *snd_met, *snd_wal; 418 Wave *snd_damn1, *snd_damn2; 419 Wave *snd_good, *snd_exc; 420 Wave *snd_wontgiveup; 421 Wave *snd_click; 422 Wave *snd_speedup, *snd_speeddown; 423 #endif 424 }; 425 426 void Shr_Free(void *p); 427 428 #endif 429