CSuperBrickBreaker.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:5k
- ///////////////////////////////////////////////////////////////////////////////
- /// File: CSuperBrickBreaker.h
- /// Purpose: Declaration of CSuperBrickBreaker Class
- /// This class represents the main class of the application. The
- /// class is a direct descendent of CDirectDrawApp.
- ///////////////////////////////////////////////////////////////////////////////
- /// Configuation Management
- ///
- /// Who When Description
- /// ===========================================================================
- /// R. Walter 28-Dec-2003 Initial Version/Release
- ///
- ///////////////////////////////////////////////////////////////////////////////
- /// Copyright 2003: Robert Walter All rights reserved
- ///////////////////////////////////////////////////////////////////////////////
- #ifndef CSUPERBRICKBREAKER_H_
- #define CSUPERBRICKBREAKER_H_
- /// HEADER DEFINES ////////////////////////////////////////////////////////////
- #define WIN32_LEAN_AND_MEAN
- /// HEADER FILE INCLUDES //////////////////////////////////////////////////////
- #include <fstream>
- #include <iostream>
- #include <strstream>
- #include <cmath>
- #include "CDirectDrawGame.h"
- #include "CBall.h"
- #include "CBricks.h"
- #include "CPaddle.h"
- using std::ofstream;
- using std::ostrstream;
- using std::ends;
- using std::endl;
- /// TYPE / CLASS DECLARATIONS /////////////////////////////////////////////////
- /// declare ENUM used to define the current state of the game
- enum EGameState {GS_INITIALIZE, GS_MAINMENU, GS_STARTTURN, GS_GAMEPLAY, GS_GAMEPAUSED, GS_GAMEOVER};
- /// declare ENUM used to define which type of game is being played
- enum EGameType {SBB_STANDARD, SBB_DOUBLE, SBB_ESCAPE};
- /// declare ENUM used to define the currently selection option
- /// on the paused menu
- enum EPausedMenuState {PS_RESUME, PS_MAINMENU};
- /// declare ENUM used to define the currently selection option
- /// on the game over menu
- enum EGameOverMenuState {GO_PLAYAGAIN, GO_MAINMENU};
- /// declare ENUM used to define the how the ball intersect the
- /// game objects
- enum EIntersect {IS_NONE, IS_TOP, IS_RIGHT, IS_BOTTOM, IS_LEFT};
- struct TBallCorner
- {
- int x;
- int y;
- };
- class CSuperBrickBreaker : public CDirectDrawGame
- {
- private:
- // keyboard state data retrieved from DirectInput
- UCHAR m_key_state[256];
- // colors
- DWORD m_3d_light_clr;
- DWORD m_3d_shadow_clr;
- DWORD m_black_clr;
- DWORD m_blue_clr;
- DWORD m_boundary_clr;
- DWORD m_green_clr;
- DWORD m_red_clr;
- DWORD m_yellow_clr;
- DWORD m_white_clr;
- // boundary RECTs
- RECT m_left_boun_rect;
- RECT m_top_boun_rect;
- RECT m_right_boun_rect;
- // boundary 3D RECTs
- RECT m_left_3d_light_rect;
- RECT m_left_3d_shadow_rect;
- RECT m_top_3d_light_rect;
- RECT m_top_3d_shadow_rect;
- RECT m_right_3d_light_rect;
- RECT m_right_3d_shadow_rect;
- // playing area
- RECT m_playing_area_rect;
- // paddle members
- CPaddle m_paddle;
- RECT m_paddle_rects[2];
- int m_paddle_cnt;
- bool m_first_paddle_hit;
- // ball members
- CBall m_ball[3];
- RECT m_ball_rect;
- int m_num_balls;
- int m_game_turns_remaining;
- int m_balls_in_play;
- bool m_hit_top_boun_fg;
- bool m_new_level_fg;
-
- // brick members
- CBricks m_bricks;
- DWORD m_brick_colors[DEFAULT_BRICK_ROWS];
- int m_brick_points[DEFAULT_BRICK_ROWS];
- int m_brick_reflect_vel[DEFAULT_BRICK_ROWS];
- // 'state' members
- EGameState m_game_state;
- EGameType m_game_type;
- EPausedMenuState m_paused_state;
- EGameOverMenuState m_gameover_state;
- // 'general' members
- int m_score;
- int m_level;
- HFONT m_menu_font;
- HFONT m_plain_font;
- ofstream m_file_stream;
- // drawing functions
- bool Draw3DFrame(const RECT p_rect);
- bool DrawBalls();
- bool DrawBoundary();
- bool DrawBricks();
- bool DrawGameOverMenu();
- bool DrawHeadingLine();
- bool DrawMainMenu();
- bool DrawPaddle();
- bool DrawPausedMenu();
- bool DrawStartNextTurn();
- // initialization functions
- void InitializeBalls();
- void InitializeBricks();
- void InitializeColors();
- void InitializeNewGame();
- void InitializeNewLevel();
- void InitializePaddle();
- void InitializePlayingArea();
- // main game processing functions
- bool ProcessBalls();
- bool ProcessKeyboard();
- bool ProcessPaddle();
- bool ProcessStateChange(EGameState m_new_game_state);
- // collision detection/resolution functions
- EIntersect CheckHitPaddle(const RECT p_ball_rect);
- EIntersect CheckHitBrick(const RECT p_ball_rect, TBrick* p_hit_brick);
- EIntersect BallRectIntersect(RECT p_ball_rect, RECT p_rect);
- bool IsBrickAtBallLocation(const RECT p_ball_rect, TBrick* l_hit_brick);
- public:
- // constructor
- CSuperBrickBreaker();
- // destructor
- ~CSuperBrickBreaker();
- // game member functions
- bool GameInitialize();
- bool GameShutdown();
- bool GameMain();
- };
- #endif