mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-07-10 05:32:01 +00:00
Sprite shifting support
This commit is contained in:
@ -36,7 +36,9 @@ int Sprite::GetWidth() {
|
||||
void Sprite::Draw(DaisyPatch patch, int x, int y) {
|
||||
for (int w = 0; w < width; w++) {
|
||||
for (int h = 0; h < height; h++) {
|
||||
patch.display.DrawPixel(x+w, y+h, sprite[w][h]);
|
||||
patch.display.DrawPixel(x+w, y+h,
|
||||
sprite[GetShiftArrayX(w)]
|
||||
[GetShiftArrayY(h)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,8 +54,8 @@ void Sprite::DrawTile(DaisyPatch patch,
|
||||
int y_max = std::max(y1, y2);
|
||||
for (int w = x_min; w < x_max; w++) {
|
||||
for (int h = y_min; h < y_max; h++) {
|
||||
patch.display.DrawPixel(w, h, sprite[(w-x_min) % width]
|
||||
[(h-y_min) % height]);
|
||||
patch.display.DrawPixel(w, h, sprite[GetShiftArrayX((w-x_min) % width)]
|
||||
[GetShiftArrayY((h-y_min+y_shift) % height)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,3 +71,31 @@ void Sprite::SetBlank() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::SetXShift(int x) {
|
||||
x_shift = x;
|
||||
}
|
||||
|
||||
void Sprite::SetYShift(int y) {
|
||||
y_shift = y;
|
||||
}
|
||||
|
||||
void Sprite::AdjustXShift(int x) {
|
||||
x_shift -= x;
|
||||
}
|
||||
|
||||
void Sprite::AdjustYShift(int y) {
|
||||
y_shift += y;
|
||||
}
|
||||
|
||||
int Sprite::GetShiftArray(int pos, int shift, int array_size) {
|
||||
return (array_size + ((pos + shift) % array_size)) % array_size;
|
||||
}
|
||||
|
||||
int Sprite::GetShiftArrayX(int pos) {
|
||||
return GetShiftArray(pos, x_shift, width);
|
||||
}
|
||||
|
||||
int Sprite::GetShiftArrayY(int pos) {
|
||||
return GetShiftArray(pos, y_shift, height);
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ class Sprite {
|
||||
private:
|
||||
int width, height;
|
||||
bool** sprite;
|
||||
int x_shift = 0;
|
||||
int y_shift = 0;
|
||||
int GetShiftArray(int, int, int);
|
||||
int GetShiftArrayX(int);
|
||||
int GetShiftArrayY(int);
|
||||
public:
|
||||
Sprite(int, int);
|
||||
~Sprite();
|
||||
@ -21,6 +26,10 @@ class Sprite {
|
||||
void Draw(DaisyPatch, int, int);
|
||||
void DrawTile(DaisyPatch, int, int, int, int);
|
||||
void SetBlank();
|
||||
void SetXShift(int);
|
||||
void SetYShift(int);
|
||||
void AdjustXShift(int);
|
||||
void AdjustYShift(int);
|
||||
};
|
||||
|
||||
#endif // CASCADE_GRAPHICS_SPRITE_H_
|
||||
|
Reference in New Issue
Block a user