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/VisibleObjects/PlayerPaddle.h
|
||||
src/VisibleObjects/Side.h
|
||||
src/VisibleObjects/Score.h)
|
||||
src/VisibleObjects/Score.h
|
||||
src/defaultfont.h)
|
||||
|
||||
# Now link the libraries to the target
|
||||
target_link_libraries(Pong ${SDL2_LIBRARIES} ${SDL2_GFX_LIBRARY} ${SDL2_TTF_LIBRARY})
|
||||
|
25
src/Game.h
25
src/Game.h
@ -10,6 +10,9 @@
|
||||
#include "VisibleObjects/PlayerPaddle.h"
|
||||
#include "VisibleObjects/Score.h"
|
||||
|
||||
enum class GameState {
|
||||
START_SCREEN, GAME, END_SCREEN
|
||||
};
|
||||
|
||||
class Game : public SdlWrapper {
|
||||
private:
|
||||
@ -17,6 +20,9 @@ private:
|
||||
Score *score;
|
||||
PlayerPaddle *leftPaddle, *rightPaddle;
|
||||
|
||||
protected:
|
||||
GameState gameState;
|
||||
|
||||
public:
|
||||
explicit Game(SDL_Point screenSize) : SdlWrapper("Pong", screenSize, 60) {
|
||||
leftPaddle = new PlayerPaddle(&this->screenSize, Side::LEFT);
|
||||
@ -29,6 +35,7 @@ public:
|
||||
};
|
||||
score = new Score(5, &this->screenSize, func);
|
||||
ball = new Ball(&this->screenSize, leftPaddle, rightPaddle, score);
|
||||
gameState = GameState::START_SCREEN;
|
||||
}
|
||||
|
||||
~Game() override {
|
||||
@ -43,18 +50,36 @@ public:
|
||||
SDL_SetRenderDrawColor(renderer, 128, 0, 128, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
switch (gameState) {
|
||||
case GameState::START_SCREEN:
|
||||
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);
|
||||
}
|
||||
|
||||
bool update() override {
|
||||
switch (gameState) {
|
||||
case GameState::START_SCREEN:
|
||||
break;
|
||||
case GameState::GAME:
|
||||
ball->update();
|
||||
leftPaddle->update();
|
||||
rightPaddle->update();
|
||||
score->update();
|
||||
break;
|
||||
case GameState::END_SCREEN:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -9,22 +9,13 @@
|
||||
#include <functional>
|
||||
#include "Side.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include "../defaultfont.h"
|
||||
|
||||
|
||||
#include <SDL_ttf.h>
|
||||
#include <string>
|
||||
#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 {
|
||||
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