A 2D tile-based sandbox game.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Chunk.h 875B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <SFML/Graphics/Texture.hpp>
  3. #include <string.h>
  4. #include "common.h"
  5. #include "Tile.h"
  6. #include "TileMap.h"
  7. namespace Swan {
  8. class Chunk {
  9. public:
  10. int x_;
  11. int y_;
  12. bool dirty_ = false;
  13. Tile::ID tiles_[CHUNK_WIDTH][CHUNK_HEIGHT];
  14. sf::Texture texture_;
  15. sf::Sprite sprite_;
  16. Chunk(int x, int y): x_(x), y_(y) {
  17. texture_.create(CHUNK_WIDTH * TILE_SIZE, CHUNK_HEIGHT * TILE_SIZE);
  18. sprite_ = sf::Sprite(texture_);
  19. }
  20. void setTile(TileMap &tmap, int x, int y, Tile::ID id) {
  21. tiles_[x][y] = id;
  22. drawBlock(tmap, x, y, id);
  23. }
  24. void drawBlock(int x, int y, Tile *t) {
  25. texture_.update(t->image_, x * TILE_SIZE, y * TILE_SIZE);
  26. dirty_ = true;
  27. }
  28. void drawBlock(TileMap &tmap, int x, int y, Tile::ID id) {
  29. drawBlock(x, y, tmap.get(id));
  30. }
  31. void redraw(TileMap &tmap);
  32. void fill(TileMap &tmap, Tile::ID id);
  33. void draw(Win &win);
  34. };
  35. }