diff options
Diffstat (limited to 'src/main/cpp')
-rw-r--r-- | src/main/cpp/Actor.cpp | 27 | ||||
-rw-r--r-- | src/main/cpp/Main.cpp | 10 | ||||
-rw-r--r-- | src/main/cpp/Map.cpp | 28 | ||||
-rw-r--r-- | src/main/cpp/Subconscious.cpp | 60 | ||||
-rw-r--r-- | src/main/cpp/WorldScene.cpp | 28 |
5 files changed, 153 insertions, 0 deletions
diff --git a/src/main/cpp/Actor.cpp b/src/main/cpp/Actor.cpp new file mode 100644 index 0000000..219488d --- /dev/null +++ b/src/main/cpp/Actor.cpp @@ -0,0 +1,27 @@ +#include "Actor.hpp" + +Actor::Actor(std::string _name, unsigned _maxHp, Type _type) : + name(_name), maxHp(_maxHp), type(_type) +{} + +Actor::~Actor() +{} + +void Actor::damage(int amt) +{ + _hp -= amt; + + if (_hp < 0) { + _hp = 0; + _alive = false; + } +} + +void Actor::heal(int amt) +{ + _hp += amt; + + if (_hp > maxHp) { + _hp = maxHp; + } +} diff --git a/src/main/cpp/Main.cpp b/src/main/cpp/Main.cpp new file mode 100644 index 0000000..9d46e8d --- /dev/null +++ b/src/main/cpp/Main.cpp @@ -0,0 +1,10 @@ +#include "Subconscious.hpp" + +int main(int argc, char *argv[]) +{ + Subconscious game; + // game.run(); + game.demo(); + + return 0; +} diff --git a/src/main/cpp/Map.cpp b/src/main/cpp/Map.cpp new file mode 100644 index 0000000..6d3ee01 --- /dev/null +++ b/src/main/cpp/Map.cpp @@ -0,0 +1,28 @@ +#include "Map.hpp" + +// TODO remove hardcoded values +Map::Map() : width(50), height(50) +{ + for (unsigned i = 0; i < width; i++) { + for (unsigned j = 0; j < height; j++) { + // TODO remove hardcoded values (grass) + Tile tile(Tile::Type::GRASS, i, j); + _tiles.push_back(tile); + } + } +} + +Tile& Map::tile(unsigned x, unsigned y) +{ + return _tiles[y * width + x]; +} + +const std::vector<Tile>& Map::tiles() const +{ + return _tiles; +} + +bool Map::moveActor(Tile &from, Tile &to) +{ + // TODO +} diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp new file mode 100644 index 0000000..942b0b4 --- /dev/null +++ b/src/main/cpp/Subconscious.cpp @@ -0,0 +1,60 @@ +#include "Subconscious.hpp" +#include "WorldScene.hpp" + +#include <SFML/Graphics.hpp> + +/*** public methods ***/ + +Subconscious::Subconscious() + : _window(sf::VideoMode(800, 600), "Subconscious") +{ + _window.setVerticalSyncEnabled(true); + _window.setFramerateLimit(90); +} + +Subconscious::~Subconscious() +{} + +void Subconscious::run() +{ + _running = true; + while (_running && _window.isOpen()) { + gameUpdate(); + gameRender(); + } +} + +void Subconscious::demo() +{ + Scene *demoScene = new WorldScene(); + + _currentScene = demoScene; + _scenes.push_back(demoScene); + + run(); +} + + +/*** private methods ***/ + +void Subconscious::gameUpdate() +{ + sf::Event event; + + while (_window.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + _window.close(); + } + } +} + +void Subconscious::gameRender() +{ + _window.clear(); + + if (_currentScene != nullptr) { + _currentScene->render(_window); + } + + _window.display(); +} diff --git a/src/main/cpp/WorldScene.cpp b/src/main/cpp/WorldScene.cpp new file mode 100644 index 0000000..ab1c4d0 --- /dev/null +++ b/src/main/cpp/WorldScene.cpp @@ -0,0 +1,28 @@ +#include "WorldScene.hpp" + +WorldScene::WorldScene() +{ + _tileSize = DEFAULT_TILE_SIZE_PX; +} + +void WorldScene::render(sf::RenderWindow &window) +{ + sf::RectangleShape rect; + + rect.setSize(sf::Vector2f(_tileSize, _tileSize)); + rect.setFillColor(sf::Color::Green); + + rect.setOutlineThickness(-.5); + rect.setOutlineColor(sf::Color::Black); + + for (const Tile &tile : map.tiles()) { + rect.setPosition(tile.x * _tileSize, tile.y * _tileSize); + window.draw(rect); + } +} + +void WorldScene::zoom(int value) +{} + +void WorldScene::pan(int dx, int dy) +{} |