very early prototype of a spaceshooter in SFML
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

level.hpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <cmath>
  3. #include <SFML/Graphics.hpp>
  4. namespace Proto4 {
  5. class Timer {
  6. const sf::Time duration;
  7. sf::Time elapsed = sf::seconds(0.f);
  8. public:
  9. Timer() : duration(sf::seconds(10)) {}
  10. Timer(sf::Time duration) : duration(duration) {}
  11. void update(sf::Time timestep) { elapsed += timestep; }
  12. float getPercent() {
  13. return std::max(0.f, 1 - elapsed / duration);
  14. }
  15. };
  16. class Ground : public sf::CircleShape, Timer {
  17. public:
  18. Ground();
  19. Ground(sf::Vector2f pos, float size, sf::Time fadeDuration);
  20. void update(sf::Time timestep);
  21. };
  22. struct SpawnState {
  23. sf::Vector2f position;
  24. float size = 0;
  25. sf::Vector2f direction;
  26. };
  27. class Level : public sf::Drawable, public sf::Transformable {
  28. std::vector<Ground> groundArea;
  29. SpawnState lastSpawn{};
  30. public:
  31. Level();
  32. Level(sf::Vector2f pos);
  33. virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
  34. void update(sf::Time timestep);
  35. void spawn(float size);
  36. };
  37. }