small update
This commit is contained in:
parent
bd090c1b52
commit
4d7579a45e
|
|
@ -17,8 +17,8 @@ struct Ball
|
||||||
sf::Vector2f pos;
|
sf::Vector2f pos;
|
||||||
sf::Vector2f velocity;
|
sf::Vector2f velocity;
|
||||||
sf::Vector2f previousPos{};
|
sf::Vector2f previousPos{};
|
||||||
bool alive{true};
|
bool alive{};
|
||||||
bool collided{false};
|
bool collided{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Brick
|
struct Brick
|
||||||
|
|
@ -26,7 +26,7 @@ struct Brick
|
||||||
Brick(sf::Vector2f position_in);
|
Brick(sf::Vector2f position_in);
|
||||||
|
|
||||||
sf::Vector2f pos;
|
sf::Vector2f pos;
|
||||||
bool alive{true};
|
bool alive{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Player
|
struct Player
|
||||||
|
|
@ -37,10 +37,10 @@ struct Player
|
||||||
sf::Vector2f pos{};
|
sf::Vector2f pos{};
|
||||||
sf::Vector2f previousPos{};
|
sf::Vector2f previousPos{};
|
||||||
int score{};
|
int score{};
|
||||||
int lives{3};
|
int lives{};
|
||||||
int mult{1};
|
int mult{};
|
||||||
bool left{false};
|
bool left{};
|
||||||
bool right{false};
|
bool right{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
|
|
@ -111,7 +111,7 @@ private:
|
||||||
int totalSpecialBricks{};
|
int totalSpecialBricks{};
|
||||||
int totalBricks{};
|
int totalBricks{};
|
||||||
int framerate{};
|
int framerate{};
|
||||||
float volume{10};
|
float volume{};
|
||||||
float playerSpeed{};
|
float playerSpeed{};
|
||||||
float ballRadius{};
|
float ballRadius{};
|
||||||
float ballMaxSpeed{};
|
float ballMaxSpeed{};
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,21 @@
|
||||||
Ball::Ball(sf::Vector2f position_in, sf::Vector2f vel_in)
|
Ball::Ball(sf::Vector2f position_in, sf::Vector2f vel_in)
|
||||||
: pos(position_in)
|
: pos(position_in)
|
||||||
, velocity(vel_in)
|
, velocity(vel_in)
|
||||||
|
, alive(true)
|
||||||
|
, collided(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Brick::Brick(sf::Vector2f position_in)
|
Brick::Brick(sf::Vector2f position_in)
|
||||||
: pos(position_in)
|
: pos(position_in)
|
||||||
|
, alive(true)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Player::Player(sf::Vector2f position_in)
|
Player::Player(sf::Vector2f position_in)
|
||||||
: pos(position_in)
|
: pos(position_in)
|
||||||
|
, lives(3)
|
||||||
|
, mult(1)
|
||||||
|
, left(false)
|
||||||
|
, right{false}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,6 +44,7 @@ Game::Game()
|
||||||
, collideSound(collideSoundBuffer)
|
, collideSound(collideSoundBuffer)
|
||||||
, brickBreakSound(brickBreakSoundBuffer)
|
, brickBreakSound(brickBreakSoundBuffer)
|
||||||
, failSound(failSoundBuffer)
|
, failSound(failSoundBuffer)
|
||||||
|
, volume(10)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!ImGui::SFML::Init(window)) return;
|
if (!ImGui::SFML::Init(window)) return;
|
||||||
|
|
|
||||||
|
|
@ -4,31 +4,45 @@
|
||||||
|
|
||||||
#include <Random.h>
|
#include <Random.h>
|
||||||
|
|
||||||
sf::Vector2f getOverlap(sf::FloatRect first, sf::FloatRect second)
|
sf::Vector2f getOverlap(const sf::FloatRect first, const sf::FloatRect second)
|
||||||
{
|
{
|
||||||
sf::Vector2f result;
|
const float deltaX = std::abs(second.position.x - first.position.x);
|
||||||
sf::Vector2f delta;
|
const float deltaY = std::abs(second.position.y - first.position.y);
|
||||||
delta.x = std::abs(second.position.x - first.position.x);
|
|
||||||
delta.y = std::abs(second.position.y - first.position.y);
|
|
||||||
|
|
||||||
result.x = (first.size.x + second.size.x) - delta.x;
|
const float resultX = (first.size.x + second.size.x) - deltaX;
|
||||||
result.y = (first.size.y + second.size.y) - delta.y;
|
const float resultY = (first.size.y + second.size.y) - deltaY;
|
||||||
return result;
|
return {resultX, resultY};
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f velocityInRandomDir(const float speed_in)
|
sf::Vector2f velocityInRandomDir(const float speed_in)
|
||||||
{
|
{
|
||||||
const bool upOrDown{(bool)Random::get(0,1)};
|
const bool upOrDown{(bool)Random::get(0,1)};
|
||||||
|
const bool leftOrRight{(bool)Random::get(0,1)};
|
||||||
|
|
||||||
// get angle within certain ranges so that the ball does not
|
// get angle within certain ranges so that the ball does not
|
||||||
// start moving straight side to side or up and down
|
// start moving straight side to side or up and down
|
||||||
sf::Angle angle = sf::degrees(upOrDown ? (float)Random::get(225, 315) : (float)Random::get(45, 135));
|
if (upOrDown && leftOrRight)
|
||||||
if (angle.asDegrees() == 90.f || angle.asDegrees() == 270)
|
{// up left
|
||||||
{
|
const sf::Angle angle = sf::degrees((float)Random::get(195, 255));
|
||||||
angle += sf::degrees(1);
|
return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
|
||||||
|
}
|
||||||
|
else if (upOrDown && !leftOrRight)
|
||||||
|
{// up right
|
||||||
|
const sf::Angle angle = sf::degrees((float)Random::get(285, 355));
|
||||||
|
return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
|
||||||
|
}
|
||||||
|
else if (!upOrDown && leftOrRight)
|
||||||
|
{// down left
|
||||||
|
const sf::Angle angle = sf::degrees((float)Random::get(105, 165));
|
||||||
|
return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
|
||||||
|
}
|
||||||
|
else if (!upOrDown && !leftOrRight)
|
||||||
|
{// down right
|
||||||
|
const sf::Angle angle = sf::degrees((float)Random::get(15, 75));
|
||||||
|
return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
|
||||||
}
|
}
|
||||||
|
|
||||||
return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
|
return {0,0};// means something went wrong
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for debugging
|
// used for debugging
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
bool useImgui{true};
|
|
||||||
Game game;
|
Game game;
|
||||||
|
|
||||||
|
// parse command-line arguments
|
||||||
|
bool useImgui{true};
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i], "--noImgui"))
|
if (!strcmp(argv[i], "--noImgui"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue