mirror of
https://github.com/lov3b/Pong.git
synced 2025-01-18 12:40:12 +01:00
Break out default font
This commit is contained in:
parent
72ea50db30
commit
d4ec09a8fb
@ -32,7 +32,8 @@ add_executable(Pong src/main.cpp
|
|||||||
src/Vec2d/Bump.h
|
src/Vec2d/Bump.h
|
||||||
src/VisibleObjects/PlayerPaddle.h
|
src/VisibleObjects/PlayerPaddle.h
|
||||||
src/VisibleObjects/Side.h
|
src/VisibleObjects/Side.h
|
||||||
src/VisibleObjects/Score.h)
|
src/VisibleObjects/Score.h
|
||||||
|
src/defaultfont.h)
|
||||||
|
|
||||||
# Now link the libraries to the target
|
# 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_LIBRARY} ${SDL2_TTF_LIBRARY})
|
||||||
|
41
src/Game.h
41
src/Game.h
@ -10,6 +10,9 @@
|
|||||||
#include "VisibleObjects/PlayerPaddle.h"
|
#include "VisibleObjects/PlayerPaddle.h"
|
||||||
#include "VisibleObjects/Score.h"
|
#include "VisibleObjects/Score.h"
|
||||||
|
|
||||||
|
enum class GameState {
|
||||||
|
START_SCREEN, GAME, END_SCREEN
|
||||||
|
};
|
||||||
|
|
||||||
class Game : public SdlWrapper {
|
class Game : public SdlWrapper {
|
||||||
private:
|
private:
|
||||||
@ -17,6 +20,9 @@ private:
|
|||||||
Score *score;
|
Score *score;
|
||||||
PlayerPaddle *leftPaddle, *rightPaddle;
|
PlayerPaddle *leftPaddle, *rightPaddle;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GameState gameState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Game(SDL_Point screenSize) : SdlWrapper("Pong", screenSize, 60) {
|
explicit Game(SDL_Point screenSize) : SdlWrapper("Pong", screenSize, 60) {
|
||||||
leftPaddle = new PlayerPaddle(&this->screenSize, Side::LEFT);
|
leftPaddle = new PlayerPaddle(&this->screenSize, Side::LEFT);
|
||||||
@ -29,6 +35,7 @@ public:
|
|||||||
};
|
};
|
||||||
score = new Score(5, &this->screenSize, func);
|
score = new Score(5, &this->screenSize, func);
|
||||||
ball = new Ball(&this->screenSize, leftPaddle, rightPaddle, score);
|
ball = new Ball(&this->screenSize, leftPaddle, rightPaddle, score);
|
||||||
|
gameState = GameState::START_SCREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Game() override {
|
~Game() override {
|
||||||
@ -43,18 +50,36 @@ public:
|
|||||||
SDL_SetRenderDrawColor(renderer, 128, 0, 128, 0);
|
SDL_SetRenderDrawColor(renderer, 128, 0, 128, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
ball->draw(renderer);
|
|
||||||
score->draw(renderer);
|
switch (gameState) {
|
||||||
leftPaddle->draw(renderer);
|
case GameState::START_SCREEN:
|
||||||
rightPaddle->draw(renderer);
|
break;
|
||||||
|
case GameState::GAME:
|
||||||
|
ball->draw(renderer);
|
||||||
|
score->draw(renderer);
|
||||||
|
leftPaddle->draw(renderer);
|
||||||
|
rightPaddle->draw(renderer);
|
||||||
|
break;
|
||||||
|
case GameState::END_SCREEN:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update() override {
|
bool update() override {
|
||||||
ball->update();
|
switch (gameState) {
|
||||||
leftPaddle->update();
|
case GameState::START_SCREEN:
|
||||||
rightPaddle->update();
|
break;
|
||||||
score->update();
|
case GameState::GAME:
|
||||||
|
ball->update();
|
||||||
|
leftPaddle->update();
|
||||||
|
rightPaddle->update();
|
||||||
|
score->update();
|
||||||
|
break;
|
||||||
|
case GameState::END_SCREEN:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,22 +9,13 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include "Side.h"
|
#include "Side.h"
|
||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
|
#include "../defaultfont.h"
|
||||||
|
|
||||||
|
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
const char* defaultFontPath = "C:\\Windows\\Fonts\\Arial.ttf";
|
|
||||||
#elif defined(__linux__)
|
|
||||||
const char *defaultFontPath = "/usr/share/fonts/truetype/DejaVuSans-Bold.ttf";
|
|
||||||
#elif defined(__APPLE__) || defined(__MACH__)
|
|
||||||
const char *defaultFontPath = "/System/Library/Fonts/Supplemental/Arial.ttf";
|
|
||||||
#else
|
|
||||||
const char* defaultFontPath = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
class Score {
|
class Score {
|
||||||
private:
|
private:
|
||||||
|
16
src/defaultfont.h
Normal file
16
src/defaultfont.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by love on 2024-01-24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
const char* defaultFontPath = "C:\\Windows\\Fonts\\Arial.ttf";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
const char *defaultFontPath = "/usr/share/fonts/truetype/DejaVuSans-Bold.ttf";
|
||||||
|
#elif defined(__APPLE__) || defined(__MACH__)
|
||||||
|
const char *defaultFontPath = "/System/Library/Fonts/Supplemental/Arial.ttf";
|
||||||
|
#else
|
||||||
|
const char* defaultFontPath = nullptr;
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user