3 #include "../include/Arkanoid.h"
12 RenderWindow window( VideoMode(
LENGTH,
WIDTH ),
"Arkanoid Game!" );
13 window.setFramerateLimit( 60 );
21 texture1.loadFromFile(
IMAGEPATH+
"block01.png" );
22 texture2.loadFromFile(
IMAGEPATH+
"background.jpg" );
23 texture3.loadFromFile(
IMAGEPATH+
"ball.png" );
24 texture4.loadFromFile(
IMAGEPATH+
"paddle.png" );
25 texture5.loadFromFile(
IMAGEPATH+
"Heart.png" );
27 Sprite s_Background( texture2 );
28 Sprite s_Ball( texture3 );
29 Sprite s_Paddle( texture4 );
30 Sprite s_Lives( texture5 );
32 s_Paddle.setPosition( 300, 440 );
33 s_Ball.setPosition( 300, 300 );
38 for(
int i = 0; i < 3; i++ )
40 lives[i].setTexture( texture5 );
41 lives[i].setPosition( i * 24, 0 );
44 for(
int i = 1; i <= 10; i++)
46 for(
int j = 1; j <= 10; j++)
48 block[
n].setTexture( texture1 );
49 block[
n].setPosition( i * 43, j * 20 );
56 PlayArkanoid( window, s_Background, s_Ball, s_Paddle, block, lives, texture1 );
59 void Arkanoid::CheckCollisions(
float& xAxis,
float& xPos,
float& yAxis,
float& yPos, Sprite* block,
const bool isVertical =
false )
61 for (
int i = 0; i <
n; i++ )
63 if ( FloatRect( xAxis + 3, yAxis + 3, 6, 6).intersects( block[i].getGlobalBounds() ) )
65 block[i].setPosition( -100, 0 );
68 if( isVertical ==
true )
83 if ( ( xAxis < 0 ) || ( xAxis >
LENGTH ) )
88 if ( ( yAxis < 0 ) || ( yAxis >
WIDTH ) )
103 if ( Keyboard::isKeyPressed( Keyboard::Right ) )
105 s_Paddle.move( 6, 0 );
108 if ( Keyboard::isKeyPressed( Keyboard::Left ) )
110 s_Paddle.move( -6, 0 );
118 lives[2].setPosition( -100, 0 );
122 lives[1].setPosition( -100, 0 );
126 lives[0].setPosition( -100, 0 );
138 const int eliminatedBlocksScore = ( eliminatedBlocks * 100 );
159 score = ( eliminatedBlocksScore + heartBonus );
164 void Arkanoid::PlayArkanoid( RenderWindow& window, Sprite& s_Background, Sprite& s_Ball, Sprite& s_Paddle, Sprite* block, Sprite* lives, Texture& texture1 )
173 while ( window.isOpen() )
176 while (window.pollEvent( event ) )
178 if ( event.type == Event::Closed )
199 if ( FloatRect( xAxis, yAxis, 12, 12 ).intersects( s_Paddle.getGlobalBounds() ) )
201 yPos = -( rand() % 5 + 2 );
205 s_Ball.setPosition( xAxis, yAxis );
209 window.draw( s_Background );
210 window.draw( s_Ball );
211 window.draw( s_Paddle );
213 for (
int i = 0; i <
n; i++)
217 window.draw( lives[i] );
219 window.draw( block[i] );
int blocksRemain
Remaining titls.
virtual int CalculateScore()
Pure virtual function inherited from GameGenerics.h Each game calculate scores differently and theref...
const std::string IMAGEPATH
Define path where image are located.
Arkanoid()
Default Constructor. Calls the InitializeVars() function.
const int WIDTH
Define the Width of the window.
int n
The number of tiles in the block. Currently, it has 100 tiles.
void SetBoundaries(float &xAxis, float &xPos, float &yAxis, float &yPos, Sprite *lives)
Set the boundaries so ball will remian inside the window. Also, whenever the ball hits outside the pa...
void InitializeVars()
Create Sprites. Load the Images and set the Sprites. Creates a block of titles with 100 tiles....
bool isGameOver
Set true when user lost all the chances. This indicate time to display game over screen.
int remainingLives
Player has 3 hearts and once it ran out game will be over. Remaining lives are multiple of 2....
const int LENGTH
Define the length of the window. If you want to change this you might need to change the background i...
void SetControls(Sprite &s_Paddle)
Set the paddle to move right and left by pressing right and left arrow keys.
void PlayArkanoid(RenderWindow &window, Sprite &s_Background, Sprite &s_Ball, Sprite &s_Paddle, Sprite *block, Sprite *lives, Texture &texture1)
Start the game and call other helper functions.
void CheckCollisions(float &xAxis, float &xPos, float &yAxis, float &yPos, Sprite *block, const bool isVertical)
This will check collisions with the tiles and the ball. Everytime the ball hit a tile,...
void SetLives(Sprite *lives)
Remove a heart whenever user miss the ball and it hit outside the paddle.
void GameOverScreen(RenderWindow &window)
Display a game over screen at the end of the game alone with user's score. Currently,...