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