Skip to content
Snippets Groups Projects
Commit 571b825f authored by PEREUIL THOMAS's avatar PEREUIL THOMAS
Browse files

loop

parent 7b160f8a
No related merge requests found
......@@ -44,6 +44,8 @@
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"ctime": "cpp",
"map": "cpp"
}
}
\ No newline at end of file
......@@ -339,7 +339,7 @@ class Ball
/**
* @brief update the coordinates of the ball
**/
void move();
void move(double t);
/**
* @brief check if there is a collision between the Rect and a Ball
......
......@@ -79,6 +79,8 @@ class Game
**/
bool collisionCheck();
void loop();
~Game();
};
......
......@@ -320,6 +320,12 @@ bool Ball::collision(Ball& b)
return false;
}
void Ball::move(double t)
{
this->x += t*this->speed*cos(this->angle);
this->y += t*this->speed*sin(this->angle);
}
void Ball::bounce(int diffX, int diffY, int a)
{
this->x -= diffX;
......
......@@ -2,6 +2,8 @@
#include <fstream>
#include <string>
#include <cmath>
#include <ctime>
#include <unistd.h>
#include "game.hpp"
#include "bricks.hpp"
......@@ -118,6 +120,25 @@ bool Game::collisionCheck()
return true;
}
void Game::loop()
{
bool isEnd = false;
std::time_t time = std::time(nullptr);
while (! isEnd)
{
std::time_t timeNew = std::time(nullptr);
for (auto baIt = this->balls.begin(); baIt != this->balls.end(); baIt++)
{
*baIt->move(timeNew-time);
}
if (this->collisionCheck())
{
isEnd = true;
}
time = timeNew;
}
}
Game::~Game()
{
for (auto brIt = this->bricks.begin(); brIt != this->bricks.end(); brIt++)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment