Skip to content

Commit

Permalink
Obstacles are now rendering...
Browse files Browse the repository at this point in the history
  • Loading branch information
Qazaroth committed Mar 12, 2022
1 parent 14e5349 commit 83647e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
24 changes: 22 additions & 2 deletions src/Level/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void Level::setup()

_objects.insert(std::pair<int, std::list<int>>(posT, values));

Objects::Block block(_windowSize.x - 100, posY, _windowSize);
//std::cout << "[" << key << "] " << val << std::endl;
}

Expand Down Expand Up @@ -97,6 +96,8 @@ void Level::update(sf::RenderWindow &window, bool isPaused)
{
window.draw(_background);

_windowSize = window.getSize();

if (!isPaused)
{
_lvlTimer++;
Expand All @@ -109,6 +110,18 @@ void Level::update(sf::RenderWindow &window, bool isPaused)
//_bgMusic.play();
}

if (_renderBlocks.size() > 0)
{
for (int i = 0; i < _renderBlocks.size(); i++)
{
std::list<Objects::Block>::iterator e = _renderBlocks.begin();
std::advance(e, i);

window.draw((*e).getObject());
}
}


if (_objects.count(_lvlTimer))
{
auto obj = _objects.find(_lvlTimer);
Expand All @@ -117,7 +130,14 @@ void Level::update(sf::RenderWindow &window, bool isPaused)
int posT = getDataOfObject(obj->second, 1);
int posY = getDataOfObject(obj->second, 2);

std::cout << type << " | " << posT << ", " << posY << std::endl;
if (type == 1)
{
Objects::Block block(_windowSize.x - 100, posY, _windowSize);
_renderBlocks.push_back(block);
window.draw(block.getObject());
}

//std::cout << type << " | " << posT << ", " << posY << std::endl;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Level/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Level

sf::Vector2u _windowSize;
std::map<int, std::list<int>> _objects;
std::list<Objects::Block> _renderBlocks;

bool _IsInit = false;

Expand Down
6 changes: 1 addition & 5 deletions src/Level/objects/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Objects
{
class Block : public sf::Drawable
class Block
{
private:
float _x, _y;
Expand All @@ -16,10 +16,6 @@ namespace Objects
sf::Vector2u _windSize;

void setup();
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(_block, states);
}
public:
Block(float x, float y, sf::Vector2u windowSize);
~Block();
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ int main()
window.draw(fpsTxt);
plr.update(window, frames, isPaused);
window.display();
frames++;

frames++;
if (time.elapsed() - timer > 1.0f)
{
timer += 1.0f;
Expand Down

0 comments on commit 83647e6

Please sign in to comment.