commit f8f640ae892b291e6d4e9606fa53f341451b80c5 Author: NaiJi Date: Wed Feb 19 20:50:09 2020 +0300 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee2fffb --- /dev/null +++ b/.gitignore @@ -0,0 +1,72 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8287224 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# sfml-test + +Just playing around with [sfml](https://www.sfml-dev.org/), since I have nothing better to do anyway. \ No newline at end of file diff --git a/game.cpp b/game.cpp new file mode 100644 index 0000000..792ac98 --- /dev/null +++ b/game.cpp @@ -0,0 +1,28 @@ +#include "game.h" + +Game::Game() +{ + sf::Window window(sf::VideoMode(640, 480), "SFML-Test Application", sf::Style::Default); + window.setActive(); +} + +int Game::run() +{ + clock = std::make_unique(); + + // On the game loop + while (main_window.isOpen()) + { + sf::Event event; + while (main_window.pollEvent(event)) + { + if (event.type == sf::Event::Closed) + main_window.close(); + + if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) + main_window.close(); + } + } + + return EXIT_SUCCESS; +} diff --git a/game.h b/game.h new file mode 100644 index 0000000..39ea3bf --- /dev/null +++ b/game.h @@ -0,0 +1,22 @@ +#ifndef GAME_H +#define GAME_H + +#include + +#include +#include + +class Game +{ +private: + std::unique_ptr clock; + sf::Window main_window; + +public: + explicit Game(); + + // Start the game loop + int run(); +}; + +#endif // GAME_H diff --git a/hero.cpp b/hero.cpp new file mode 100644 index 0000000..e713c06 --- /dev/null +++ b/hero.cpp @@ -0,0 +1,25 @@ +#include "hero.h" + +Hero::Hero(int initial_charges) : + hero_charges(initial_charges) +{} + +void Hero::refillCharges(int append_charges) +{ + hero_charges += append_charges; +} + +int Hero::charges() const noexcept +{ + return hero_charges; +} + +bool Hero::useCharge() +{ + if (hero_charges > 0) { + --hero_charges; + return true; + } + + return false; +} diff --git a/hero.h b/hero.h new file mode 100644 index 0000000..dc462e5 --- /dev/null +++ b/hero.h @@ -0,0 +1,22 @@ +#ifndef HERO_H +#define HERO_H + +class Hero +{ +private: + int hero_charges; + +public: + explicit Hero(int initial_charges = 0); + + // Add more charges for hero to use + inline void refillCharges(int append_charges); + + // Get amount of charges + inline int charges() const noexcept; + + // Spend one charge on action + inline bool useCharge(); +}; + +#endif // HERO_H diff --git a/level.cpp b/level.cpp new file mode 100644 index 0000000..c3545be --- /dev/null +++ b/level.cpp @@ -0,0 +1,6 @@ +#include "level.h" + +Level::Level() +{ + +} diff --git a/level.h b/level.h new file mode 100644 index 0000000..e94475d --- /dev/null +++ b/level.h @@ -0,0 +1,19 @@ +#ifndef LEVEL_H +#define LEVEL_H + +#include + +constexpr int side = 32; + +using Map = std::array, side>; + +class Level +{ +private: + Map map; + +public: + Level(); +}; + +#endif // LEVEL_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..468fc00 --- /dev/null +++ b/main.cpp @@ -0,0 +1,8 @@ +#include +#include "game.h" + +int main() +{ + Game game; + return game.run(); +} diff --git a/sfml-test.pro b/sfml-test.pro new file mode 100644 index 0000000..571cfdd --- /dev/null +++ b/sfml-test.pro @@ -0,0 +1,18 @@ +TEMPLATE = app +CONFIG += c++17 +CONFIG -= console app_bundle +CONFIG -= qt + +SOURCES += \ + game.cpp \ + hero.cpp \ + level.cpp \ + main.cpp + +HEADERS += \ + game.h \ + hero.h \ + level.h + +# Only to highlight syntax when I am on Windows +win32:INCLUDEPATH += d:\SFML-2.5.1\include