-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.hpp
61 lines (44 loc) · 1.45 KB
/
Grid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef GRID_HPP
#define GRID_HPP
#include "rgb.hpp"
#include "Block.hpp"
#include "Vec2.hpp"
#include "Random.hpp"
#include <SFML/Graphics.hpp>
#include <vector>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
class Grid {
int blocksize;
public:
sf::RenderTexture framebuffer, background_framebuffer;
sf::Sprite background_sprite, foreground_sprite;
sf::Shader backgroundShader;
sf::Texture tileset;
int width, height;
Vec2 offset;
std::vector<Block> blocks;
std::vector<Block> background_blocks;
Grid(Vec2 screenSize, int width, int height, const char *tileset);
~Grid();
void setSize(size_t, size_t);
void moveCamera(float x, float y);
void setCamera(float x, float y);
bool load(const char *filename);
void save(const char *filename);
void generate();
Block& at(int idx, bool foreground = true);
Block& at(int x, int y, bool foreground = true);
void set(int x, int y, Block b, bool foreground = true);
int neighbors(int x, int y);
float raycast(Vec2 start, Vec2 dir, float len = 100.0, float infinity = -1.0);
void point_to_grid(int px, int py, int& x, int& y);
Block& atPoint(int px, int py, bool foreground = true);
Block& atPoint(Vec2 p, bool foreground = true);
void render();
void render(int xs, int ys, int width, int height);
void render(sf::RenderWindow &window);
void eachVisibleBlock(std::function<void (Block &, Block &, int, int)>, int xoff = 0, int yoff = 0, int xendoff = 0, int yendoff = 0);
};
#endif