3Obstacle::Obstacle(ObstacleType t,
float x) : type(t), pos{x, 0.0f} {
5 case ObstacleType::SmallBox:
8 colour = {1.0f, 0.5f, 0.0f, 1.0f};
12 case ObstacleType::TallBox:
15 colour = {1.0f, 0.2f, 0.2f, 1.0f};
19 case ObstacleType::FlyingBox:
22 colour = {0.5f, 0.2f, 1.0f, 1.0f};
29 emitter.colour = colour;
30 emitter.spawnRate = 40.0f;
32 emitter.props.position = pos;
33 emitter.props.velocity = {3.0f, 0.0f};
34 emitter.props.lifeTime = 0.8f;
35 emitter.props.sizeBegin = 0.3f;
36 emitter.props.sizeEnd = 0.0f;
37 emitter.props.colourBegin = colour;
38 emitter.props.colourEnd = glm::vec4(colour.r, colour.g, colour.b, 0.0f);
46 pos.x -= speed * dt.seconds();
49 emitter.props.position = pos;
56void Obstacle::reset(
float x) {
61 case ObstacleType::SmallBox:
64 case ObstacleType::TallBox:
67 case ObstacleType::FlyingBox:
73 emitter.props.position = pos;
76bool Obstacle::collidesWith(
const glm::vec2 &otherPos,
const glm::vec2 &otherSize)
const {
82 float left1 = pos.x - (size.x * 0.5f);
83 float right1 = pos.x + (size.x * 0.5f);
84 float bottom1 = pos.y - (size.y * 0.5f);
85 float top1 = pos.y + (size.y * 0.5f);
87 float left2 = otherPos.x - (otherSize.x * 0.5f);
88 float right2 = otherPos.x + (otherSize.x * 0.5f);
89 float bottom2 = otherPos.y - (otherSize.y * 0.5f);
90 float top2 = otherPos.y + (otherSize.y * 0.5f);
92 return !(left1 > right2 || right1 < left2 || bottom1 > top2 || top1 < bottom2);