{
window.draw(sprite);
window.draw(point_text);
+}
+
+bool Map::collides(Object& other)
+{
+ sf::FloatRect glb {sprite.getGlobalBounds()};
+ sf::FloatRect hb {other.get_hitbox()};
+ return !(glb.contains({hb.left, hb.top}) &&
+ glb.contains({hb.left + hb.width, hb.top + hb.height}));
}
\ No newline at end of file
#include <SFML/Graphics.hpp>
#include "json.hpp"
+#include "Object.h"
using json = nlohmann::json;
void update(int const collected, int const points, int const time_left);
void render(sf::RenderWindow& window) const;
+ bool collides(Object& other);
protected:
private:
sf::Texture texture;
move(false);
}
+void Player::collision(Map& map)
+{
+ move(false);
+}
+
void Player::collision(YF& yf)
{
move(false);
#include "json.hpp"
#include "YF.h"
#include "Bike_enemy.h"
+#include "Map.h"
using json = nlohmann::json;
~Player() = default;
void collision(Object& other) override;
+ void collision(Map& map);
void collision(YF& yf);
void collision(Bike_enemy& bike);
void update(Context& context) override;
context.next_state = std::make_unique<GameOver_menu>();
return;
}
-
+
for (unsigned int i {0}; i < bottles.size(); ++i)
{
enemy->collision(*bike);
}
}
-
+
time_since_last_bottle += context.time.asSeconds();
time_since_last_yf += context.time.asSeconds();
{
bike->update(context);
}
-
+ if(game_map->collides(*player))
+ {
+ player->collision(*game_map);
+ }
}
void Game_state::render(sf::RenderWindow &window) const