diff --git a/sem2/DogadinNM/DinoGame/AssetManager.cpp b/sem2/DogadinNM/DinoGame/AssetManager.cpp new file mode 100644 index 00000000..5286cb3b --- /dev/null +++ b/sem2/DogadinNM/DinoGame/AssetManager.cpp @@ -0,0 +1,30 @@ + +#include "AssetManager.hpp" + +AssetManager* AssetManager::sInstance = nullptr; + +AssetManager::AssetManager() +{ + // Разрешить существование только одного AssetManager + // В противном случае сгенерировать исключение + assert(sInstance == nullptr); + sInstance = this; +} +sf::Texture& AssetManager::GetTexture(std::string const& filename) +{ + auto& texMap = sInstance->m_Textures; + + auto pairFound = texMap.find(filename); + + if (pairFound != texMap.end()) + { + return pairFound->second; + } + else + { + auto& texture = texMap[filename]; + texture.loadFromFile(filename); + return texture; + } + +} diff --git a/sem2/DogadinNM/DinoGame/DB/dbUser.db b/sem2/DogadinNM/DinoGame/DB/dbUser.db new file mode 100644 index 00000000..4e15ee2f Binary files /dev/null and b/sem2/DogadinNM/DinoGame/DB/dbUser.db differ diff --git a/sem2/DogadinNM/DinoGame/DatabaseFunc.cpp b/sem2/DogadinNM/DinoGame/DatabaseFunc.cpp new file mode 100644 index 00000000..db41722b --- /dev/null +++ b/sem2/DogadinNM/DinoGame/DatabaseFunc.cpp @@ -0,0 +1,223 @@ +// +// DatabaseFunc.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "DatabaseFunc.hpp" +template + +void split(const std::string &s, char delim, Out result) { + std::istringstream iss(s); + std::string item; + while (std::getline(iss, item, delim)) { + *result++ = item; + } +} +std::vector split(const std::string &s, char delim) { + std::vector elems; + split(s, delim, std::back_inserter(elems)); + return elems; +} + +static int callback(void *pString, int argc, char **argv, char **azColName){ + if (argc>0) { + std::string* str = static_cast(pString); + str->assign(argv[0]); + } + return 0; +} + +void insertUser(Textbox textbox){ + std::string enteringText = textbox.getString(); + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return(1); + } + sql = "INSERT INTO User( id, namespace, balance, inventory) VALUES ('1', '" + enteringText + "', '300', '') ON CONFLICT (id) DO UPDATE SET namespace = '" + enteringText + "', balance = '300', inventory = '' WHERE id ='1';"; + + // Run the SQL (convert the string to a C-String with c_str() ) + rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg); + sqlite3_close(db); +} +void selectInventory (std::string &outInventory){ + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return(1); + } + sql = "Select inventory FROM User WHERE id ='1';"; + + // Run the SQL (convert the string to a C-String with c_str() ) + + rc = sqlite3_exec(db, sql.c_str(), callback, &outInventory, &zErrMsg); + + std::vector splittedInventory = split(outInventory,' '); + sqlite3_close(db); + +} +void selectBalance(sf::Font font, std::string &outStr){ + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return (1); + } + + sql = "Select balance FROM User WHERE id ='1';"; + + // Run the SQL (convert the string to a C-String with c_str() ) + rc = sqlite3_exec(db, sql.c_str(), callback, &outStr, &zErrMsg); + sqlite3_close(db); +} +void selectNamespace(std::string &outStrNamespace){ + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return(1); + } + sql = "Select namespace FROM User WHERE id ='1';"; + + // Run the SQL (convert the string to a C-String with c_str() ) + rc = sqlite3_exec(db, sql.c_str(), callback, &outStrNamespace, &zErrMsg); + sqlite3_close(db); + +} +void updateBalance(std::string outStr, std::string name){ + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return(1); + } + + sql = "UPDATE User SET balance = (balance - 100) WHERE id = '1';"; + rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg); + sql = "Select inventory from User"; + rc = sqlite3_exec(db, sql.c_str(), callback, &outStr, &zErrMsg); + + sql = "Update User SET inventory = '"+outStr+name+" ' WHERE id='1';"; + rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg); + sqlite3_close(db); +} +void updateBalanceAfterWin(){ + // Pointer to SQLite connection + sqlite3 *db; + + // Save any error messages + char *zErrMsg = 0; + + // Save the result of opening the file + int rc; + + // Save any SQL + std::string sql; + + // Save the result of opening the file + rc = sqlite3_open("/Users/admin/Desktop/Progz/DinoGame/DinoGame/dbUser.db", &db); + + if( rc ){ + // Show an error message + std::cout << "DB Error: " << sqlite3_errmsg(db) << std::endl; + // Close the connection + sqlite3_close(db); + // Return an error + return(1); + } + + sql = "UPDATE User SET balance = (balance + 25) WHERE id = '1';"; + rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg); + + sqlite3_close(db); +} diff --git a/sem2/DogadinNM/DinoGame/Headers/Animator.h b/sem2/DogadinNM/DinoGame/Headers/Animator.h new file mode 100644 index 00000000..4f0c76e2 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/Animator.h @@ -0,0 +1,68 @@ +// +// Animator.h +// Souls +// +// Created by Nikitoooooozy) on 25.04.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef Animator_h +#define Animator_h + +#include "includes.h" + +class Animator +{ +public: + struct Animation + { + std::string m_Name; + std::string m_TextureName; + std::vector m_Frames; + sf::Time m_Duration; + bool m_Looping; + Animation(std::string const& name, std::string const& textureName, + sf::Time const& duration, bool looping) :m_Name(name), m_TextureName(textureName), + m_Duration(duration), m_Looping(looping){} + void AddFrames(sf::Vector2i const& startFrom, + sf::Vector2i const& frameSize, unsigned int frames, unsigned int traccia) + { + sf::Vector2i current = startFrom; + for (unsigned int t = 0; t < traccia; t++) { + for (unsigned int i = 0; i < frames; i++) + { + m_Frames.push_back(sf::IntRect(current.x, current.y, frameSize.x, frameSize.y)); + current.x += frameSize.x; + } + current.y += frameSize.y; + current.x = startFrom.x; + } + } + }; + explicit Animator(sf::Sprite& sprite); + + Animator::Animation& CreateAnimation(std::string const& name, + std::string const& textureName, sf::Time const& duration, + bool loop = false ); + + void Update(sf::Time const& dt); + bool SwitchAnimation(std::string const& name); + std::string GetCurrentAnimationName() const; + void restart(); + bool getEndAnim() const + { + return endAnim; + } + bool endAnim = false; + +private: + + Animator::Animation* FindAnimation(std::string const& name); + void SwitchAnimation(Animator::Animation* animation); + sf::Sprite& m_Sprite; + sf::Time m_CurrentTime; + std::list m_Animations; + Animator::Animation* m_CurrentAnimation; +}; + +#endif /* Animator_h */ diff --git a/sem2/DogadinNM/DinoGame/Headers/Animator.hpp b/sem2/DogadinNM/DinoGame/Headers/Animator.hpp new file mode 100644 index 00000000..36c6aeb9 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/Animator.hpp @@ -0,0 +1,69 @@ +// +// Animator.hpp +// DinoGame +// +// Created by Nikitoooooozy) on 21.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef Animator_hpp +#define Animator_hpp + +#include "AssetManager.hpp" +#include "includes.h" + +class Animator +{ +public: + struct Animation + { + std::string m_Name; + std::string m_TextureName; + std::vector m_Frames; + sf::Time m_Duration; + bool m_Looping; + Animation(std::string const& name, std::string const& textureName, + sf::Time const& duration, bool looping) :m_Name(name), m_TextureName(textureName), + m_Duration(duration), m_Looping(looping){} + void AddFrames(sf::Vector2i const& startFrom, + sf::Vector2i const& frameSize, unsigned int frames, unsigned int traccia) + { + sf::Vector2i current = startFrom; + for (unsigned int t = 0; t < traccia; t++) { + for (unsigned int i = 0; i < frames; i++) + { + m_Frames.push_back(sf::IntRect(current.x, current.y, frameSize.x, frameSize.y)); + current.x += frameSize.x; + } + current.y += frameSize.y; + current.x = startFrom.x; + } + } + }; + explicit Animator(sf::Sprite& sprite); + + Animator::Animation& CreateAnimation(std::string const& name, + std::string const& textureName, sf::Time const& duration, + bool loop = false ); + + void Update(sf::Time const& dt); + bool SwitchAnimation(std::string const& name); + std::string GetCurrentAnimationName() const; + void restart(); + bool getEndAnim() const + { + return endAnim; + } + bool endAnim = false; + +private: + + Animator::Animation* FindAnimation(std::string const& name); + void SwitchAnimation(Animator::Animation* animation); + sf::Sprite& m_Sprite; + sf::Time m_CurrentTime; + std::list m_Animations; + Animator::Animation* m_CurrentAnimation; +}; + +#endif /* Animator_hpp */ diff --git a/sem2/DogadinNM/DinoGame/Headers/AssetManager.hpp b/sem2/DogadinNM/DinoGame/Headers/AssetManager.hpp new file mode 100644 index 00000000..362a5acc --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/AssetManager.hpp @@ -0,0 +1,24 @@ + +#ifndef AssetManager_hpp +#define AssetManager_hpp + +#include "includes.h" + +class AssetManager +{ + +public: + AssetManager(); + + static sf::Texture& GetTexture(std::string const& filename); + static sf::SoundBuffer& GetSoundBuffer(std::string const& filename); + static sf::Font& GetFont(std::string const& filename); +private: + + std::map m_Textures; + std::map m_SoundBuffer; + std::map m_Fonts; + + static AssetManager* sInstance; +}; +#endif /* AssetManager_hpp */ diff --git a/sem2/DogadinNM/DinoGame/Headers/DatabaseFunc.hpp b/sem2/DogadinNM/DinoGame/Headers/DatabaseFunc.hpp new file mode 100644 index 00000000..7fc0170d --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/DatabaseFunc.hpp @@ -0,0 +1,20 @@ +// +// DatabaseFunc.hpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef DatabaseFunc_hpp +#define DatabaseFunc_hpp + +#include "includes.h" + +void insertUser(Textbox textbox); +void selectInventory (std::string &outInventory); +void selectBalance(sf::Font font, std::string &outStr); +void selectNamespace(std::string &outStrNamespace); +void updateBalance(std::string outStr, std::string name); +void updateBalanceAfterWin(); +#endif /* DatabaseFunc_hpp */ diff --git a/sem2/DogadinNM/DinoGame/Headers/Graphics.h b/sem2/DogadinNM/DinoGame/Headers/Graphics.h new file mode 100644 index 00000000..1942ddff --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/Graphics.h @@ -0,0 +1,27 @@ +// +// Graphics.h +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + + +#ifndef Graphics_h +#define Graphics_h +#define SCRWIDTH 800 +#define SCRHEIGHT 300 +#include "includes.h" + +using namespace std::this_thread; // sleep_for, sleep_until +using namespace std::chrono; // nanoseconds, system_clock, seconds +void menuWindowPrint(); +void shopWindowPrint(); +void registrationWindowPrint(); +void startWindowPrint(); +void profileWindowPrint(); +void startingBattleWindowPrint(); +void winnerWindowPrint(); +void looserWindowPrint(); +void idleAnimation(sf::Sprite &sprite, std::string output); +#endif /* Graphics_h */ diff --git a/sem2/DogadinNM/DinoGame/Headers/Menu.h b/sem2/DogadinNM/DinoGame/Headers/Menu.h new file mode 100644 index 00000000..93370010 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/Menu.h @@ -0,0 +1,15 @@ +// +// Menu.h +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef Menu_h +#define Menu_h +#include "includes.h" +void menuWindowPrint(); + + +#endif /* Menu_h */ diff --git a/sem2/DogadinNM/DinoGame/Headers/RegisterMenu.h b/sem2/DogadinNM/DinoGame/Headers/RegisterMenu.h new file mode 100644 index 00000000..a53e03aa --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/RegisterMenu.h @@ -0,0 +1,18 @@ +// +// RegisterMenu.h +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef RegisterMenu_h +#define RegisterMenu_h +#define SCRWIDTH 800 +#define SCRHEIGHT 300 +#include "includes.h" +using namespace std::this_thread; // sleep_for, sleep_until +using namespace std::chrono; // nanoseconds, system_clock, seconds +void registrationWindowPrint(); + +#endif /* RegisterMenu_h */ diff --git a/sem2/DogadinNM/DinoGame/Headers/ResourcePath.hpp b/sem2/DogadinNM/DinoGame/Headers/ResourcePath.hpp new file mode 100644 index 00000000..0a009e55 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/ResourcePath.hpp @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2023 Marco Antognini (antognini.marco@gmail.com), +// Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef RESOURCE_PATH_HPP +#define RESOURCE_PATH_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +//////////////////////////////////////////////////////////// +/// \brief Return the path to the resource folder. +/// +/// \return The path to the resource folder associate +/// with the main bundle or an empty string is there is no bundle. +/// +//////////////////////////////////////////////////////////// +std::string resourcePath(void); + +#endif diff --git a/sem2/DogadinNM/DinoGame/Headers/Textbox.hpp b/sem2/DogadinNM/DinoGame/Headers/Textbox.hpp new file mode 100644 index 00000000..7ec59153 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/Textbox.hpp @@ -0,0 +1,41 @@ +// +// Textbox.hpp +// SFML Textbox +// +// Created by Thomas Redding on 9/12/15. +// Copyright © 2015 Thomas Redding. All rights reserved. +// + +#ifndef Textbox_cpp +#define Textbox_cpp + +#include +#include +#include + +class Textbox { +public: + Textbox(sf::RenderWindow &windowToUse, sf::Font &fontToUse); + void setDimensons(double newX, double newY, double newWidth, double newHeight); + void draw(); + void setString(std::string newString); + std::string getString(); + bool pollEvent(sf::Event event); + void setFocus(bool newFocus); + void setReturnEvent(void (*newFunctionToCall)()); +private: + bool isFocused; + double x; + double y; + double width; + double height; + std::string string = ""; + sf::Font &font; + sf::RenderWindow &window; + sf::RectangleShape background; + sf::Text text; + + bool enterText(sf::Uint32 unicode); +}; + +#endif /* Textbox_cpp */ diff --git a/sem2/DogadinNM/DinoGame/Headers/dino.h b/sem2/DogadinNM/DinoGame/Headers/dino.h new file mode 100644 index 00000000..ba9f35d9 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/dino.h @@ -0,0 +1,80 @@ + +enum Terrain { Plain, River, Mountain }; +class Dino { +public: + int STRENGTH; + int DEXTERITY; + int INTELLIGENCE; + std::string ULTY; + float HP = 100; + std::string name; + int cost; +public: + virtual int damage(Terrain terrain) = 0; +}; +class Kira : public Dino +{ +public: + int cost = 100; + Kira() { + STRENGTH = 10; + DEXTERITY = 15; + INTELLIGENCE = 10; + cost = 100; + HP = 100; + name = "Kira"; + } + int damage(Terrain terrain) { + return terrain == Terrain::Mountain ? + 2 * INTELLIGENCE : + terrain == Terrain::River ? + DEXTERITY : + STRENGTH; + } + +}; +class Cole : public Dino +{ +public: + int cost = 100; + Cole() { + STRENGTH = 10; + DEXTERITY = 10; + INTELLIGENCE = 15; + cost = 100; + HP = 100; + name = "Cole"; + } + + int damage(Terrain terrain) { + return terrain == Terrain::River ? + 2 * DEXTERITY : + terrain == Terrain::Plain || terrain == Terrain::Mountain ? + DEXTERITY : + STRENGTH; + } + +}; + + +class Mono : public Dino +{ +public: + int cost = 100; + Mono() { + + STRENGTH = 15; + DEXTERITY = 10; + INTELLIGENCE = 15; + cost = 100; + HP = 100; + name = "Mono"; + } + int damage(Terrain terrain) { + return terrain == Terrain::Plain ? + 2 * STRENGTH : + terrain == Terrain::River ? + DEXTERITY : + INTELLIGENCE; + } +}; diff --git a/sem2/DogadinNM/DinoGame/Headers/includes.h b/sem2/DogadinNM/DinoGame/Headers/includes.h new file mode 100644 index 00000000..798c8034 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Headers/includes.h @@ -0,0 +1,34 @@ +// +// includes.h +// Souls +// +// Created by Nikitoooooozy) on 25.04.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#ifndef includes_h +#define includes_h +#include +#include +#include +#include +#include +#include +#include +#include "dino.h" +#include "Textbox.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ResourcePath.hpp" +#include "AssetManager.hpp" + +#endif /* includes_h */ diff --git a/sem2/DogadinNM/DinoGame/LooserMenu.cpp b/sem2/DogadinNM/DinoGame/LooserMenu.cpp new file mode 100644 index 00000000..7b3d2fff --- /dev/null +++ b/sem2/DogadinNM/DinoGame/LooserMenu.cpp @@ -0,0 +1,148 @@ +// +// LooserMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 17.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "includes.h" +#include "Graphics.h" +#include "DatabaseFunc.hpp" +void looserWindowPrint(){ + // Create window + sf::RenderWindow looserWindow(sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + // Set the Icon + sf::Image icon; + if (!icon.loadFromFile(resourcePath() + "icon.jpg")) { + return EXIT_FAILURE; + } + looserWindow.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); + + // Load a sprite to display + sf::Texture texture; + if (!texture.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite sprite(texture); + + // Create a graphical text to display + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + // + sf::Text text("RIP DINO'S", font); + text.setCharacterSize(165); + text.setFillColor(sf::Color(0,197,208,230)); + text.setStyle(sf::Text::Bold); + + //center text + sf::FloatRect textRect = text.getLocalBounds(); + text.setOrigin(textRect.width/2,textRect.height/2); + text.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT/2.0f - 70)); + + + //text buttons + sf::Text startText; + float startButtonWidth = startText.getLocalBounds().width; + float startButtonHeight = startText.getLocalBounds().height; + startText.setFont( font ); + startText.setStyle( sf::Text::Regular ); + startText.setString( "You are loooooooooooser!!!" ); + startText.setFillColor( sf::Color::Black ); + startText.setCharacterSize( 75 ); + startText.setPosition(75,300); + + + //image buttons + sf::Texture exitButton; + sf::Sprite exitButtonImage; + if ( !exitButton.loadFromFile( resourcePath() + "exitButton.png" ) ) + std::cout << "Can't find the image" << std::endl; + float exitButtonWidth = exitButtonImage.getLocalBounds().width; + float exitButtonHeight = exitButtonImage.getLocalBounds().height; + exitButtonImage.setPosition( exitButtonWidth, exitButtonHeight ); + + exitButtonImage.setTexture( exitButton ); + + //grave 1 + sf::Texture grave1; + sf::Sprite grave1Sprite; + if ( !grave1.loadFromFile( resourcePath() + "grave2.png" ) ) + std::cout << "Can't find the image" << std::endl; + + grave1Sprite.setPosition( 150, 400 ); + grave1Sprite.setScale(3, 3); + grave1Sprite.setTexture( grave1 ); + + //grave2 + sf::Texture grave2; + sf::Sprite grave2Sprite; + if ( !grave2.loadFromFile( resourcePath() + "grave2.png" ) ) + std::cout << "Can't find the image" << std::endl; + grave2Sprite.setPosition( 350, 470 ); + grave2Sprite.setScale(3, 3); + grave2Sprite.setTexture( grave2 ); + + //grave 3 + sf::Texture grave3; + sf::Sprite grave3Sprite; + if ( !grave3.loadFromFile( resourcePath() + "grave2.png" ) ) + std::cout << "Can't find the image" << std::endl; + grave3Sprite.setPosition( 550, 400 ); + grave3Sprite.setScale(3, 3); + grave3Sprite.setTexture( grave3 ); + + while (looserWindow.isOpen()) { + looserWindow.clear(); + + looserWindow.draw(sprite); + looserWindow.draw(startText); + looserWindow.draw(exitButtonImage); + looserWindow.draw(grave1Sprite); + looserWindow.draw(grave2Sprite); + looserWindow.draw(grave3Sprite); + looserWindow.draw(text); + looserWindow.display(); + + sf::Event Event; + + while (looserWindow.pollEvent(Event)) { + switch (Event.type) { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( looserWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + exitButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + exitButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + } + break; + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( looserWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + looserWindow.close(); + menuWindowPrint(); + } + } + break; + } + } + } +} + diff --git a/sem2/DogadinNM/DinoGame/Menu.cpp b/sem2/DogadinNM/DinoGame/Menu.cpp new file mode 100644 index 00000000..f3f04c4c --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Menu.cpp @@ -0,0 +1,229 @@ +// +// Menu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "Graphics.h" + +void menuWindowPrint(){ + + // Create window + sf::RenderWindow window(sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + // Set the Icon + sf::Image icon; + if (!icon.loadFromFile(resourcePath() + "icon.jpg")) { + return EXIT_FAILURE; + } + window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); + + // Load a sprite to display + sf::Texture texture; + if (!texture.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite sprite(texture); + + // Create a graphical text to display + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + // + sf::Text text("Dino Wars", font); + text.setCharacterSize(115); + text.setFillColor(sf::Color(0,197,208,230)); + text.setStyle(sf::Text::Bold); + + //center text + sf::FloatRect textRect = text.getLocalBounds(); + text.setOrigin(textRect.width/2,textRect.height/2); + text.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT/2.0f)); + + //image buttons + sf::Texture exitButton; + sf::Sprite exitButtonImage; + if ( !exitButton.loadFromFile( resourcePath() + "exitButton.png" ) ) + std::cout << "Can't find the image" << std::endl; + float exitButtonWidth = exitButtonImage.getLocalBounds().width; + float exitButtonHeight = exitButtonImage.getLocalBounds().height; + exitButtonImage.setPosition( exitButtonWidth, exitButtonHeight ); + + exitButtonImage.setTexture( exitButton ); + + //text buttons + sf::Text startText; + float startButtonWidth = startText.getLocalBounds().width; + float startButtonHeight = startText.getLocalBounds().height; + startText.setFont( font ); + startText.setStyle( sf::Text::Regular ); + startText.setString( "Create New Profile" ); + startText.setFillColor( sf::Color::Black ); + startText.setCharacterSize( 55 ); + startText.setPosition( 50.0f, 320.0f ); + + sf::Text profileText; + float profileTextWidth = profileText.getLocalBounds().width; + float profileTextHeight = profileText.getLocalBounds().height; + profileText.setFont( font ); + profileText.setStyle( sf::Text::Regular ); + profileText.setString( "Profile" ); + profileText.setFillColor( sf::Color::Black ); + profileText.setCharacterSize( 55 ); + profileText.setPosition( 50.0f, 380.0f ); + + sf::Text shopText; + float shopButtonWidth = shopText.getLocalBounds().width; + float shopButtonHeight = shopText.getLocalBounds().height; + shopText.setFont( font ); + shopText.setStyle( sf::Text::Regular ); + shopText.setString( "Shop" ); + shopText.setFillColor( sf::Color::Black ); + shopText.setCharacterSize( 55 ); + shopText.setPosition( 50.0f, 440.0f ); + + sf::Text battleText; + float battleTextWidth = battleText.getLocalBounds().width; + float battleTextHeight = battleText.getLocalBounds().height; + battleText.setFont( font ); + battleText.setStyle( sf::Text::Regular ); + battleText.setString( "BATTLE" ); + battleText.setFillColor( sf::Color::Black ); + battleText.setCharacterSize( 75 ); + battleText.setPosition( 540.0f, 440.0f ); + + + + + + // Start the game loop + while (window.isOpen()) + { + + // Clear screen + window.clear(); + + // Draw the sprite + window.draw(sprite); + + //Draw the buttons + window.draw( exitButtonImage ); + window.draw( startText ); + window.draw( profileText ); + window.draw( shopText ); + window.draw(battleText); + // Draw the string + window.draw(text); + + // Update the window + window.display(); + + // Process events + sf::Event Event; + + + + while (window.pollEvent(Event)) + { + switch ( Event.type ) + { + break; + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( window ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + exitButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + exitButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + + //if for start button + if ( startText.getGlobalBounds().contains( mousePosF ) ) + { + startText.setFillColor(sf::Color::Red); + } + else + { + startText.setFillColor(sf::Color::Black); + } + + //if for profile button + if ( profileText.getGlobalBounds().contains( mousePosF ) ) + { + profileText.setFillColor(sf::Color::Red); + } + else + { + profileText.setFillColor(sf::Color::Black); + } + + //if for shop button + if ( shopText.getGlobalBounds().contains( mousePosF ) ) + { + shopText.setFillColor(sf::Color::Red); + } + else + { + shopText.setFillColor(sf::Color::Black); + } + //if for battle button + if ( battleText.getGlobalBounds().contains( mousePosF ) ) + { + battleText.setFillColor(sf::Color::Red); + } + else + { + battleText.setFillColor(sf::Color::Black); + } + } + break; + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( window ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + window.close(); + } + //if user registers a new profile + if ( startText.getGlobalBounds().contains( mousePosF ) ) + { + window.close(); + registrationWindowPrint(); + } + //if button shop pressed + if ( shopText.getGlobalBounds().contains( mousePosF )) + { + window.close(); + shopWindowPrint(); + } + //if button profile pressed + if ( profileText.getGlobalBounds().contains( mousePosF )) + { + window.close(); + profileWindowPrint(); + } + //if user starts battle + if (battleText.getGlobalBounds().contains(mousePosF)) + { + window.close(); + startingBattleWindowPrint(); + } + } + break; + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/ProfileMenu.cpp b/sem2/DogadinNM/DinoGame/ProfileMenu.cpp new file mode 100644 index 00000000..0dcc2e1d --- /dev/null +++ b/sem2/DogadinNM/DinoGame/ProfileMenu.cpp @@ -0,0 +1,221 @@ +// +// ProfileMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "Graphics.h" +#include "DatabaseFunc.hpp" +void profileWindowPrint(){ + sf::RenderWindow profileWindow(sf::VideoMode(800,600), "Dino Wars",sf::Style::Resize); + + //background + sf::Texture textureBackground; + if (!textureBackground.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite spriteBackground(textureBackground); + + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + + //button back + sf::Texture backButton; + sf::Sprite backButtonImage; + if ( !backButton.loadFromFile( resourcePath() + "iconButtonBack.png" ) ) + std::cout << "Can't find the image" << std::endl; + float backButtonWidth = backButtonImage.getLocalBounds().width; + float backButtonHeight = backButtonImage.getLocalBounds().height; + backButtonImage.setPosition( backButtonWidth, backButtonHeight ); + + backButtonImage.setTexture( backButton ); + + //title + sf::Text title("Your profile: ", font); + title.setCharacterSize(70); + title.setFillColor(sf::Color(0,197,208,230)); + title.setStyle(sf::Text::Bold); + + //centre upper text + sf::FloatRect textRect = title.getLocalBounds(); + title.setOrigin(textRect.width/2,textRect.height/2); + title.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT * 2.0f)); + + //dino background sprite + //DINOS BACKGROUND SPRITE + sf::Texture backgroundTextureForDinos; + if ( !backgroundTextureForDinos.loadFromFile( resourcePath() + "dinoAssets/dinosBackground.jpg" ) ) + std::cout << "Can't find the image" << std::endl; + + // + int frameNum = 3; + float animationDuration = 1; + sf::Time elapsedTime; + sf::Clock clock; + + + //dino sprite + //KIRA SPRITE + sf::Texture dinoKiraTexture; + if ( !dinoKiraTexture.loadFromFile( resourcePath() + "dinoAssets/Kira/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoKiraSprite(dinoKiraTexture,sf::IntRect(0,0,24,24)); + dinoKiraSprite.setPosition(50, 270); + dinoKiraSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Sprite backgroundKiraSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + sf::Text kiraTextName("Kira ", font); + kiraTextName.setCharacterSize(70); + kiraTextName.setFillColor(sf::Color(0,197,208,230)); + kiraTextName.setStyle(sf::Text::Bold); + kiraTextName.setPosition(85, 190); + backgroundKiraSpriteForDinos.setPosition(70, 270); + backgroundKiraSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + + //COLE SPRITE + sf::Texture dinoColeTexture; + if ( !dinoColeTexture.loadFromFile( resourcePath() + "dinoAssets/Cole/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoColeSprite(dinoColeTexture,sf::IntRect(0,0,24,24)); + dinoColeSprite.setPosition(305, 270); + dinoColeSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Text coleTextName("Cole ", font); + coleTextName.setCharacterSize(70); + coleTextName.setFillColor(sf::Color(0,197,208,230)); + coleTextName.setStyle(sf::Text::Bold); + coleTextName.setPosition(340, 190); + sf::Sprite backgroundColeSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + backgroundColeSpriteForDinos.setPosition(325, 270); + backgroundColeSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + + //sprite MONO + sf::Texture dinoMonoTexture; + if ( !dinoMonoTexture.loadFromFile( resourcePath() + "dinoAssets/Mono/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoMonoSprite(dinoMonoTexture,sf::IntRect(0,0,24,24)); + dinoMonoSprite.setPosition(550, 270); + dinoMonoSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Sprite backgroundMonoSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + sf::Text monoTextName("Mono ", font); + monoTextName.setCharacterSize(70); + monoTextName.setFillColor(sf::Color(0,197,208,230)); + monoTextName.setStyle(sf::Text::Bold); + monoTextName.setPosition(585, 190); + backgroundMonoSpriteForDinos.setPosition(570, 270); + backgroundMonoSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + + //text of namespace + std::string outStrNamespace; + selectNamespace(outStrNamespace); + //text of namespace + sf::Text namespaceText("Namespace: " + outStrNamespace + " ", font, 60); + namespaceText.setFillColor(sf::Color::White); + namespaceText.setStyle(sf::Text::Bold); + namespaceText.setPosition(sf::Vector2f(30,100)); + //text of balance + std::string outStrBalance; + selectBalance(font, outStrBalance); + sf::Text balanceText("Balance: " + outStrBalance, font, 60); + balanceText.setFillColor(sf::Color::White); + balanceText.setStyle(sf::Text::Bold); + balanceText.setPosition(sf::Vector2f(485,100)); + + + + while (profileWindow.isOpen()) { + + sf::Event Event; + sf::Time deltaTime = clock.restart(); + elapsedTime += deltaTime; + float timeAsSecond = elapsedTime.asSeconds(); + + int animFrame = static_cast((timeAsSecond/animationDuration)* static_cast(frameNum))% frameNum; + + dinoKiraSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + dinoColeSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + dinoMonoSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + profileWindow.clear(); + profileWindow.draw(spriteBackground); + profileWindow.draw(backgroundKiraSpriteForDinos); + profileWindow.draw(backgroundColeSpriteForDinos); + profileWindow.draw(backgroundMonoSpriteForDinos); + + std::string outputStr; + std::string outInventory; + selectInventory(outInventory); + std::stringstream ss(outInventory); + + std::vector vector; + + + while (std::getline(ss, outputStr, ' ')) { + + vector.push_back(outputStr); + } + + for (int i = 0; i < vector.size(); i++) { + if (vector[i] == "Kira") { + profileWindow.draw(dinoKiraSprite); + } + + if (vector[i] == "Cole") { + profileWindow.draw(dinoColeSprite); + } + + if (vector[i] == "Mono") { + profileWindow.draw(dinoMonoSprite); + } + + } + + + profileWindow.draw(backButtonImage); + profileWindow.draw(namespaceText); + profileWindow.draw(balanceText); + profileWindow.draw(kiraTextName); + profileWindow.draw(coleTextName); + profileWindow.draw(monoTextName); + + profileWindow.display(); + + while (profileWindow.pollEvent(Event)) { + + switch (Event.type) { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( profileWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + backButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + backButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + break; + } + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( profileWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + profileWindow.close(); + menuWindowPrint(); + } + break; + } + } + } + } + +} diff --git a/sem2/DogadinNM/DinoGame/RegisterMenu.cpp b/sem2/DogadinNM/DinoGame/RegisterMenu.cpp new file mode 100644 index 00000000..345f07f1 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/RegisterMenu.cpp @@ -0,0 +1,125 @@ +// +// RegisterMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// +#include "Graphics.h" +#include "DatabaseFunc.hpp" + +void registrationWindowPrint(){ + + sf::RenderWindow startWindow(sf::VideoMode(800,600), "Dino Wars",sf::Style::Resize); + + + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + + //background + sf::Texture textureBackground; + if (!textureBackground.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite spriteBackground(textureBackground); + + //button back + sf::Texture backButton; + sf::Sprite backButtonImage; + if ( !backButton.loadFromFile( resourcePath() + "iconButtonBack.png" ) ) + std::cout << "Can't find the image" << std::endl; + float backButtonWidth = backButtonImage.getLocalBounds().width; + float backButtonHeight = backButtonImage.getLocalBounds().height; + backButtonImage.setPosition( backButtonWidth, backButtonHeight ); + + backButtonImage.setTexture( backButton ); + + //title + sf::Text title("Type your nickname", font); + title.setCharacterSize(70); + title.setFillColor(sf::Color(0,197,208,230)); + title.setStyle(sf::Text::Bold); + + //centre upper text + title.setPosition(sf::Vector2f(SCRWIDTH/5.0f,SCRHEIGHT * 0.015f)); + + //text of registration + sf::Text registeredText("Yep, you've registered", font); + registeredText.setCharacterSize(70); + registeredText.setFillColor(sf::Color(0,197,208,230)); + registeredText.setStyle(sf::Text::Bold); + + //centre upper text + registeredText.setPosition(sf::Vector2f(100,300)); + + //textbox + Textbox textbox(startWindow, font); + textbox.setDimensons(100, 200, 400, 30); + textbox.setFocus(true); + + + + while (startWindow.isOpen()) { + // Process events + sf::Event Event; + startWindow.draw(spriteBackground); + startWindow.draw(backButtonImage); + startWindow.draw(title); + textbox.draw(); + startWindow.display(); + + while (startWindow.pollEvent(Event)) + { + switch ( Event.type ) + { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( startWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + backButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + backButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + }break; + + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( startWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + startWindow.close(); + menuWindowPrint(); + } + }break; + + } + std::string enteringText = textbox.getString(); + bool didHitReturn = textbox.pollEvent(Event); + if(didHitReturn) { + title.setString(enteringText); + } + + if (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Return) { + startWindow.draw(registeredText); + startWindow.display(); + sleep_until(system_clock::now() + seconds(3)); + + insertUser(textbox); + + textbox.setFocus(false); + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/ResourcePath.mm b/sem2/DogadinNM/DinoGame/ResourcePath.mm new file mode 100644 index 00000000..cd6bd78d --- /dev/null +++ b/sem2/DogadinNM/DinoGame/ResourcePath.mm @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2023 Marco Antognini (antognini.marco@gmail.com), +// Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include "ResourcePath.hpp" +#import + +//////////////////////////////////////////////////////////// +std::string resourcePath(void) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + std::string rpath; + NSBundle* bundle = [NSBundle mainBundle]; + + if (bundle == nil) { +#ifdef DEBUG + NSLog(@"bundle is nil... thus no resources path can be found."); +#endif + } else { + NSString* path = [bundle resourcePath]; + rpath = [path UTF8String] + std::string("/"); + } + + [pool drain]; + + return rpath; +} diff --git a/sem2/DogadinNM/DinoGame/Resources/background.jpg b/sem2/DogadinNM/DinoGame/Resources/background.jpg new file mode 100644 index 00000000..820c7b60 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/background.jpg differ diff --git a/sem2/DogadinNM/DinoGame/Resources/battleButton.png b/sem2/DogadinNM/DinoGame/Resources/battleButton.png new file mode 100644 index 00000000..d17d6ebc Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/battleButton.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/blackberry.otf b/sem2/DogadinNM/DinoGame/Resources/blackberry.otf new file mode 100644 index 00000000..d52536ad Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/blackberry.otf differ diff --git a/sem2/DogadinNM/DinoGame/Resources/doodle_pop.ogg b/sem2/DogadinNM/DinoGame/Resources/doodle_pop.ogg new file mode 100644 index 00000000..555ea348 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/doodle_pop.ogg differ diff --git a/sem2/DogadinNM/DinoGame/Resources/exitButton.png b/sem2/DogadinNM/DinoGame/Resources/exitButton.png new file mode 100644 index 00000000..72449d75 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/exitButton.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/grave2.png b/sem2/DogadinNM/DinoGame/Resources/grave2.png new file mode 100644 index 00000000..b7a932b5 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/grave2.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/greenbar.png b/sem2/DogadinNM/DinoGame/Resources/greenbar.png new file mode 100644 index 00000000..4402aba4 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/greenbar.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/greenbarUpper.png b/sem2/DogadinNM/DinoGame/Resources/greenbarUpper.png new file mode 100644 index 00000000..dbc9f766 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/greenbarUpper.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/icon.jpg b/sem2/DogadinNM/DinoGame/Resources/icon.jpg new file mode 100644 index 00000000..1c17a5f3 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/icon.jpg differ diff --git a/sem2/DogadinNM/DinoGame/Resources/iconButtonBack.png b/sem2/DogadinNM/DinoGame/Resources/iconButtonBack.png new file mode 100644 index 00000000..1b7b77f9 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/iconButtonBack.png differ diff --git a/sem2/DogadinNM/DinoGame/Resources/plainBackground.jpg b/sem2/DogadinNM/DinoGame/Resources/plainBackground.jpg new file mode 100644 index 00000000..d0eeb99d Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/plainBackground.jpg differ diff --git a/sem2/DogadinNM/DinoGame/Resources/riverBackground.jpg b/sem2/DogadinNM/DinoGame/Resources/riverBackground.jpg new file mode 100644 index 00000000..bbe8ddc6 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/Resources/riverBackground.jpg differ diff --git a/sem2/DogadinNM/DinoGame/ShopMenu.cpp b/sem2/DogadinNM/DinoGame/ShopMenu.cpp new file mode 100644 index 00000000..db87676f --- /dev/null +++ b/sem2/DogadinNM/DinoGame/ShopMenu.cpp @@ -0,0 +1,345 @@ +// +// ShopMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "Graphics.h" +#include "DatabaseFunc.hpp" + + +void shopWindowPrint(){ + + sf::RenderWindow shopWindow(sf::VideoMode(800,600), "Dino Wars",sf::Style::Resize); + + //background + sf::Texture textureBackground; + if (!textureBackground.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite spriteBackground(textureBackground); + + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + + //dinos names + sf::Text kiraNamespaceText; + kiraNamespaceText.setString(Kira().name); + kiraNamespaceText.setFont( font ); + kiraNamespaceText.setFillColor( sf::Color(0,197,208,230) ); + kiraNamespaceText.setCharacterSize( 40 ); + kiraNamespaceText.setPosition( 60, 80 ); + + sf::Text coleNamespaceText; + coleNamespaceText.setString(Cole().name); + coleNamespaceText.setFont( font ); + coleNamespaceText.setFillColor( sf::Color(0,197,208,230) ); + coleNamespaceText.setCharacterSize( 40 ); + coleNamespaceText.setPosition( 60, 250 ); + + sf::Text monoNamespaceText; + monoNamespaceText.setString(Mono().name); + monoNamespaceText.setFont( font ); + monoNamespaceText.setFillColor( sf::Color(0,197,208,230) ); + monoNamespaceText.setCharacterSize( 40 ); + monoNamespaceText.setPosition( 60, 420 ); + + //dino sprite + //KIRA SPRITE + sf::Texture dinoKiraTexture; + if ( !dinoKiraTexture.loadFromFile( resourcePath() + "dinoAssets/Kira/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoKiraSprite(dinoKiraTexture,sf::IntRect(0,0,24,24)); + dinoKiraSprite.setPosition(0, 100); + dinoKiraSprite.setScale(sf::Vector2f(7.0f,7.0f)); + + //COLE SPRITE + sf::Texture dinoColeTexture; + if ( !dinoColeTexture.loadFromFile( resourcePath() + "dinoAssets/Cole/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoColeSprite(dinoColeTexture,sf::IntRect(0,0,24,24)); + dinoColeSprite.setPosition(0, 270); + dinoColeSprite.setScale(sf::Vector2f(7.0f,7.0f)); + + //sprite MONO + sf::Texture dinoMonoTexture; + if ( !dinoMonoTexture.loadFromFile( resourcePath() + "dinoAssets/Mono/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoMonoSprite(dinoMonoTexture,sf::IntRect(0,0,24,24)); + dinoMonoSprite.setPosition(0, 440); + dinoMonoSprite.setScale(sf::Vector2f(7.0f,7.0f)); + + //dino characteristics text + //KIRA CHARACTERISTICS + sf::Text dinoKiraCharacteristics("Strength - " + std::to_string(Kira().STRENGTH) + "\nDexteriry - " + std::to_string(Kira().DEXTERITY) + "\nIntelegience - " + std::to_string(Kira().INTELLIGENCE), font, 40); + dinoKiraCharacteristics.setFillColor(sf::Color::Black); + dinoKiraCharacteristics.setStyle(sf::Text::Bold); + dinoKiraCharacteristics.setPosition(sf::Vector2f(200,115)); + + //COLE CHARACTERISTICS + sf::Text dinoColeCharacteristics("Strength - " + std::to_string(Cole().STRENGTH) + "\nDexteriry - " + std::to_string(Cole().DEXTERITY) + "\nIntelegience - " + std::to_string(Cole().INTELLIGENCE), font, 40); + dinoColeCharacteristics.setFillColor(sf::Color::Black); + dinoColeCharacteristics.setStyle(sf::Text::Bold); + dinoColeCharacteristics.setPosition(sf::Vector2f(200,285)); + + //MONO CHARACTERISTICS + sf::Text dinoMonoCharacteristics("Strength - " + std::to_string(Mono().STRENGTH) + "\nDexteriry - " + std::to_string(Mono().DEXTERITY) + "\nIntelegience - " + std::to_string(Mono().INTELLIGENCE), font, 40); + dinoMonoCharacteristics.setFillColor(sf::Color::Black); + dinoMonoCharacteristics.setStyle(sf::Text::Bold); + dinoMonoCharacteristics.setPosition(sf::Vector2f(200,455)); + + + //dino button + //BUTTON FOR KIRA + sf::Text buttonKiraBuyText; + float buttonKiraBuyTextWidth = buttonKiraBuyText.getLocalBounds().width; + float buttonKiraBuyTextHeight = buttonKiraBuyText.getLocalBounds().height; + buttonKiraBuyText.setFont( font ); + buttonKiraBuyText.setStyle( sf::Text::Regular ); + buttonKiraBuyText.setString( "BUY" ); + buttonKiraBuyText.setFillColor( sf::Color::Black ); + buttonKiraBuyText.setCharacterSize( 55 ); + buttonKiraBuyText.setPosition(sf::Vector2f(600,145)); + + //BUTTON FOR COLE + sf::Text buttonColeBuyText; + float buttonColeBuyTextWidth = buttonColeBuyText.getLocalBounds().width; + float buttonColeBuyTextHeight = buttonColeBuyText.getLocalBounds().height; + buttonColeBuyText.setFont( font ); + buttonColeBuyText.setStyle( sf::Text::Regular ); + buttonColeBuyText.setString( "BUY" ); + buttonColeBuyText.setFillColor( sf::Color::Black ); + buttonColeBuyText.setCharacterSize( 55 ); + buttonColeBuyText.setPosition(sf::Vector2f(600,290)); + + //BUTTON FOR MONO + sf::Text buttonMonoBuyText; + float buttonMonoBuyTextWidth = buttonMonoBuyText.getLocalBounds().width; + float buttonMonoBuyTextHeight = buttonMonoBuyText.getLocalBounds().height; + buttonMonoBuyText.setFont( font ); + buttonMonoBuyText.setStyle( sf::Text::Regular ); + buttonMonoBuyText.setString( "BUY" ); + buttonMonoBuyText.setFillColor( sf::Color::Black ); + buttonMonoBuyText.setCharacterSize( 55 ); + buttonMonoBuyText.setPosition(sf::Vector2f(600,470)); + + //button back + sf::Texture backButton; + sf::Sprite backButtonImage; + if ( !backButton.loadFromFile( resourcePath() + "iconButtonBack.png" ) ) + std::cout << "Can't find the image" << std::endl; + float backButtonWidth = backButtonImage.getLocalBounds().width; + float backButtonHeight = backButtonImage.getLocalBounds().height; + backButtonImage.setPosition( backButtonWidth, backButtonHeight ); + + backButtonImage.setTexture( backButton ); + + //title + sf::Text title("Dino Shop", font); + title.setCharacterSize(70); + title.setFillColor(sf::Color(0,197,208,230)); + title.setStyle(sf::Text::Bold); + + //centre upper text + sf::FloatRect textRect = title.getLocalBounds(); + title.setOrigin(textRect.width/2,textRect.height/2); + title.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT * 0.05f)); + + + int frameNum = 3; + float animationDuration = 1; + + sf::Time elapsedTime; + sf::Clock clock; + + while (shopWindow.isOpen()) { + + sf::Time deltaTime = clock.restart(); + elapsedTime += deltaTime; + float timeAsSecond = elapsedTime.asSeconds(); + + int animFrame = static_cast((timeAsSecond/animationDuration)* static_cast(frameNum))% frameNum; + + dinoKiraSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + dinoColeSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + dinoMonoSprite.setTextureRect(sf::IntRect(animFrame*24,0,24,24)); + + // Process events + sf::Event Event; + + // Clear screen + shopWindow.clear(); + shopWindow.draw(spriteBackground); + std::string outInventory; + std::string outStr; + selectInventory(outInventory); + selectBalance(font, outStr); + + //text of balance + sf::Text balanceText("Balance: " + outStr, font, 30); + balanceText.setFillColor(sf::Color(0,197,208,230)); + balanceText.setStyle(sf::Text::Bold); + balanceText.setPosition(sf::Vector2f(600,40)); + + if (outInventory == "") { + shopWindow.draw(buttonKiraBuyText); + shopWindow.draw(buttonColeBuyText); + shopWindow.draw(buttonMonoBuyText); + + } + std::string outputStr; + + std::stringstream ss(outInventory); + + std::vector vector; + + + while (std::getline(ss, outputStr, ' ')) { + + vector.push_back(outputStr); + } + + for (int i = 0; i < vector.size(); i++) { + if (vector[i] == "Kira") { + buttonKiraBuyText.setString("Purchased"); + buttonKiraBuyText.setFillColor(sf::Color::Red); + shopWindow.draw(buttonKiraBuyText); + } + else { + shopWindow.draw(buttonKiraBuyText); + } + + if (vector[i] == "Cole") { + buttonColeBuyText.setString("Purchased"); + buttonColeBuyText.setFillColor(sf::Color::Red); + shopWindow.draw(buttonColeBuyText); + } + else { + shopWindow.draw(buttonColeBuyText); + } + + if (vector[i] == "Mono") { + buttonMonoBuyText.setString("Purchased"); + buttonMonoBuyText.setFillColor(sf::Color::Red); + shopWindow.draw(buttonMonoBuyText); + } + else { + shopWindow.draw(buttonMonoBuyText); + } + } + + + // Draw the sprite + shopWindow.draw( dinoKiraSprite ); + shopWindow.draw( dinoColeSprite ); + shopWindow.draw( dinoMonoSprite ); + shopWindow.draw(backButtonImage); + + + // Draw the string + shopWindow.draw(title); + shopWindow.draw(dinoKiraCharacteristics); + shopWindow.draw(dinoColeCharacteristics); + shopWindow.draw(dinoMonoCharacteristics); + shopWindow.draw(balanceText); + shopWindow.draw(kiraNamespaceText); + shopWindow.draw(coleNamespaceText); + shopWindow.draw(monoNamespaceText); + + + // Update the window + shopWindow.display(); + + while (shopWindow.pollEvent(Event)) + { + switch ( Event.type ) + { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( shopWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for button BUY Kira + if ( buttonKiraBuyText.getGlobalBounds().contains( mousePosF ) && buttonKiraBuyText.getString() == "BUY" && outStr != "0") + { + buttonKiraBuyText.setFillColor(sf::Color::Red); + } + else + { + buttonKiraBuyText.setFillColor(sf::Color::Black); + } + + //if for button BUY Cole + if ( buttonColeBuyText.getGlobalBounds().contains( mousePosF ) && buttonColeBuyText.getString() == "BUY" && outStr != "0") + { + buttonColeBuyText.setFillColor(sf::Color::Red); + } + else + { + buttonColeBuyText.setFillColor(sf::Color::Black); + } + + //if for button BUY Mono + if ( buttonMonoBuyText.getGlobalBounds().contains( mousePosF ) && buttonMonoBuyText.getString() == "BUY" && outStr != "0") + { + buttonMonoBuyText.setFillColor(sf::Color::Red); + } + else + { + buttonMonoBuyText.setFillColor(sf::Color::Black); + } + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + backButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + backButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + break; + } + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( shopWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + shopWindow.close(); + menuWindowPrint(); + } + if (buttonKiraBuyText.getGlobalBounds().contains(mousePosF) && outStr != "0" && buttonKiraBuyText.getString() == "BUY") + { + updateBalance(outStr, Kira().name); + buttonKiraBuyText.setString("Purchased"); + sleep_until(system_clock::now() + seconds(2)); + + } + if (buttonColeBuyText.getGlobalBounds().contains(mousePosF) && outStr != "0" && buttonColeBuyText.getString() == "BUY") + { + updateBalance(outStr, Cole().name); + buttonColeBuyText.setString("Purchased"); + sleep_until(system_clock::now() + seconds(2)); + + } + if (buttonMonoBuyText.getGlobalBounds().contains(mousePosF) && outStr != "0" && buttonMonoBuyText.getString() == "BUY") + { + updateBalance(outStr, Mono().name); + buttonMonoBuyText.setString("Purchased"); + sleep_until(system_clock::now() + seconds(2)); + + } + break; + } + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/StartMenu.cpp b/sem2/DogadinNM/DinoGame/StartMenu.cpp new file mode 100644 index 00000000..8b936e3a --- /dev/null +++ b/sem2/DogadinNM/DinoGame/StartMenu.cpp @@ -0,0 +1,143 @@ +// +// StartMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "./Graphics.h" + +void startWindowPrint(){ + // Load a music to play + sf::Music music; + if (!music.openFromFile(resourcePath() + "doodle_pop.ogg")) { + return EXIT_FAILURE; + } + + // Play the music + music.setLoop(true); + music.setVolume(70); + music.play(); + + + BeginWindow: + // Create window + sf::RenderWindow beginWindow(sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + // Set the Icon + sf::Image icon; + if (!icon.loadFromFile(resourcePath() + "icon.jpg")) { + return EXIT_FAILURE; + } + beginWindow.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); + + // Load a sprite to display + sf::Texture texture; + if (!texture.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite sprite(texture); + + // Create a graphical text to display + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + // + sf::Text text("Dino Wars", font); + text.setCharacterSize(165); + text.setFillColor(sf::Color(0,197,208,230)); + text.setStyle(sf::Text::Bold); + + //center text + sf::FloatRect textRect = text.getLocalBounds(); + text.setOrigin(textRect.width/2,textRect.height/2); + text.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT/2.0f)); + + + //text buttons + sf::Text startText; + float startButtonWidth = startText.getLocalBounds().width; + float startButtonHeight = startText.getLocalBounds().height; + startText.setFont( font ); + startText.setStyle( sf::Text::Regular ); + startText.setString( "Start the game" ); + startText.setFillColor( sf::Color::Black ); + startText.setCharacterSize( 75 ); + + startText.setOrigin(textRect.width/2,textRect.height/2); + startText.setPosition(sf::Vector2f(SCRWIDTH/1.57f,SCRHEIGHT/0.8f)); + + //image buttons + sf::Texture exitButton; + sf::Sprite exitButtonImage; + if ( !exitButton.loadFromFile( resourcePath() + "exitButton.png" ) ) + std::cout << "Can't find the image" << std::endl; + float exitButtonWidth = exitButtonImage.getLocalBounds().width; + float exitButtonHeight = exitButtonImage.getLocalBounds().height; + exitButtonImage.setPosition( exitButtonWidth, exitButtonHeight ); + + exitButtonImage.setTexture( exitButton ); + + while (beginWindow.isOpen()) { + beginWindow.clear(); + + beginWindow.draw(sprite); + beginWindow.draw(startText); + beginWindow.draw(exitButtonImage); + beginWindow.draw(text); + beginWindow.display(); + + sf::Event Event; + + while (beginWindow.pollEvent(Event)) { + switch (Event.type) { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( beginWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + exitButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + exitButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + + //if for start button + if ( startText.getGlobalBounds().contains( mousePosF ) ) + { + startText.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + startText.setColor( sf::Color::Black ); + } + } + break; + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( beginWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + beginWindow.close(); + } + + //if for button start + if (startText.getGlobalBounds().contains(mousePosF)) { + beginWindow.close(); + menuWindowPrint(); + } + } + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/StartingBattleMenu.cpp b/sem2/DogadinNM/DinoGame/StartingBattleMenu.cpp new file mode 100644 index 00000000..d14475d6 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/StartingBattleMenu.cpp @@ -0,0 +1,725 @@ +// +// StartingBattleMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 16.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "Graphics.h" +#include "DatabaseFunc.hpp" + +AssetManager manager; +bool needToDrawEnemyGrave = false; +bool needToDrawMyGrave = false; + +void idleAnimation(sf::Sprite &sprite, std::string output){ + sprite.setTexture(AssetManager::GetTexture(resourcePath() + + "dinoAssets/"+ output +"/idle.png")); +} +auto callback = []() { + std::cout << "Timer expired!" << std::endl; + }; + +void startingBattleWindowPrint(){ + + int killCounter = 0; + sf::RenderWindow battleWindow (sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + //vectors to post and pull from inventory + std::vector vector; + std::vector vectorDinosReady; + + //background + sf::Texture textureBackground; + if (!textureBackground.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite spriteBackground(textureBackground); + + + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + + //TITLE + sf::Text titleBattle ("Choose your dino's", font); + titleBattle.setFillColor(sf::Color::White); + titleBattle.setCharacterSize(60); + titleBattle.setPosition(sf::Vector2f(175,20)); + titleBattle.setStyle(sf::Text::Bold); + + + //dino button + //BUTTON FOR KIRA + sf::Text buttonKiraPickText; + float buttonKiraPickTextWidth = buttonKiraPickText.getLocalBounds().width; + float buttonKiraPickTextHeight = buttonKiraPickText.getLocalBounds().height; + buttonKiraPickText.setFont( font ); + buttonKiraPickText.setStyle( sf::Text::Regular ); + buttonKiraPickText.setString( "PICK" ); + buttonKiraPickText.setFillColor( sf::Color::Black ); + buttonKiraPickText.setCharacterSize( 55 ); + buttonKiraPickText.setPosition(sf::Vector2f(85,480)); + + //BUTTON FOR COLE + sf::Text buttonColePickText; + float buttonColePickTextWidth = buttonColePickText.getLocalBounds().width; + float buttonColePickTextTextHeight = buttonColePickText.getLocalBounds().height; + buttonColePickText.setFont( font ); + buttonColePickText.setStyle( sf::Text::Regular ); + buttonColePickText.setString( "PICK" ); + buttonColePickText.setFillColor( sf::Color::Black ); + buttonColePickText.setCharacterSize( 55 ); + buttonColePickText.setPosition(sf::Vector2f(345,480)); + + //BUTTON FOR MONO + sf::Text buttonMonoPickText; + float buttonMonoPickTextWidth = buttonMonoPickText.getLocalBounds().width; + float buttonMonoPickTextHeight = buttonMonoPickText.getLocalBounds().height; + buttonMonoPickText.setFont( font ); + buttonMonoPickText.setStyle( sf::Text::Regular ); + buttonMonoPickText.setString( "PICK" ); + buttonMonoPickText.setFillColor( sf::Color::Black ); + buttonMonoPickText.setCharacterSize( 55 ); + buttonMonoPickText.setPosition(sf::Vector2f(595,480)); + + //button back + sf::Texture backButton; + sf::Sprite backButtonImage; + if ( !backButton.loadFromFile( resourcePath() + "iconButtonBack.png" ) ) + std::cout << "Can't find the image" << std::endl; + float backButtonWidth = backButtonImage.getLocalBounds().width; + float backButtonHeight = backButtonImage.getLocalBounds().height; + backButtonImage.setPosition( backButtonWidth, backButtonHeight ); + + backButtonImage.setTexture( backButton ); + + //button start battle + sf::Texture startButton; + sf::Sprite startButtonImage; + if ( !startButton.loadFromFile( resourcePath() + "battleButton.png" ) ) + std::cout << "Can't find the image" << std::endl; + startButtonImage.setPosition( 700, 20 ); + startButtonImage.setTexture( startButton ); + + //dino background sprite + //DINOS BACKGROUND SPRITE + sf::Texture backgroundTextureForDinos; + if ( !backgroundTextureForDinos.loadFromFile( resourcePath() + "dinoAssets/dinosBackground.jpg" ) ) + std::cout << "Can't find the image" << std::endl; + + //dino sprite + //KIRA SPRITE + sf::Texture dinoKiraTexture; + if ( !dinoKiraTexture.loadFromFile( resourcePath() + "dinoAssets/Kira/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoKiraSprite(dinoKiraTexture,sf::IntRect(0,0,24,24)); + dinoKiraSprite.setPosition(50, 230); + dinoKiraSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Sprite backgroundKiraSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + sf::Text kiraTextName("Kira ", font); + kiraTextName.setCharacterSize(70); + kiraTextName.setFillColor(sf::Color(0,197,208,230)); + kiraTextName.setStyle(sf::Text::Bold); + kiraTextName.setPosition(85, 150); + backgroundKiraSpriteForDinos.setPosition(70, 230); + backgroundKiraSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + sf::Text kiraCharacteristicsText ("STRENGTH - " + std::to_string(Kira().STRENGTH) + "\nDEXTERITY - " + std::to_string(Kira().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Kira().INTELLIGENCE),font); + kiraCharacteristicsText.setCharacterSize(25); + kiraCharacteristicsText.setFillColor(sf::Color::White); + kiraCharacteristicsText.setPosition(75, 400); + + //COLE SPRITE + sf::Texture dinoColeTexture; + if ( !dinoColeTexture.loadFromFile( resourcePath() + "dinoAssets/Cole/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoColeSprite(dinoColeTexture,sf::IntRect(0,0,24,24)); + dinoColeSprite.setPosition(305, 230); + dinoColeSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Text coleTextName("Cole ", font); + coleTextName.setCharacterSize(70); + coleTextName.setFillColor(sf::Color(0,197,208,230)); + coleTextName.setStyle(sf::Text::Bold); + coleTextName.setPosition(340, 150); + sf::Sprite backgroundColeSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + backgroundColeSpriteForDinos.setPosition(325, 230); + backgroundColeSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + sf::Text coleCharacteristicsText ("STRENGTH - " + std::to_string(Cole().STRENGTH) + "\nDEXTERITY - " + std::to_string(Cole().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Cole().INTELLIGENCE),font); + coleCharacteristicsText.setCharacterSize(25); + coleCharacteristicsText.setFillColor(sf::Color::White); + coleCharacteristicsText.setPosition(330, 400); + + //sprite MONO + sf::Texture dinoMonoTexture; + if ( !dinoMonoTexture.loadFromFile( resourcePath() + "dinoAssets/Mono/idle.png" ) ) + std::cout << "Can't find the image" << std::endl; + sf::Sprite dinoMonoSprite(dinoMonoTexture,sf::IntRect(0,0,24,24)); + dinoMonoSprite.setPosition(550, 230); + dinoMonoSprite.setScale(sf::Vector2f(7.0f,7.0f)); + sf::Sprite backgroundMonoSpriteForDinos(backgroundTextureForDinos,sf::IntRect(0,0,24,24)); + sf::Text monoTextName("Mono ", font); + monoTextName.setCharacterSize(70); + monoTextName.setFillColor(sf::Color(0,197,208,230)); + monoTextName.setStyle(sf::Text::Bold); + monoTextName.setPosition(585, 150); + backgroundMonoSpriteForDinos.setPosition(570, 230); + backgroundMonoSpriteForDinos.setScale(sf::Vector2f(6.0f,7.0f)); + sf::Text monoCharacteristicsText ("STRENGTH - " + std::to_string(Mono().STRENGTH) + "\nDEXTERITY - " + std::to_string(Mono().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Mono().INTELLIGENCE),font); + monoCharacteristicsText.setCharacterSize(25); + monoCharacteristicsText.setFillColor(sf::Color::White); + monoCharacteristicsText.setPosition(575, 400); + + + //counter text + int dinoCounter = 0; + sf::Text counterText (std::to_string(dinoCounter) + "/3",font); + counterText.setFillColor(sf::Color(0,197,208,230)); + counterText.setCharacterSize(30); + counterText.setStyle( sf::Text::Bold ); + counterText.setPosition(730, 550); + + while (battleWindow.isOpen()) { + + + sf::Event event; + battleWindow.clear(); + battleWindow.draw(spriteBackground); + battleWindow.draw(backgroundKiraSpriteForDinos); + battleWindow.draw(backgroundColeSpriteForDinos); + battleWindow.draw(backgroundMonoSpriteForDinos); + battleWindow.draw(kiraTextName); + battleWindow.draw(kiraCharacteristicsText); + battleWindow.draw(coleTextName); + battleWindow.draw(coleCharacteristicsText); + battleWindow.draw(monoTextName); + battleWindow.draw(monoCharacteristicsText); + battleWindow.draw(backButtonImage); + battleWindow.draw(buttonKiraPickText); + battleWindow.draw(buttonColePickText); + battleWindow.draw(buttonMonoPickText); + + + battleWindow.draw(counterText); + + + std::string outInventory; + selectInventory(outInventory); + std::string outputStr; + + std::stringstream ss(outInventory); + + + while (std::getline(ss, outputStr, ' ')) { + + vector.push_back(outputStr); + } + + for (int i = 0; i < vector.size(); i++) { + if (vector[i] == "Kira") { + battleWindow.draw(dinoKiraSprite); + } + + if (vector[i] == "Cole") { + battleWindow.draw(dinoColeSprite); + } + + if (vector[i] == "Mono") { + battleWindow.draw(dinoMonoSprite); + } + + } + if (dinoCounter == 3) { + battleWindow.draw(startButtonImage); + } + battleWindow.draw(titleBattle); + battleWindow.display(); + sf::Event Event; + + while (battleWindow.pollEvent(Event)) { + + switch (Event.type) { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( battleWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + backButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + backButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + + //if for battle button + if (startButtonImage.getGlobalBounds().contains(mousePosF)) + { + startButtonImage.setColor(sf::Color( 250, 20, 20 )); + } + else + { + startButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + + //if for KIRA button + if ( buttonKiraPickText.getGlobalBounds().contains( mousePosF ) && buttonKiraPickText.getString() == "PICK") + { + buttonKiraPickText.setFillColor( sf::Color( 250, 20, 20 ) ); + } + else if (buttonKiraPickText.getString() == "Picked") + { + buttonKiraPickText.setFillColor( sf::Color::Red); + } + else + { + buttonKiraPickText.setFillColor( sf::Color::Black ); + } + + //if for COLE button + if ( buttonColePickText.getGlobalBounds().contains( mousePosF ) && buttonColePickText.getString() == "PICK") + { + buttonColePickText.setFillColor( sf::Color( 250, 20, 20 ) ); + } + else if (buttonColePickText.getString() == "Picked") + { + buttonColePickText.setFillColor( sf::Color::Red); + } + else + { + buttonColePickText.setFillColor( sf::Color::Black ); + } + //if for MONO button + if ( buttonMonoPickText.getGlobalBounds().contains( mousePosF ) && buttonMonoPickText.getString() == "PICK") + { + buttonMonoPickText.setFillColor( sf::Color( 250, 20, 20 ) ); + } + else if (buttonMonoPickText.getString() == "Picked") + { + buttonMonoPickText.setFillColor( sf::Color::Red); + } + else + { + buttonMonoPickText.setFillColor( sf::Color::Black ); + } + } + break; + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( battleWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( backButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + battleWindow.close(); + menuWindowPrint(); + } + //if for pick kira + if (buttonKiraPickText.getGlobalBounds().contains(mousePosF) && buttonKiraPickText.getString() == "PICK") { + dinoCounter++; + counterText.setString(std::to_string(dinoCounter) + "/3"); + buttonKiraPickText.setFillColor(sf::Color::Red); + buttonKiraPickText.setString("Picked"); + battleWindow.draw(counterText); + battleWindow.display(); + vectorDinosReady.push_back(Kira().name); + } + //if for pick cole + if (buttonColePickText.getGlobalBounds().contains(mousePosF) && buttonColePickText.getString() == "PICK") { + dinoCounter++; + counterText.setString(std::to_string(dinoCounter) + "/3"); + buttonColePickText.setFillColor(sf::Color::Red); + buttonColePickText.setString("Picked"); + battleWindow.draw(counterText); + battleWindow.display(); + vectorDinosReady.push_back(Cole().name); + } + //if for pick mono + if (buttonMonoPickText.getGlobalBounds().contains(mousePosF) && buttonMonoPickText.getString() == "PICK") { + dinoCounter++; + counterText.setString(std::to_string(dinoCounter) + "/3"); + buttonMonoPickText.setFillColor(sf::Color::Red); + buttonMonoPickText.setString("Picked"); + battleWindow.draw(counterText); + battleWindow.display(); + vectorDinosReady.push_back(Mono().name); + } + + //entering battle + if (startButtonImage.getGlobalBounds().contains(mousePosF)) { +start: + battleWindow.close(); + sf::RenderWindow showBattleWindow (sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + //hp icon + sf::Texture hpIcon; + sf::Sprite hpIconSprite; + if ( !hpIcon.loadFromFile( resourcePath() + "greenbar.png" ) ) + std::cout << "Can't find the image" << std::endl; + hpIconSprite.setPosition( 100, 250 ); + hpIconSprite.setTexture( hpIcon ); + + + + //hp icon + sf::Texture hpIconEnemy; + sf::Sprite hpIconSpriteEnemy; + if ( !hpIconEnemy.loadFromFile( resourcePath() + "greenbar.png" ) ) + std::cout << "Can't find the image" << std::endl; + hpIconSpriteEnemy.setPosition( 570, 250 ); + hpIconSpriteEnemy.setTexture( hpIconEnemy ); + + + //mapping for string vector + std::map hash; + hash["Kira"] = 0; + hash["Cole"] = 1; + hash["Mono"] = 2; + + //kira characteristics + sf::Text kiraCharacteristicsText ("STRENGTH - " + std::to_string(Kira().STRENGTH) + "\nDEXTERITY - " + std::to_string(Kira().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Kira().INTELLIGENCE),font); + kiraCharacteristicsText.setCharacterSize(25); + kiraCharacteristicsText.setFillColor(sf::Color::White); + + //cole characteristics + sf::Text coleCharacteristicsText ("STRENGTH - " + std::to_string(Cole().STRENGTH) + "\nDEXTERITY - " + std::to_string(Cole().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Cole().INTELLIGENCE),font); + coleCharacteristicsText.setCharacterSize(25); + coleCharacteristicsText.setFillColor(sf::Color::White); + + //mono characteristics + sf::Text monoCharacteristicsText ("STRENGTH - " + std::to_string(Mono().STRENGTH) + "\nDEXTERITY - " + std::to_string(Mono().DEXTERITY) + "\nINTELLIGENCE - " + std::to_string(Mono().INTELLIGENCE),font); + monoCharacteristicsText.setCharacterSize(25); + monoCharacteristicsText.setFillColor(sf::Color::White); + + //background + sf::Texture textureBackgroundPlain; + if (!textureBackgroundPlain.loadFromFile(resourcePath() + "plainBackground.jpg")) { + return EXIT_FAILURE; + } + sf::Texture textureBackgroundMountain; + if (!textureBackgroundMountain.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Texture textureBackgroundRiver; + if (!textureBackgroundRiver.loadFromFile(resourcePath() + "riverBackground.jpg")) { + return EXIT_FAILURE; + } + // Seed the random number generator with the current time + std::srand(std::time(0)); + // Generate a random day using rand() and the enum range + Terrain randomTerrain = static_cast(std::rand() % 3); + sf::Sprite spriteBackground; + // Switch statement to print the corresponding day + switch (randomTerrain) { + case Plain: + spriteBackground.setTexture(textureBackgroundPlain); + break; + case River: + spriteBackground.setTexture(textureBackgroundRiver); + break; + case Mountain: + spriteBackground.setTexture(textureBackgroundMountain); + break; + } + //myDino sprite +DeathMyDino: std::string myDinoOutput = vectorDinosReady[rand()%vectorDinosReady.size()]; + sf::Vector2i spriteSize(24,24); + sf::Sprite myDino; + myDino.setScale(6, 6); + myDino.setPosition(100,300); + int frameNum = 3; + float animationDuration = 0.5; + + + //enemyDino Sprite +DeathEnemyDino: idleAnimation(myDino, myDinoOutput); + std::string enemyDinoOutput = vectorDinosReady[rand()%vectorDinosReady.size()]; + sf::Sprite enemyDino; + idleAnimation(enemyDino, enemyDinoOutput); + enemyDino.setScale(-6, 6); + enemyDino.setPosition(715,300); + + //hp green line + sf::Texture greenLine; + sf::Sprite greenLineSprite; + if ( !greenLine.loadFromFile( resourcePath() + "greenbarUpper.png" ) ) + std::cout << "Can't find the image" << std::endl; + greenLineSprite.setPosition( 100, 265 ); + greenLineSprite.setTexture( greenLine ); + + sf::Time elapsedTime; + sf::Clock clock; + //hp green line + sf::Texture greenLineEnemy; + sf::Sprite greenLineSpriteEnemy; + if ( !greenLineEnemy.loadFromFile( resourcePath() + "greenbarUpper.png" ) ) + std::cout << "Can't find the image" << std::endl; + greenLineSpriteEnemy.setPosition( 570, 265 ); + greenLineSpriteEnemy.setTexture( greenLineEnemy ); + + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + //title + sf::Text battleTitle("Press enter to smash!",font); + battleTitle.setFillColor(sf::Color::Red); + battleTitle.setPosition(180, 60); + battleTitle.setCharacterSize(70); + + //battle algorithm + Kira kira = Kira(); + Kira kiraEnemy = Kira(); + Cole cole = Cole(); + Cole coleEnemy = Cole(); + Mono mono = Mono(); + Mono monoEnemy = Mono(); + bool needToDrawEnemy = true; + if ( killCounter == 3) { + showBattleWindow.close(); + winnerWindowPrint(); + } + if (vectorDinosReady.size() == 0) { +loose: showBattleWindow.close(); + looserWindowPrint(); + } + + while (showBattleWindow.isOpen()) { +begin: + sf::Event Event; + showBattleWindow.clear(); + showBattleWindow.draw(spriteBackground); + sf::Time deltaTime = clock.restart(); + elapsedTime += deltaTime; + float timeAsSecond = elapsedTime.asSeconds(); + + int animFrame = static_cast((timeAsSecond/animationDuration)* static_cast(frameNum))% frameNum; + + myDino.setTextureRect(sf::IntRect(animFrame*spriteSize.x,0,spriteSize.x,spriteSize.y)); + enemyDino.setTextureRect(sf::IntRect(animFrame*spriteSize.x,0,spriteSize.x,spriteSize.y)); + showBattleWindow.draw(myDino); + if (animFrame == frameNum - 1 && timeAsSecond >= 1.25f) { + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/" + myDinoOutput + "/idle.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/" + enemyDinoOutput + "/idle.png")); + } + showBattleWindow.draw(hpIconSprite); + showBattleWindow.draw(greenLineSprite); + showBattleWindow.draw(hpIconSpriteEnemy); + if (needToDrawEnemy == true) { + showBattleWindow.draw(greenLineSpriteEnemy); + showBattleWindow.draw(enemyDino); + } + showBattleWindow.draw(battleTitle); + std::string myDinoPicked; + switch (hash[myDinoOutput]) { + case 0: + showBattleWindow.draw(kiraCharacteristicsText); + myDinoPicked = "Kira"; + kiraCharacteristicsText.setPosition(100, 450); + break; + case 1: + showBattleWindow.draw(coleCharacteristicsText); + myDinoPicked = "Cole"; + coleCharacteristicsText.setPosition(100, 450); + break; + case 2: + showBattleWindow.draw(monoCharacteristicsText); + myDinoPicked = "Mono"; + monoCharacteristicsText.setPosition(100, 450); + break; + } + showBattleWindow.display(); + while (showBattleWindow.pollEvent(Event)) { + switch (Event.type) { + case sf::Event::KeyPressed: + switch (hash[enemyDinoOutput]) { + case 0: + if (greenLineSpriteEnemy.getScale().x > 0.28 && greenLineSprite.getScale().x > 0.25) + { + if (myDinoPicked == "Kira") { + kiraEnemy.HP = kiraEnemy.HP - kira.damage(randomTerrain); + kira.HP = kira.HP - kiraEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(kiraEnemy.HP/100, 1); + greenLineSprite.setScale(kira.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Cole") { + kiraEnemy.HP = kiraEnemy.HP - cole.damage(randomTerrain); + cole.HP = cole.HP - kiraEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(kiraEnemy.HP/100, 1); + greenLineSprite.setScale(cole.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Mono") { + kiraEnemy.HP = kiraEnemy.HP - mono.damage(randomTerrain); + mono.HP = mono.HP - kiraEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(kiraEnemy.HP/100, 1); + greenLineSprite.setScale(mono.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + } + else + { + ++killCounter; + needToDrawEnemyGrave = true; + goto DeathEnemyDino; + } + if (greenLineSprite.getScale().x == greenLineSpriteEnemy.getScale().x && greenLineSprite.getScale().x < 0.25) { + ++killCounter; + needToDrawMyGrave = true; + needToDrawEnemyGrave = true; + if (vectorDinosReady.size()!=0) { + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + if (vectorDinosReady.size() == 0) { + goto loose; + } + goto start; + } + + if(greenLineSprite.getScale().x < 0.25) + { + if (vectorDinosReady.size()!=0) { + needToDrawMyGrave = true; + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + goto DeathMyDino; + } + + break; + case 1: + if (greenLineSpriteEnemy.getScale().x > 0.28 && greenLineSprite.getScale().x > 0.25) + { + if (myDinoPicked == "Kira") { + coleEnemy.HP = coleEnemy.HP - kira.damage(randomTerrain); + kira.HP = kira.HP - coleEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(coleEnemy.HP/100, 1); + greenLineSprite.setScale(kira.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Cole") { + coleEnemy.HP = coleEnemy.HP - cole.damage(randomTerrain); + cole.HP = cole.HP - coleEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(coleEnemy.HP/100, 1); + greenLineSprite.setScale(cole.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Mono") { + coleEnemy.HP = coleEnemy.HP - mono.damage(randomTerrain); + mono.HP = mono.HP - coleEnemy.damage(randomTerrain); + greenLineSpriteEnemy.setScale(coleEnemy.HP/100, 1); + greenLineSprite.setScale(mono.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + } + else + { + ++killCounter; + needToDrawEnemy = false; + needToDrawEnemyGrave = true; + goto DeathEnemyDino; + } + if (greenLineSprite.getScale().x == greenLineSpriteEnemy.getScale().x && greenLineSprite.getScale().x < 0.25) { + ++killCounter; + needToDrawMyGrave = true; + needToDrawEnemyGrave = true; + if (vectorDinosReady.size()!=0) { + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + if (vectorDinosReady.size() == 0) { + goto loose; + } + goto start; + } + if(greenLineSprite.getScale().x < 0.25) + { + if (vectorDinosReady.size()!=0) { + needToDrawMyGrave = true; + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + goto DeathMyDino; + } + + + break; + case 2: + if (greenLineSpriteEnemy.getScale().x > 0.28 && greenLineSprite.getScale().x > 0.25) + { + if (myDinoPicked == "Kira") { + monoEnemy.HP = monoEnemy.HP - kira.damage(randomTerrain); + greenLineSpriteEnemy.setScale(monoEnemy.HP/100, 1); + kira.HP = kira.HP - monoEnemy.damage(randomTerrain); + greenLineSprite.setScale(kira.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Cole") { + monoEnemy.HP = monoEnemy.HP - cole.damage(randomTerrain); + greenLineSpriteEnemy.setScale(monoEnemy.HP/100, 1); + cole.HP = cole.HP - monoEnemy.damage(randomTerrain); + greenLineSprite.setScale(cole.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + if (myDinoPicked == "Mono") { + monoEnemy.HP = monoEnemy.HP - mono.damage(randomTerrain); + greenLineSpriteEnemy.setScale(monoEnemy.HP/100, 1); + mono.HP = mono.HP - monoEnemy.damage(randomTerrain); + greenLineSprite.setScale(mono.HP/100, 1); + myDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ myDinoOutput +"/hurt.png")); + enemyDino.setTexture(AssetManager::GetTexture(resourcePath() + "dinoAssets/"+ enemyDinoOutput +"/hurt.png")); + } + } + else + { + ++killCounter; + needToDrawEnemy = false; + needToDrawEnemyGrave = true; + goto DeathEnemyDino; + } + if (greenLineSprite.getScale().x == greenLineSpriteEnemy.getScale().x && greenLineSprite.getScale().x < 0.25) { + ++killCounter; + needToDrawMyGrave = true; + needToDrawEnemyGrave = true; + if (vectorDinosReady.size()!=0) { + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + if (vectorDinosReady.size() == 0) { + goto loose; + } + goto start; + } + if(greenLineSprite.getScale().x < 0.25) + { + if (vectorDinosReady.size()!=0) { + needToDrawMyGrave = true; + vectorDinosReady.erase( std::remove(vectorDinosReady.begin(), vectorDinosReady.end(), myDinoPicked), vectorDinosReady.end() ); + } + goto DeathMyDino; + } + + break; + } + break; + } + } + } + } + } + break; + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/Textbox.cpp b/sem2/DogadinNM/DinoGame/Textbox.cpp new file mode 100644 index 00000000..d4502613 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/Textbox.cpp @@ -0,0 +1,74 @@ +// +// Textbox.cpp +// SFML Textbox +// +// Created by Thomas Redding on 9/12/15. +// Copyright © 2015 Thomas Redding. All rights reserved. +// + +#include "Textbox.hpp" + +/********** -------------- **********/ +/********** Public Methods **********/ +/********** -------------- **********/ + + +Textbox::Textbox(sf::RenderWindow &windowToUse, sf::Font &fontToUse) : window(windowToUse), font(fontToUse) { + text = sf::Text("", font); + background.setFillColor(sf::Color::White); + text.setColor(sf::Color::Red); +} + +void Textbox::draw() { + window.draw(background); + window.draw(text); +} + +void Textbox::setDimensons(double newX, double newY, double newWidth, double newHeight) { + x = newX; + y = newY; + width = newWidth; + height = newHeight; + text.setPosition(x, y-height/5); + text.setCharacterSize(height); + background.setPosition(x, y); + background.setSize(sf::Vector2f(width, height)); +} + +void Textbox::setString(std::string newString) { + string = newString; + text.setString(string); +} + +std::string Textbox:: getString() { + return string; +} + +bool Textbox::pollEvent(sf::Event event) { + if(isFocused) { + if(event.type == sf::Event::TextEntered) + return enterText(event.text.unicode); + } + return false; +} + +void Textbox::setFocus(bool newFocus) { + isFocused = newFocus; +} + +/********** --------------- **********/ +/********** Private Methods **********/ +/********** --------------- **********/ + +bool Textbox::enterText(sf::Uint32 unicode) { + if(unicode == 8) + string = string.substr(0, string.length()-1); // delete key + else if(unicode == 10) + return true; // return key + else + string += (char) unicode; + text.setString(string); + return false; +} + + diff --git a/sem2/DogadinNM/DinoGame/WinnerMenu.cpp b/sem2/DogadinNM/DinoGame/WinnerMenu.cpp new file mode 100644 index 00000000..9d95eb3c --- /dev/null +++ b/sem2/DogadinNM/DinoGame/WinnerMenu.cpp @@ -0,0 +1,127 @@ +// +// WinnerMenu.cpp +// DinoGame +// +// Created by Nikitoooooozy) on 17.05.2024. +// Copyright © 2024 Nikitoooooozy). All rights reserved. +// + +#include "includes.h" +#include "Graphics.h" +#include "DatabaseFunc.hpp" +void winnerWindowPrint(){ + // Create window + sf::RenderWindow winnerWindow(sf::VideoMode(800,600,60), "Dino Wars",sf::Style::Resize); + + // Set the Icon + sf::Image icon; + if (!icon.loadFromFile(resourcePath() + "icon.jpg")) { + return EXIT_FAILURE; + } + winnerWindow.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); + + // Load a sprite to display + sf::Texture texture; + if (!texture.loadFromFile(resourcePath() + "background.jpg")) { + return EXIT_FAILURE; + } + sf::Sprite sprite(texture); + + // Create a graphical text to display + //font + sf::Font font; + if (!font.loadFromFile(resourcePath() + "blackberry.otf")) { + return EXIT_FAILURE; + } + // + sf::Text text("Dino Wars", font); + text.setCharacterSize(165); + text.setFillColor(sf::Color(0,197,208,230)); + text.setStyle(sf::Text::Bold); + + //center text + sf::FloatRect textRect = text.getLocalBounds(); + text.setOrigin(textRect.width/2,textRect.height/2); + text.setPosition(sf::Vector2f(SCRWIDTH/2.0f,SCRHEIGHT/2.0f)); + + + //text buttons + sf::Text startText; + float startButtonWidth = startText.getLocalBounds().width; + float startButtonHeight = startText.getLocalBounds().height; + startText.setFont( font ); + startText.setStyle( sf::Text::Regular ); + startText.setString( "You are the winner!!!" ); + startText.setPosition(150, 400); + startText.setFillColor( sf::Color::Black ); + startText.setCharacterSize( 75 ); + + + //text of balance + sf::Text balanceText; + balanceText.setFont(font); + balanceText.setCharacterSize(50); + balanceText.setFillColor(sf::Color::Black); + balanceText.setStyle(sf::Text::Bold); + balanceText.setPosition(10, 300); + balanceText.setString("You've collected 25 coins to your balance"); + + //image buttons + sf::Texture exitButton; + sf::Sprite exitButtonImage; + if ( !exitButton.loadFromFile( resourcePath() + "exitButton.png" ) ) + std::cout << "Can't find the image" << std::endl; + float exitButtonWidth = exitButtonImage.getLocalBounds().width; + float exitButtonHeight = exitButtonImage.getLocalBounds().height; + exitButtonImage.setPosition( exitButtonWidth, exitButtonHeight ); + + exitButtonImage.setTexture( exitButton ); + + while (winnerWindow.isOpen()) { + winnerWindow.clear(); + + winnerWindow.draw(sprite); + winnerWindow.draw(startText); + winnerWindow.draw(exitButtonImage); + winnerWindow.draw(text); + winnerWindow.draw(balanceText); + winnerWindow.display(); + + sf::Event Event; + + while (winnerWindow.pollEvent(Event)) { + switch (Event.type) { + case sf::Event::MouseMoved: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( winnerWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if for exit button + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + exitButtonImage.setColor( sf::Color( 250, 20, 20 ) ); + } + else + { + exitButtonImage.setColor( sf::Color( 255, 255, 255 ) ); + } + } + break; + case sf::Event::MouseButtonPressed: + { + sf::Vector2i mousePos = sf::Mouse::getPosition( winnerWindow ); + sf::Vector2f mousePosF( static_cast( mousePos.x ), static_cast( mousePos.y ) ); + + //if exit button pressed + if ( exitButtonImage.getGlobalBounds().contains( mousePosF ) ) + { + winnerWindow.close(); + updateBalanceAfterWin(); + menuWindowPrint(); + } + } + break; + } + } + } +} diff --git a/sem2/DogadinNM/DinoGame/dinoAssets/Mono/dead.png b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/dead.png new file mode 100644 index 00000000..c4ddd78e Binary files /dev/null and b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/dead.png differ diff --git a/sem2/DogadinNM/DinoGame/dinoAssets/Mono/hurt.png b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/hurt.png new file mode 100644 index 00000000..a346c608 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/hurt.png differ diff --git a/sem2/DogadinNM/DinoGame/dinoAssets/Mono/idle.png b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/idle.png new file mode 100644 index 00000000..ea6de825 Binary files /dev/null and b/sem2/DogadinNM/DinoGame/dinoAssets/Mono/idle.png differ diff --git a/sem2/DogadinNM/DinoGame/dinoAssets/dinosBackground.jpg b/sem2/DogadinNM/DinoGame/dinoAssets/dinosBackground.jpg new file mode 100644 index 00000000..ed0dd63a Binary files /dev/null and b/sem2/DogadinNM/DinoGame/dinoAssets/dinosBackground.jpg differ diff --git a/sem2/DogadinNM/DinoGame/main.cpp b/sem2/DogadinNM/DinoGame/main.cpp new file mode 100644 index 00000000..902b3906 --- /dev/null +++ b/sem2/DogadinNM/DinoGame/main.cpp @@ -0,0 +1,24 @@ + +// +// Disclaimer: +// ---------- +// +// This code will work only if you selected window, graphics and audio. +// +// Note that the "Run Script" build phase will copy the required frameworks +// or dylibs to your application bundle so you can execute it on any OS X +// computer. +// +// Your resource files (images, sounds, fonts, ...) are also copied to your +// application bundle. To get the path to these resources, use the helper +// function `resourcePath()` from ResourcePath.hpp +// + + +#include "Graphics.h" + + +int main(int, char const**) +{ + startWindowPrint(); +}