Skip to content

Commit

Permalink
Merge pull request #18 from better0fdead/for_review_v2
Browse files Browse the repository at this point in the history
For review v2
  • Loading branch information
better0fdead authored Dec 28, 2021
2 parents f1db734 + 02e8912 commit 93ee3c5
Show file tree
Hide file tree
Showing 97 changed files with 49,212 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/.vscode
/build
/cmake-build-debug
45 changes: 45 additions & 0 deletions CMakeLists.txt
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 added assets/fonts/ARCADECLASSIC.TTF
Binary file not shown.
14 changes: 14 additions & 0 deletions assets/fonts/pizzadudedotdk.txt
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 added assets/music/theme.wav
Binary file not shown.
Binary file added assets/textures/b1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/b2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fireball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/guardian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/guardian1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/loading.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/manubackground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/menubackground_extrashakal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/pause_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/tyan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions libraries/AssetManager/CMakeLists.txt
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)
29 changes: 29 additions & 0 deletions libraries/AssetManager/include/AssetManager.hpp
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;
};
33 changes: 33 additions & 0 deletions libraries/AssetManager/src/AssetManager.cpp
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());
}
4 changes: 4 additions & 0 deletions libraries/Bullet/CMakeLists.txt
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)
26 changes: 26 additions & 0 deletions libraries/Bullet/include/Bullet.hpp
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;
};
47 changes: 47 additions & 0 deletions libraries/Bullet/src/Bullet.cpp
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)));
}

4 changes: 4 additions & 0 deletions libraries/Button/CMakeLists.txt
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)
84 changes: 84 additions & 0 deletions libraries/Button/include/Button.hpp
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
2 changes: 2 additions & 0 deletions libraries/Button/src/Button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#include "Button.hpp"
4 changes: 4 additions & 0 deletions libraries/Character/CMakeLists.txt
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)
23 changes: 23 additions & 0 deletions libraries/Character/include/Character.hpp
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;
};
9 changes: 9 additions & 0 deletions libraries/Character/src/Character.cpp
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;
}
7 changes: 7 additions & 0 deletions libraries/Client/CMakeLists.txt
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})
Loading

0 comments on commit 93ee3c5

Please sign in to comment.