add little parallax

This commit is contained in:
Askou
2021-06-17 18:00:34 +02:00
parent 2ff8230c35
commit da448c49c9
5 changed files with 17 additions and 2 deletions
+1
View File
@@ -54,6 +54,7 @@ namespace BBM
constexpr const char Blowable[] = "Blowable";
// interact with visual features like camera
constexpr const char Player[] = "Player";
constexpr const char Background[] = "Background";
constexpr const char Unbreakable[] = "Unbreakable";
constexpr const char Breakable[] = "Breakable";
constexpr const char Hole[] = "Hole";
+1 -1
View File
@@ -338,7 +338,7 @@ namespace BBM
if (rnd > 0.98)
return HOLE;
if (rnd > 0.25)
return BREAKABLE;
return NOTHING;
return NOTHING;
}
+7
View File
@@ -68,6 +68,13 @@ namespace BBM
return *this;
}
template<typename T2>
Vector2<T> operator-(const Vector2<T2> &vec) const
{
return Vector2<T>(this->x - vec.x, this->y - vec.y);
}
template<typename T2>
Vector2<T> &operator*=(T2 d)
{
+2 -1
View File
@@ -46,7 +46,8 @@ namespace BBM
.addComponent<Drawable2DComponent, RAY2D::Text>("", 60, RAY::Vector2(), ORANGE);
scene->addEntity("background image")
.addComponent<Drawable2DComponent, RAY::Texture>(true, "assets/background.png", false)
.addComponent<PositionComponent>();
.addComponent<PositionComponent>()
.addComponent<TagComponent<Background>>();
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, hasHeights), scene);
return scene;
}
+6
View File
@@ -74,6 +74,12 @@ namespace BBM
cam.target += (newCameraPos.abs() - pos.position.abs()) / 10;
newCameraPos.y = maxDist;
newCameraPos.z -= 1;
Vector3f pos2d(pos.position.abs().x,0, pos.position.abs().z);
Vector3f newPos2d(newCameraPos.abs().x, 0, pos.position.abs().z);
for (auto &[entity, backPos, _] : this->_wal.getScene()->view<PositionComponent, TagComponent<Background>>()) {
backPos.position -= (newPos2d - pos2d) / 10;
}
pos.position += (newCameraPos.abs() - pos.position.abs()) / 10;
}
}