43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
class GameRect {
|
|
private:
|
|
int16_t x;
|
|
int16_t y;
|
|
int16_t w;
|
|
int16_t h;
|
|
|
|
public:
|
|
GameRect(int16_t x = 0, int16_t y = 0, int16_t w = 0, int16_t h = 0)
|
|
: x(x), y(y), w(w), h(h) {}
|
|
|
|
// Getter
|
|
int16_t getX() const { return x; }
|
|
int16_t getY() const { return y; }
|
|
int16_t getWidth() const { return w; }
|
|
int16_t getHeight() const { return h; }
|
|
|
|
// Setter
|
|
void setX(int16_t nx) { x = nx; }
|
|
void setY(int16_t ny) { y = ny; }
|
|
void setWidth(int16_t nw) { w = nw; }
|
|
void setHeight(int16_t nh) { h = nh; }
|
|
void set(int16_t nx, int16_t ny, int16_t nw, int16_t nh) {
|
|
x = nx; y = ny; w = nw; h = nh;
|
|
}
|
|
|
|
// Kollisionserkennung (wie pygame.Rect.colliderect)
|
|
bool collideRect(const GameRect& other) const {
|
|
return !(x + w <= other.x || // links von other
|
|
x >= other.x + other.w || // rechts von other
|
|
y + h <= other.y || // über other
|
|
y >= other.y + other.h); // unter other
|
|
}
|
|
|
|
// Punkt-in-Rechteck Test
|
|
bool contains(int16_t px, int16_t py) const {
|
|
return (px >= x && px < x + w && py >= y && py < y + h);
|
|
}
|
|
}; |