-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobstacles.cpp
More file actions
56 lines (49 loc) · 2.15 KB
/
Copy pathobstacles.cpp
File metadata and controls
56 lines (49 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
** EPITECH PROJECT, 2024
** r-type
** File description:
** obstacles.cpp
*/
#include "obstacles.hpp"
#include "sets/drawable/systems/drawable_system.hpp"
ObstablesSystem::ObstablesSystem(mew::managers::ScenesManager::Ptr scenesManager,
const zygarde::utils::Timer::Nanoseconds& delta_time)
: delta_time{delta_time}, scenesManager_{std::move(scenesManager)} {
clock_.restart();
}
void ObstablesSystem::Run(Registry::Ptr r, ZippedComponents components) {
if (clock_.getElapsedTime() > sf::seconds(1)) {
clock_.restart();
CreateObstacle(r);
}
for (auto&& [tags, rigidbody, collider] : components) {
if (tags & "player") {
if (collider.HasCollision()) {
scenesManager_->Quit();
}
}
}
}
void ObstablesSystem::CreateObstacle(Registry::Ptr r) {
const auto player = r->SpawnEntity();
// Random number between 0 abd 800
const auto randomX = rand() % 800;
const core::types::Vector3f position{static_cast<float>(randomX), 0, 0};
auto aligns = Alignment{HorizontalAlign::kCenter, VerticalAlign::kCenter};
r->AddComponent<Position>(player, Position{position, aligns});
r->AddComponent<BoxCollider2D>(player,
physics::components::BoxCollider2D(core::types::Vector2f(50, 50)));
r->AddComponent<physics::components::Rigidbody2D>(
player, physics::components::Rigidbody2D{core::types::Vector2f(0, 1000)});
;
r->AddComponent<mew::sets::drawable::Drawable>(player,
{.drawable =
mew::sets::drawable::Rectangle{
.fillColor = sf::Color::Red,
.outlineColor = sf::Color::Black,
.outlineThickness = 0,
.size = {50, 50},
},
.view = mew::managers::WindowManager::GAME,
.layer = 10});
}