mirror of
https://github.com/lov3b/Pong.git
synced 2025-09-13 00:00:21 +02:00
Hpp and better imports
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.idea
|
||||
cmake-build-*
|
||||
build
|
||||
.cache
|
||||
|
@@ -6,52 +6,36 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
# Option for enabling optimizations
|
||||
option(ENABLE_OPTIMIZATIONS "Enable compiler optimizations" OFF)
|
||||
|
||||
# Base SDL2
|
||||
find_package(SDL2 REQUIRED)
|
||||
# Use pkg-config
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
link_directories(${SDL2_LIBRARY_DIRS})
|
||||
|
||||
# SDL2 Gfx
|
||||
find_library(SDL2_GFX_LIBRARY NAMES SDL2_gfx SDL2_gfxd libSDL2_gfx)
|
||||
if (NOT SDL2_GFX_LIBRARY)
|
||||
message(FATAL_ERROR "SDL2_gfx not found")
|
||||
endif ()
|
||||
pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx)
|
||||
include_directories(${SDL2_GFX_INCLUDE_DIRS})
|
||||
link_directories(${SDL2_GFX_LIBRARY_DIRS})
|
||||
|
||||
find_library(SDL2_TTF_LIBRARY NAMES SDL2_ttf SDL2_TTF SDL2TTF)
|
||||
if (NOT SDL2_TTF_LIBRARY)
|
||||
message(FATAL_ERROR "SDL2_TTF not found")
|
||||
endif ()
|
||||
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
|
||||
include_directories(${SDL2_TTF_INCLUDE_DIRS})
|
||||
link_directories(${SDL2_TTF_LIBRARY_DIRS})
|
||||
|
||||
|
||||
# Define the executable target before linking libraries
|
||||
add_executable(Pong src/main.cpp
|
||||
src/SdlWrapper.h
|
||||
src/SdlWrapper.cpp
|
||||
src/Game.h
|
||||
src/Game.cpp
|
||||
src/VisibleObjects/Ball.h
|
||||
src/VisibleObjects/Ball.cpp
|
||||
src/Vec2d/Vec2d.h
|
||||
src/Vec2d/Vec2d.cpp
|
||||
src/Vec2d/Bump.h
|
||||
src/VisibleObjects/PlayerPaddle.h
|
||||
src/VisibleObjects/PlayerPaddle.cpp
|
||||
src/VisibleObjects/Side.h
|
||||
src/text/TextScreen.h
|
||||
src/text/TextScreen.cpp
|
||||
src/defaultfont.h
|
||||
src/defaultfont.cpp
|
||||
src/icon.h
|
||||
src/icon.cpp
|
||||
src/text/OptionScreen.h
|
||||
src/text/OptionScreen.cpp
|
||||
src/text/Score.h
|
||||
src/text/Score.cpp
|
||||
src/text/ScrollOptionScreen.cpp
|
||||
src/text/ScrollOptionScreen.h
|
||||
)
|
||||
|
||||
# Now link the libraries to the target
|
||||
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARY} ${SDL2_TTF_LIBRARY})
|
||||
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARIES} ${SDL2_TTF_LIBRARIES})
|
||||
|
||||
# Set compiler optimization flags
|
||||
if (ENABLE_OPTIMIZATIONS)
|
||||
@@ -59,7 +43,11 @@ if (ENABLE_OPTIMIZATIONS)
|
||||
set_target_properties(Pong PROPERTIES LINK_SEARCH_START_STATIC 1)
|
||||
set_target_properties(Pong PROPERTIES LINK_SEARCH_END_STATIC 1)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
|
||||
# Apply static linking options only for GCC
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
|
||||
# Make sure that a terminal window doesn't launch under Windows.
|
||||
# We will still launch the terminal if we haven't compiled with optimizations.
|
||||
|
@@ -1,6 +1,8 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "Game.h"
|
||||
#include "Game.hpp"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
Game::Game(SDL_Point screenSize) : SdlWrapper("Pong", screenSize, 60),
|
||||
leftPaddle(new PlayerPaddle(&this->screenSize, Side::LEFT)),
|
||||
|
@@ -2,15 +2,13 @@
|
||||
|
||||
#pragma
|
||||
|
||||
#include "SdlWrapper.h"
|
||||
#include "SDL.h"
|
||||
#include "VisibleObjects/Ball.h"
|
||||
#include "VisibleObjects/PlayerPaddle.h"
|
||||
#include "text/Score.h"
|
||||
#include "text/TextScreen.h"
|
||||
#include "text/OptionScreen.h"
|
||||
#include "text/Score.h"
|
||||
#include "text/ScrollOptionScreen.h"
|
||||
#include "SdlWrapper.hpp"
|
||||
#include "VisibleObjects/Ball.hpp"
|
||||
#include "VisibleObjects/PlayerPaddle.hpp"
|
||||
#include "text/Score.hpp"
|
||||
#include "text/OptionScreen.hpp"
|
||||
#include "text/Score.hpp"
|
||||
#include "text/ScrollOptionScreen.hpp"
|
||||
|
||||
enum class GameState {
|
||||
START_SCREEN, GAME, END_SCREEN
|
@@ -1,6 +1,8 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "SdlWrapper.h"
|
||||
#include "SdlWrapper.hpp"
|
||||
#include "icon.hpp"
|
||||
#include <iostream>
|
||||
|
||||
SdlWrapper::SdlWrapper(const char *const title, const SDL_Point screenSize, const uint8_t fps) : fps(fps), screenSize(
|
||||
screenSize) {
|
||||
|
@@ -2,11 +2,7 @@
|
||||
|
||||
#pragma
|
||||
|
||||
#include <string>
|
||||
#include <SDL_ttf.h>
|
||||
#include <iostream>
|
||||
#include "SDL.h"
|
||||
#include "icon.h"
|
||||
|
||||
class SdlWrapper {
|
||||
private:
|
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "Vec2d.h"
|
||||
#include "Vec2d.hpp"
|
||||
|
||||
Vec2d::Vec2d(float_t hypotenuse) : hypotenuse(hypotenuse) {
|
||||
std::random_device rd;
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "random"
|
||||
#include "ctime"
|
||||
#include "cmath"
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <SDL_stdinc.h>
|
||||
|
||||
#include "SDL_rect.h"
|
||||
#include "Bump.h"
|
||||
#include "Bump.hpp"
|
||||
|
||||
inline double_t toRadians(double_t degrees) {
|
||||
return degrees * M_PI / 100;
|
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "Ball.h"
|
||||
#include "Ball.hpp"
|
||||
|
||||
|
||||
Ball::Ball(const SDL_Point *screen, const PlayerPaddle *leftPaddle, const PlayerPaddle *rightPaddle, Score *score)
|
||||
|
@@ -2,13 +2,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Vec2d/Vec2d.h"
|
||||
#include "PlayerPaddle.h"
|
||||
#include "../Vec2d/Vec2d.hpp"
|
||||
#include "PlayerPaddle.hpp"
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
#include <iostream>
|
||||
#include "optional"
|
||||
#include "../text/Score.h"
|
||||
#include "../text/Score.h"
|
||||
#include "../text/Score.hpp"
|
||||
|
||||
class Ball {
|
||||
private:
|
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "PlayerPaddle.h"
|
||||
#include "PlayerPaddle.hpp"
|
||||
|
||||
|
||||
PlayerPaddle::PlayerPaddle(const SDL_Point *screen, const Side side) : SDL_Rect(), screen(screen) {
|
||||
|
@@ -4,8 +4,8 @@
|
||||
|
||||
#include <SDL_rect.h>
|
||||
#include <SDL_render.h>
|
||||
#include "Side.h"
|
||||
#include "../Vec2d/Bump.h"
|
||||
#include "Side.hpp"
|
||||
#include "../Vec2d/Bump.hpp"
|
||||
|
||||
class PlayerPaddle : public SDL_Rect {
|
||||
private:
|
@@ -1,5 +1,5 @@
|
||||
// This is the bytes of ./icon.bmp
|
||||
#include "icon.h"
|
||||
#include "icon.hpp"
|
||||
|
||||
const unsigned char icon[] = {
|
||||
0x42, 0x4d, 0x9a, 0x76, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "Game.h"
|
||||
#include "Game.hpp"
|
||||
#include <SDL.h>
|
||||
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "OptionScreen.h"
|
||||
#include "OptionScreen.hpp"
|
||||
#include <chrono>
|
||||
#include "../defaultfont.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int_least64_t getCurrentEpochTimeMillis() {
|
||||
|
@@ -2,8 +2,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TextScreen.h"
|
||||
#include "../VisibleObjects/Side.h"
|
||||
#include "TextScreen.hpp"
|
||||
|
||||
|
||||
class OptionScreen : public TextScreen {
|
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "Score.h"
|
||||
#include "Score.hpp"
|
||||
#include <sstream>
|
||||
|
||||
Score::Score(SDL_Point *screenSize, uint8_t max_score) : maxScore_(max_score), leftScore(0), rightScore(0),
|
||||
TextScreen("", screenSize, std::make_optional(
|
||||
|
@@ -3,17 +3,12 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "TextScreen.h"
|
||||
#include <cstdint>
|
||||
#include <SDL_render.h>
|
||||
#include <functional>
|
||||
#include "../VisibleObjects/Side.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include "../defaultfont.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
|
||||
#include "TextScreen.hpp"
|
||||
#include "../VisibleObjects/Side.hpp"
|
||||
|
||||
class Score : public TextScreen {
|
||||
private:
|
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
#include "ScrollOptionScreen.h"
|
||||
#include "ScrollOptionScreen.hpp"
|
||||
#include <iostream>
|
||||
|
||||
std::string textAppendHelper(std::string string, const std::string &toAppend) {
|
||||
string.append("\nMax Score: ");
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "OptionScreen.h"
|
||||
#include "OptionScreen.hpp"
|
||||
|
||||
class ScrollOptionScreen : public OptionScreen {
|
||||
|
@@ -3,8 +3,10 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include "TextScreen.h"
|
||||
#include "optional"
|
||||
#include <optional>
|
||||
#include "TextScreen.hpp"
|
||||
#include "../defaultfont.hpp"
|
||||
#include <iostream>
|
||||
|
||||
std::vector<std::string> splitString(const std::string &string, const char &delim) {
|
||||
int size = 0;
|
||||
|
@@ -4,11 +4,8 @@
|
||||
|
||||
#include <SDL_render.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "../defaultfont.h"
|
||||
#include "iostream"
|
||||
|
||||
struct Position {
|
||||
SDL_Rect shadowPosition;
|
Reference in New Issue
Block a user