-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from better0fdead/for_review_v2
For review v2
- Loading branch information
Showing
97 changed files
with
49,212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.idea | ||
/.vscode | ||
/build | ||
/cmake-build-debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(test) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -lboost_thread --coverage") | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
add_compile_options("--coverage") | ||
|
||
add_subdirectory(libraries/Game) | ||
add_subdirectory(libraries/State) | ||
add_subdirectory(libraries/GameState) | ||
add_subdirectory(libraries/LostState) | ||
add_subdirectory(libraries/Entity) | ||
add_subdirectory(libraries/Character) | ||
add_subdirectory(libraries/Collider) | ||
add_subdirectory(libraries/Stone) | ||
add_subdirectory(libraries/Tyan) | ||
add_subdirectory(libraries/Guardian) | ||
add_subdirectory(libraries/Bullet) | ||
add_subdirectory(libraries/Button) | ||
add_subdirectory(libraries/StateManager) | ||
add_subdirectory(libraries/AssetManager) | ||
add_subdirectory(libraries/MenuState) | ||
add_subdirectory(libraries/PauseState) | ||
add_subdirectory(libraries/GameContext) | ||
add_subdirectory(libraries/utils) | ||
add_subdirectory(libraries/Connecting) | ||
add_subdirectory(libraries/LoadState) | ||
add_subdirectory(libraries/TyanState) | ||
add_subdirectory(libraries/Client) | ||
add_subdirectory(libraries/Tasks) | ||
|
||
|
||
set(SOCKET_LIB libraries/Connecting/common/socket.cpp) | ||
add_library(socket_lib STATIC ${SOCKET_LIB}) | ||
|
||
#enable_testing() | ||
#find_package(GTest REQUIRED) | ||
#add_executable(tests tests/tests.cpp) | ||
#include_directories(${GTEST_INCLUDE_DIRS}) | ||
#target_link_libraries(tests ${GTEST_LIBRARIES} Game State Entity GameState LostState | ||
# Character Collider Stone Tyan Guardian Bullet Button gcov) | ||
|
||
add_executable(main main.cpp) | ||
target_link_libraries(main PUBLIC Game socket_lib Client) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Thank you for downloading this font! | ||
|
||
This font is copyright (c) Jakob Fischer at www.pizzadude.dk, all rights reserved. Do not distribute without the author's permission. | ||
|
||
Use this font for non-commercial use only! If you plan to use it for commercial purposes, contact me before doing so! | ||
|
||
|
||
For more original fonts take a look at www.pizzadude.dk | ||
|
||
Have fun and enjoy! | ||
|
||
Jakob Fischer | ||
jakob@pizzadude.dk | ||
www.pizzadude.dk |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_library(AssetManager STATIC src/AssetManager.cpp) | ||
|
||
target_include_directories(AssetManager PUBLIC include) | ||
target_link_libraries(AssetManager PUBLIC GameContext GameState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <SFML/Graphics/Texture.hpp> | ||
#include <SFML/Graphics/Font.hpp> | ||
|
||
enum class AssetID { | ||
MAIN_FONT = 0, BACKGROUND, GUARDIAN, TYAN, STONE, BULLET, PAUSE, LOST, MENU | ||
}; | ||
|
||
class AssetManager { | ||
public: | ||
AssetManager(); | ||
|
||
~AssetManager(); | ||
|
||
void addTexture(AssetID id, const std::string &fileName, bool wantRepeating = false); | ||
|
||
void addFont(AssetID id, const std::string &fileName); | ||
|
||
const sf::Texture &getTexture(AssetID id) const; | ||
|
||
const sf::Font &getFont(AssetID id) const; | ||
|
||
private: | ||
std::map<AssetID, std::unique_ptr<sf::Texture>> textures; | ||
std::map<AssetID, std::unique_ptr<sf::Font>> fonts; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "AssetManager.hpp" | ||
|
||
AssetManager::AssetManager() {} | ||
|
||
AssetManager::~AssetManager() {} | ||
|
||
void AssetManager::addTexture(AssetID id, const std::string &fileName, bool wantRepeating) { | ||
auto texture = std::make_unique<sf::Texture>(); | ||
|
||
std::string filePath = "../assets/textures/" + fileName; | ||
if (texture->loadFromFile(filePath)) { | ||
texture->setRepeated(wantRepeating); | ||
textures[id] = std::move(texture); | ||
} | ||
} | ||
|
||
void AssetManager::addFont(AssetID id, const std::string &fileName) { | ||
auto font = std::make_unique<sf::Font>(); | ||
|
||
std::string filePath = "../assets/fonts/" + fileName; | ||
if (font->loadFromFile(filePath)) { | ||
fonts[id] = std::move(font); | ||
} | ||
} | ||
|
||
|
||
const sf::Texture &AssetManager::getTexture(AssetID id) const { | ||
return *(textures.at(id).get()); | ||
} | ||
|
||
const sf::Font &AssetManager::getFont(AssetID id) const { | ||
return *(fonts.at(id).get()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_library(Bullet STATIC src/Bullet.cpp) | ||
|
||
target_include_directories(Bullet PUBLIC include) | ||
target_link_libraries(Bullet PUBLIC Entity GameContext) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <valarray> | ||
#include "Entity.hpp" | ||
#include "GameContext.hpp" | ||
|
||
constexpr uint8_t SPEED_BUFF_COEFF = 5; | ||
constexpr uint8_t DEFAULT_SPEED = 7; | ||
constexpr uint8_t DEFAULT_SIZE = 1; | ||
|
||
class Bullet : public Entity { | ||
public: | ||
Bullet(sf::Vector2f position, sf::Vector2f direction, STATES buffType = STATES::normal); | ||
Bullet(float xPos, float yPos, float rotationDegree, float size = 1); | ||
|
||
~Bullet(); | ||
float direction_x; | ||
float direction_y; | ||
|
||
void update(sf::Time deltaTime) override; | ||
|
||
private: | ||
sf::Vector2f directionVectNorm; | ||
float speed; | ||
float size; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "Bullet.hpp" | ||
|
||
Bullet::Bullet(sf::Vector2f position, sf::Vector2f direction, STATES buffType) : speed(DEFAULT_SPEED), | ||
size(DEFAULT_SIZE) { | ||
body.setPosition(position); | ||
|
||
switch (buffType) { | ||
case STATES::normal: { | ||
break; | ||
} | ||
case STATES::bulletSpeedBuff: { | ||
speed *= SPEED_BUFF_COEFF; | ||
break; | ||
} | ||
case STATES::bulletSizeBuff: { | ||
size *= 2; | ||
break; | ||
} | ||
} | ||
|
||
body.scale(size, size); | ||
direction_x = direction.x; | ||
direction_y = direction.y; | ||
// ищем нормированный вектор направления полета пули | ||
auto directionVect = direction - position; | ||
directionVectNorm = directionVect / (float) sqrt(directionVect.x * directionVect.x + | ||
directionVect.y * directionVect.y); | ||
|
||
// вращаем текстурку | ||
body.setRotation((float) (atan2f(directionVectNorm.x, directionVectNorm.y) * (-180.0f / 3.14159265f)) + 90); | ||
} | ||
|
||
Bullet::Bullet(float xPos, float yPos, float rotationDegree, float size) { | ||
body.setPosition(xPos, yPos); | ||
body.setRotation(rotationDegree); | ||
body.scale(sf::Vector2f(size, size)); | ||
} | ||
|
||
Bullet::~Bullet() { | ||
|
||
} | ||
|
||
void Bullet::update(sf::Time deltaTime) { | ||
auto curPos = body.getPosition(); | ||
body.setPosition((curPos + (directionVectNorm * speed))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_library(Button STATIC src/Button.cpp) | ||
|
||
target_include_directories(Button PUBLIC include) | ||
target_link_libraries(Button PUBLIC Entity sfml-graphics sfml-window sfml-system GameContext MenuState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
#ifndef BUTTON_HPP | ||
#define BUTTON_HPP | ||
|
||
|
||
#include <SFML/Window.hpp> | ||
#include <SFML/Graphics.hpp> | ||
#include <iostream> | ||
#include "GameContext.hpp" | ||
#include <memory> | ||
class Button{ | ||
public: | ||
sf::Vector2f position; | ||
sf::Vector2f text_position; | ||
sf::Vector2f icon_position; | ||
sf::RectangleShape rect; | ||
bool is_hovering; | ||
int width, height; | ||
sf::Font font; | ||
sf::Text m_text; | ||
sf::Text m_shadow; | ||
bool is_muted = false; | ||
bool is_answer = false; | ||
Button(){ | ||
rect.setFillColor(sf::Color(0,167,189)); | ||
} | ||
|
||
void setText(std::string s) | ||
{ | ||
m_text.setString(s); | ||
m_shadow = m_text; | ||
}; | ||
|
||
void create(float w, float h, float x, float y, std::string but_text){ | ||
font.loadFromFile("../assets/fonts/ARCADECLASSIC.TTF"); | ||
width = w; | ||
height = h; | ||
position = {x,y}; | ||
text_position = {x + (w / 2), y}; | ||
icon_position = {x + (w / 2), y + h / 2 - 5}; | ||
m_text.setString(but_text); | ||
m_text.setFont(font); | ||
m_text.setCharacterSize(h); | ||
//m_text.setOrigin(x, y); | ||
m_text.setOrigin(m_text.getLocalBounds().width / 2, | ||
m_text.getLocalBounds().height / 2); | ||
m_text.setPosition(text_position); | ||
//m_text.setColor(sf::Color(200,200,200)); | ||
rect.setSize(sf::Vector2f(w,h)); | ||
rect.setPosition(position); | ||
} | ||
|
||
|
||
void draw(std::shared_ptr<GameContext> context) | ||
{ | ||
context->window->draw(rect); | ||
context->window->draw(m_text); | ||
} | ||
void collidepoint(sf::Vector2f mouse){ | ||
if (mouse.x > position.x && | ||
mouse.x < (position.x + width) && | ||
mouse.y > position.y && | ||
mouse.y < position.y + height){ | ||
is_hovering = true; | ||
} | ||
else{ | ||
is_hovering = false; | ||
} | ||
|
||
if (is_hovering) | ||
rect.setFillColor(sf::Color(50,50,50)); | ||
else | ||
rect.setFillColor(sf::Color(0,167,189)); | ||
} | ||
void set_text_size(int h) | ||
{ | ||
m_text.setCharacterSize(h); | ||
//m_text.setOrigin(x, y); | ||
m_text.setOrigin(m_text.getLocalBounds().width / 2, | ||
m_text.getLocalBounds().height / 2); | ||
m_text.setPosition(icon_position); | ||
} | ||
}; | ||
#endif // BUTTON_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
#include "Button.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_library(Character STATIC src/Character.cpp) | ||
|
||
target_include_directories(Character PUBLIC include) | ||
target_link_libraries(Character PUBLIC Entity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include "Entity.hpp" | ||
|
||
constexpr uint8_t DEFAULT_MAX_HP = 1; | ||
|
||
class Character : public Entity { | ||
public: | ||
Character(): HPmax(DEFAULT_MAX_HP), HPcurrent(DEFAULT_MAX_HP) {}; | ||
|
||
virtual ~Character() {}; | ||
|
||
virtual void update(sf::Time deltaTime) = 0; | ||
|
||
void takeDamage(); | ||
|
||
bool isDead(); | ||
|
||
protected: | ||
int HPmax; | ||
int HPcurrent; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "Character.hpp" | ||
|
||
void Character::takeDamage() { | ||
--HPcurrent; | ||
} | ||
|
||
bool Character::isDead() { | ||
return HPcurrent <= 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_library(Client STATIC src/client.cpp) | ||
|
||
find_package(Boost) | ||
include_directories(${Boost_INCLUDE_DIRS}) | ||
|
||
target_include_directories(Client PUBLIC include) | ||
target_link_libraries(Client PUBLIC Bullet Stone ${Boost_LIBRARIES}) |
Oops, something went wrong.