You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB
C++

#include "level.hpp"
#include "vec2util.hpp"
#include "random.hpp"
namespace Proto4 {
Ground::Ground() {}
Ground::Ground(sf::Vector2f pos, float size, sf::Time fadeDuration)
: sf::CircleShape(size, 50)
, Timer(fadeDuration) {
setFillColor(sf::Color(90, 100, 120));
setOrigin(size, size);
setPosition(pos);
}
// TODO: self destruct once 0?
void Ground::update(sf::Time timestep) {
Timer::update(timestep);
sf::Color col = getFillColor();
col.a = getPercent() * 255;
setFillColor(col);
}
/////////////////////////////////////////
Level::Level() {}
Level::Level(sf::Vector2f pos = sf::Vector2f(0, 0)) {
setPosition(pos);
// initialize with first ground
spawn(400);
Proto4::rotate(lastSpawn.direction, sf::Vector2f(1, 1), randomFloat() * 360.f);
}
void Level::update(sf::Time timestep) {
for (auto &ground : groundArea) {
ground.update(timestep);
}
}
void Level::draw(sf::RenderTarget &target, sf::RenderStates states) const {
states.transform *= getTransform();
for (auto &ground : groundArea) {
target.draw(ground, states);
}
}
void Level::spawn(float size) {
lastSpawn.direction = normalized(Proto4::rotate(lastSpawn.direction, randomFloat() * 160 - 80));
lastSpawn.position += lastSpawn.direction * (lastSpawn.size + 0.7f * size);
lastSpawn.size = size;
groundArea.push_back(Ground(lastSpawn.position, size, sf::seconds(10)));
}
}