mirror of
https://github.com/NoelFB/tiny_link.git
synced 2025-02-23 14:28:27 +08:00
54 lines
1.0 KiB
C++
54 lines
1.0 KiB
C++
#pragma once
|
|
#include <blah.h>
|
|
#include <memory>
|
|
#include "../world.h"
|
|
|
|
using namespace Blah;
|
|
|
|
namespace TL
|
|
{
|
|
class Collider : public Component
|
|
{
|
|
public:
|
|
enum class Shape
|
|
{
|
|
None,
|
|
Rect,
|
|
Grid
|
|
};
|
|
|
|
uint32_t mask;
|
|
|
|
Collider();
|
|
|
|
static Collider make_rect(const RectI& rect);
|
|
static Collider make_grid(int tile_size, int columns, int rows);
|
|
|
|
Shape shape() const;
|
|
RectI get_rect() const;
|
|
void set_rect(const RectI& value);
|
|
bool get_cell(int x, int y) const;
|
|
void set_cell(int x, int y, bool value);
|
|
|
|
bool check(uint32_t mask, Point offset = Point::zero) const;
|
|
bool overlaps(const Collider* other, Point offset = Point::zero) const;
|
|
|
|
void render(Batch& batch) override;
|
|
|
|
private:
|
|
struct Grid
|
|
{
|
|
int columns;
|
|
int rows;
|
|
int tile_size;
|
|
std::shared_ptr<bool[]> cells;
|
|
};
|
|
|
|
Shape m_shape = Shape::None;
|
|
RectI m_rect;
|
|
Grid m_grid;
|
|
|
|
static bool rect_to_rect(const Collider* a, const Collider* b, Point offset);
|
|
static bool rect_to_grid(const Collider* a, const Collider* b, Point offset);
|
|
};
|
|
} |