Overoptimizing as per usual (removed a bunch of imaginary variables and cleaned up the code)

This commit is contained in:
Andrew Haynes
2026-02-25 11:29:27 -05:00
parent 49bd8ac080
commit 31c021b50c
5 changed files with 86 additions and 127 deletions
-23
View File
@@ -1,23 +0,0 @@
#ifndef GLOBALS_HPP
#define GLOBALS_HPP
// General
#define TILESIZE 32.0f
#define WIDTH (TILESIZE * 16)
#define HEIGHT (TILESIZE * 13)
#define FPS 60
//Paddle
#define SIZE_X 10
#define SIZE_Y 50
#define POS_Y 200
#define VELOCITY 4
// Ball
#define VELOCITY_X 3
#define VELOCITY_Y 2
#endif
+26 -21
View File
@@ -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