Overoptimizing as per usual (removed a bunch of imaginary variables and cleaned up the code)
This commit is contained in:
+26
-21
@@ -1,25 +1,23 @@
|
||||
#ifndef GRAPHICS_HPP
|
||||
#define GRAPHICS_HPP
|
||||
|
||||
// Ball, Paddle
|
||||
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
|
||||
#include "globals.hpp"
|
||||
constexpr float TILESIZE = 32.0f;
|
||||
constexpr float WIDTH = (TILESIZE * 16);
|
||||
constexpr float HEIGHT = (TILESIZE * 13);
|
||||
|
||||
struct Ball
|
||||
{
|
||||
Ball(sf::Vector2f pos) : velocity({ VELOCITY_X, VELOCITY_Y })
|
||||
{
|
||||
object.setSize({ (float)SIZE_X / 2, (float)SIZE_X / 2 });
|
||||
object.setPosition(pos);
|
||||
};
|
||||
constexpr float SIZE_X = 10.f;
|
||||
constexpr float SIZE_Y = 50.f;
|
||||
constexpr float POS_Y = (HEIGHT / 2) - (SIZE_Y / 2);
|
||||
constexpr float PADDLE_VELOCITY = 4.f;
|
||||
|
||||
sf::Vector2f velocity;
|
||||
sf::RectangleShape object;
|
||||
};
|
||||
constexpr float BALL_VELOCITY_X = 3.f;
|
||||
constexpr float BALL_VELOCITY_Y = 2.f;
|
||||
constexpr float BALL_SIZE = 5.f;
|
||||
|
||||
struct Paddle
|
||||
{
|
||||
@@ -29,17 +27,24 @@ struct Paddle
|
||||
rect.setPosition(pos);
|
||||
};
|
||||
|
||||
int points;
|
||||
int points { 0 };
|
||||
void check_and_move(enum sf::Keyboard::Key key_up,
|
||||
enum sf::Keyboard::Key key_down);
|
||||
sf::RectangleShape rect;
|
||||
};
|
||||
|
||||
void
|
||||
check_and_move();
|
||||
void
|
||||
handle_ball();
|
||||
struct Ball
|
||||
{
|
||||
Ball()
|
||||
{
|
||||
object.setSize({ BALL_SIZE, BALL_SIZE });
|
||||
object.setPosition(
|
||||
{ (WIDTH / 2) - BALL_SIZE, (HEIGHT / 2) - BALL_SIZE });
|
||||
};
|
||||
|
||||
extern Paddle p1;
|
||||
extern Paddle p2;
|
||||
extern Ball ball;
|
||||
sf::Vector2f velocity { BALL_VELOCITY_X, BALL_VELOCITY_Y };
|
||||
sf::RectangleShape object;
|
||||
void handle_ball(Paddle* p1, Paddle* p2);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user