game/level.hpp
2017-10-23 02:25:19 +02:00

48 lines
1.1 KiB
C++

#pragma once
#include <cmath>
#include <SFML/Graphics.hpp>
namespace Proto4 {
class Timer {
const sf::Time duration;
sf::Time elapsed = sf::seconds(0.f);
public:
Timer() : duration(sf::seconds(10)) {}
Timer(sf::Time duration) : duration(duration) {}
void update(sf::Time timestep) { elapsed += timestep; }
float getPercent() {
return std::max(0.f, 1 - elapsed / duration);
}
};
class Ground : public sf::CircleShape, Timer {
public:
Ground();
Ground(sf::Vector2f pos, float size, sf::Time fadeDuration);
void update(sf::Time timestep);
};
struct SpawnState {
sf::Vector2f position;
float size = 0;
sf::Vector2f direction;
};
class Level : public sf::Drawable, public sf::Transformable {
std::vector<Ground> groundArea;
SpawnState lastSpawn{};
public:
Level();
Level(sf::Vector2f pos);
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
void update(sf::Time timestep);
void spawn(float size);
};
}