Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
LuridHound committed Nov 12, 2019
1 parent 529e7c7 commit 82c0dce
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
4 changes: 3 additions & 1 deletion source/BackgroundManager/BackgroundManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/RenderWindow.hpp>

#include "../Enums.h"


Expand All @@ -30,7 +31,8 @@ class BackgroundManager final
PICTURES_RIGHT = 4;

const int BLOCK_SIZE_Y = 270,
BLOCK_SIZE_X = 270;
BLOCK_SIZE_X = 270;

const std::string PATH_TO_BACKGROUND = "resources/Textures/Backgrounds/";
const std::string EXTENSION = ".jpg";

Expand Down
4 changes: 3 additions & 1 deletion source/GameEngine/GameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ void GameEngine::initializeWindow()
sf::Image icon;
icon.loadFromFile("resources/Textures/Runes/0.png");

window = new sf::RenderWindow(sf::VideoMode(1920, 1080), title, sf::Style::Fullscreen);
sf::VideoMode videoMode(sf::VideoMode().getDesktopMode());

window = new sf::RenderWindow(videoMode, title, sf::Style::Fullscreen);

window->setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());

Expand Down
12 changes: 7 additions & 5 deletions source/Geometry/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ Rune* Geometry::getRune(int x, int y)
Rune* rune = nullptr;
for ( int z = 0; z < MAX_DEPTH; ++z )
{
int x_ = field[((x - (54 / 12) * z)/ 27)][((y + (90 / 12) * z) / 45)][z].x;
int y_ = field[((x - (54 / 12) * z)/ 27)][((y + (90 / 12) * z) / 45)][z].y;
int x_ = field[((x - (Rune::getOffset().x) * z)/ (Rune::getTextureSize().x / 2) )][((y + (Rune::getOffset().y) * z) / (Rune::getTextureSize().y / 2))][z].x;
int y_ = field[((x - (Rune::getOffset().x) * z)/ (Rune::getTextureSize().x / 2)) ][((y + (Rune::getOffset().y) * z) / (Rune::getTextureSize().y / 2))][z].y;
if ( x_ == -1 || y_ == -1 )
continue;
if(x_ > MAX_WIDTH || y_ > MAX_HEIGHT)
Expand Down Expand Up @@ -227,17 +227,18 @@ void Geometry::loadLevel(const int LEVEL)
runes.push_back(new Rune(i));
runes[i]->setRuneType(rand() % 30);
runes[i]->setPosition(positions[i].x, positions[i].y, positions[i].z);
/*
runes[i]->x = positions[i].x;
runes[i]->y = positions[i].y;
runes[i]->z = positions[i].z;

*/
}
generateRunes();

std::sort(runes.begin(), runes.end(),
[](Rune* first, Rune* second)
{
if(first->z < second->z)
if(first->getPosition().z < second->getPosition().z)
return true;
return false;
}
Expand Down Expand Up @@ -272,7 +273,8 @@ void Geometry::deleteRunes(Rune* first, Rune* second)
{
if ( rune->getID() == first->getID() || rune->getID() == second->getID() )
{
clearCell(rune->x, rune->y, rune->z);
sf::Vector3i position = rune->getPosition();
clearCell(position.x, position.y, position.z);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion source/Geometry/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Geometry final
};
std::vector<Position> positions;
int id = 0;
//beware

struct Tile
{
int x = - 1, y = -1;
Expand Down
20 changes: 20 additions & 0 deletions source/Rune/Rune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void Rune::setPosition(const int X, const int Y, const int Z)
sprite.setPosition(textureSizeX * (X / 2) + (textureSizeX / 2) * (X % 2) + Z * offsetX,
textureSizeY * (Y / 2) + (textureSizeY / 2) * (Y % 2) - Z * offsetY);

x = X;
y = Y;
z = Z;

return;
}

Expand Down Expand Up @@ -96,4 +100,20 @@ void Rune::unhighlight()
}

return;
}


//
//
sf::Vector2i Rune::getOffset()
{
return sf::Vector2i(offsetX, offsetY);
}


//
//
sf::Vector2i Rune::getTextureSize()
{
return sf::Vector2i(textureSizeX, textureSizeY);
}
13 changes: 12 additions & 1 deletion source/Rune/Rune.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/System.hpp>


//
Expand All @@ -27,11 +28,19 @@ class Rune final

void setRuneType(const int TYPE);
void draw(sf::RenderWindow* window);
int x, y, z; // get rid

[[nodiscard]]
sf::Vector3i getPosition()
{
return sf::Vector3i(x, y, z);
};

void highlight();
void unhighlight();

static sf::Vector2i getOffset();
static sf::Vector2i getTextureSize();

private :

static int offsetX, offsetY;
Expand All @@ -41,6 +50,8 @@ class Rune final

bool ishHighlighted;

int x, y, z;

const int ID;

size_t type;
Expand Down

0 comments on commit 82c0dce

Please sign in to comment.