Arkanoid Remake  1.0
ArkanoidRemake.h
Go to the documentation of this file.
1 /*
2 ArkanoidRemakeSDL
3 a sample of object-oriented game programming with C++.
4 version 1.0, May 2016
5 
6 Copyright (c) 2016 Giovanni Paolo Vigano'
7 
8 The source code of the SDL library used by ArkanoidRemakeSDL can be found here:
9 https://www.libsdl.org/
10 ---
11 ArkanoidRemakeSDL source code is licensed with the same zlib license:
12 (http://www.gzip.org/zlib/zlib_license.html)
13 
14 This software is provided 'as-is', without any express or implied warranty. In
15 no event will the authors be held liable for any damages arising from the use of
16 this software.
17 
18 Permission is granted to anyone to use this software for any purpose, including
19 commercial applications, and to alter it and redistribute it freely, subject to
20 the following restrictions:
21 
22  1. The origin of this software must not be misrepresented; you must not
23  claim that you wrote the original software. If you use this software in a
24  product, an acknowledgment in the product documentation would be appreciated
25  but is not required.
26 
27  2. Altered source versions must be plainly marked as such, and must not be
28  misrepresented as being the original software.
29 
30  3. This notice may not be removed or altered from any source distribution.
31 */
32 
33 
37 
38 #pragma once
39 
40 #ifndef ARKANOID_REMAKE_H
41 #define ARKANOID_REMAKE_H
42 
43 #include <cmath>
44 #include <vector>
45 #include <string>
46 #include <map>
47 #include <App.h>
48 #include <VecXy.h>
49 #include <BoxObj.h>
50 #include <DynObj.h>
51 #include <Ball.h>
52 #include <Ship.h>
53 
54 #include <Bonus.h>
55 #include <Block.h>
56 #include <BlockMatrix.h>
57 #include <PlayArea.h>
58 #include <Level.h>
59 
62 
63 
64 
65 
66 
88 class ArkanoidRemake : public App
89 {
90 protected:
91 
94 
97 
100 
102  unsigned int mCurrLevel;
103 
106  double mPrevTime;
107  double mCurrTime;
109 
112 
114  std::vector<Level> mLevel;
115 
117  std::vector<Bonus> mBonus;
118 
120  std::map<std::string,Bonus> mBonusDef;
121 
123  std::string mScoreText;
124 
126  unsigned int mLevelScore;
127 
129  unsigned int mTotalScore;
130 
132  unsigned int mBlocksLeft;
133 
138 
140  virtual void AddLevel();
141 
143  virtual bool SetCurrentLevel(unsigned int n);
144 
146  virtual void GoToNextLevel();
147 
149 
151  virtual void AddScore(int n);
152 
154  virtual void UpdateScoreText();
155 
157  void MoveBallWithShip();
158 
160  void LaunchBall();
161 
163  bool CalculateBallPosition();
164 
166  void CalculateBonusPosition();
167 
169  bool CalculateShipPosition(int x=-1);
170 
172  bool CheckBallBlockCollision(const Block& block, int x, int y);
173 
175  bool CheckBallCollision(int x, int y);
176 
177 public:
178 
180  ArkanoidRemake();
181 
183 
184 
186  virtual bool Init();
187 
189  virtual void Start();
190 
192  virtual void Update();
194 
197 
198 
200  virtual double GetTime()=0;
201 
203  virtual void HandleEvents()=0;
204 
206  virtual void Frame()=0;
208 
210 
211 
213  virtual void HitBlock(Block& block, int x, int y);
214 
216  virtual void HitShip();
217 
219  virtual void GetBonus(const Bonus& bonus);
220 
222  virtual bool DropBonus(const std::string& name, const VecXy& pos);
223 
225  virtual void BonusLost(const Bonus& bonus);
226 
228  virtual void BallLost();
229 
231 };
232 
234 
235 #endif//ARKANOID_REMAKE_H
virtual void GoToNextLevel()
Go to the next level.
Block class definition.
Ball class definition.
unsigned int mTotalScore
Total game score.
Definition: ArkanoidRemake.h:129
virtual bool SetCurrentLevel(unsigned int n)
Set the current level.
virtual bool Init()
App interface implementation.
virtual double GetTime()=0
Get the current time in seconds.
Bonus item, dropped when a wall block is hit.
Definition: Bonus.h:52
virtual void HitShip()
The ship hit the ball.
Game ball definition.
Definition: Ball.h:51
Vector with two (double precision) coordinate values.
Definition: VecXy.h:59
App interface definition.
virtual void HandleEvents()=0
Handle input events.
virtual void AddScore(int n)
Add the givent points to the score.
Ship class definition.
Ship mShip
Ship object.
Definition: ArkanoidRemake.h:99
virtual void AddLevel()
Add a (the only one foer now) new level.
virtual void Frame()=0
Render a frame.
unsigned int mBlocksLeft
Counter for the blocks not yet destroyed.
Definition: ArkanoidRemake.h:132
void CalculateBonusPosition()
Calculate the bonuses position according to their velocity and the play area size.
DynObj class definition.
Level class definition.
std::vector< Level > mLevel
List of game levels.
Definition: ArkanoidRemake.h:114
void LaunchBall()
Launch tha ball (if held by the ship)
virtual void HitBlock(Block &block, int x, int y)
Actions implementation.
virtual void Start()
Initialize the score and go to the first level.
virtual void BonusLost(const Bonus &bonus)
The ship missed a bonus.
virtual bool DropBonus(const std::string &name, const VecXy &pos)
A bonus item was dropped.
Base class for an implementation of a remake of the old game Arkanoid.
Definition: ArkanoidRemake.h:88
Ball mBall
Ball object.
Definition: ArkanoidRemake.h:96
std::vector< Bonus > mBonus
List of dropped bunuses.
Definition: ArkanoidRemake.h:117
Wall block.
Definition: Block.h:52
virtual void GetBonus(const Bonus &bonus)
The ship hit a bonus item.
PlayArea mPlayArea
Play area definition.
Definition: ArkanoidRemake.h:93
Bonus class definition.
ArkanoidRemake()
Constructor: just initialize data members.
unsigned int mCurrLevel
Index of the active level.
Definition: ArkanoidRemake.h:102
Matrix with the wall blocks of the game.
Definition: BlockMatrix.h:52
bool CheckBallCollision(int x, int y)
Check (and manage) the collision between the ball and the walls.
BlockMatrix class definition.
Application interface definition.
Definition: App.h:56
void MoveBallWithShip()
Move the ball along with the ship (when it is attached)
BlockMatrix mBlock
Current blocks configuration.
Definition: ArkanoidRemake.h:111
bool CheckBallBlockCollision(const Block &block, int x, int y)
Check (and manage) the collision between the ball and a block.
virtual void UpdateScoreText()
Update the score text.
std::map< std::string, Bonus > mBonusDef
Bonus definitions (templates for bonus creation)
Definition: ArkanoidRemake.h:120
unsigned int mLevelScore
Score reached within the current level.
Definition: ArkanoidRemake.h:126
Play area definition.
Definition: PlayArea.h:46
bool CalculateShipPosition(int x=-1)
Calculate the ship position according to the play area size.
2-dimensional vector
BoxObj class definition.
virtual void BallLost()
The ship missed the ball.
bool CalculateBallPosition()
Calculate the ball position according to its velocity and the play area size.
Game ship object definition.
Definition: Ship.h:53
virtual void Update()
Update the application (call it in an iteration loop)
std::string mScoreText
Score text buffer.
Definition: ArkanoidRemake.h:123