A 2D tile-based sandbox game.
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.

common.h 915B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <SFML/Graphics.hpp>
  3. #include <SFML/System/Vector2.hpp>
  4. #include "Vector2.h"
  5. namespace Swan {
  6. static constexpr int TILE_SIZE = 32;
  7. static constexpr int TICK_RATE = 20;
  8. static constexpr int CHUNK_HEIGHT = 32;
  9. static constexpr int CHUNK_WIDTH = 32;
  10. using TilePos = Vec2i;
  11. using ChunkPos = Vec2i;
  12. class Game;
  13. class World;
  14. class WorldPlane;
  15. struct Context {
  16. Game &game;
  17. World &world;
  18. WorldPlane &plane;
  19. };
  20. struct Win {
  21. sf::RenderWindow *window_;
  22. sf::Transform transform_;
  23. Vec2 cam_;
  24. double scale_ = 2;
  25. Win(sf::RenderWindow *win): window_(win) {}
  26. void setPos(const Vec2 &pos) {
  27. transform_ = sf::Transform()
  28. .scale(scale_, scale_)
  29. .translate((pos - cam_) * TILE_SIZE);
  30. }
  31. void draw(const sf::Drawable &drawable) {
  32. window_->draw(drawable, transform_);
  33. }
  34. Vec2 getSize() {
  35. sf::Vector2u v = window_->getSize();
  36. return Vec2(v.x, v.y) / (TILE_SIZE * scale_);
  37. }
  38. };
  39. }