Sprite shifting support

This commit is contained in:
Christian Colglazier 2020-09-23 20:09:12 -04:00
parent 94c5b276bb
commit 8106e4ae70
5 changed files with 56 additions and 12 deletions

View File

@ -57,9 +57,6 @@ void Droplet::AnimationInc() {
count = 0; count = 0;
} }
count++; count++;
//animation_count = animation_count % animation_rate;
WriteCenteredString(*patch, (screen_min + screen_max) / 2, 40,
Font_6x8, std::to_string(animation_count));
} }
void Droplet::SetAnimationRate(int rate) { void Droplet::SetAnimationRate(int rate) {
@ -69,3 +66,7 @@ void Droplet::SetAnimationRate(int rate) {
int Droplet::GetAnimationCount() { int Droplet::GetAnimationCount() {
return animation_count; return animation_count;
} }
bool Droplet::NeedUpdate() {
return count % animation_rate == 0;
}

View File

@ -43,6 +43,7 @@ public:
void AnimationInc(); void AnimationInc();
void SetAnimationRate(int); void SetAnimationRate(int);
int GetAnimationCount(); int GetAnimationCount();
bool NeedUpdate();
}; };
#endif // CASCADE_DROPLETS_DROPLET_H_ #endif // CASCADE_DROPLETS_DROPLET_H_

View File

@ -16,6 +16,12 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
num_waves, Parameter::LINEAR); num_waves, Parameter::LINEAR);
ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0, ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0,
0.5f, Parameter::LINEAR); 0.5f, Parameter::LINEAR);
wave->SetBlank();
for (int i = 0; i < sine_width; i++) {
int pixel = (int) round(std::sin(2*pi*((double)(i%sine_width)/sine_width)) * (GetTitleHeight()/2) + GetTitleHeight()/2);
wave->SetPixel(i, pixel, true);
}
} }
VCODroplet::~VCODroplet() { VCODroplet::~VCODroplet() {
@ -49,15 +55,12 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
} }
void VCODroplet::Draw() { void VCODroplet::Draw() {
wave->SetBlank();
for (int i = 0; i < sine_width; i++) {
int pixel = (int) round(std::sin(2*pi*((double)(i + GetAnimationCount()%sine_width)/sine_width)) * (GetTitleHeight()/2) + GetTitleHeight()/2);
wave->SetPixel(i, pixel, true);
}
WriteString(*Patch(), 0, 54, Font_6x8, WriteString(*Patch(), 0, 54, Font_6x8,
WaveToString(wavectrl.Process())); WaveToString(wavectrl.Process()));
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight()); wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
if(NeedUpdate()) {
wave->AdjustXShift(1);
}
DrawName("VCO"); DrawName("VCO");
AnimationInc(); AnimationInc();
} }

View File

@ -36,7 +36,9 @@ int Sprite::GetWidth() {
void Sprite::Draw(DaisyPatch patch, int x, int y) { void Sprite::Draw(DaisyPatch patch, int x, int y) {
for (int w = 0; w < width; w++) { for (int w = 0; w < width; w++) {
for (int h = 0; h < height; h++) { 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); int y_max = std::max(y1, y2);
for (int w = x_min; w < x_max; w++) { for (int w = x_min; w < x_max; w++) {
for (int h = y_min; h < y_max; h++) { for (int h = y_min; h < y_max; h++) {
patch.display.DrawPixel(w, h, sprite[(w-x_min) % width] patch.display.DrawPixel(w, h, sprite[GetShiftArrayX((w-x_min) % width)]
[(h-y_min) % height]); [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);
}

View File

@ -11,6 +11,11 @@ class Sprite {
private: private:
int width, height; int width, height;
bool** sprite; bool** sprite;
int x_shift = 0;
int y_shift = 0;
int GetShiftArray(int, int, int);
int GetShiftArrayX(int);
int GetShiftArrayY(int);
public: public:
Sprite(int, int); Sprite(int, int);
~Sprite(); ~Sprite();
@ -21,6 +26,10 @@ class Sprite {
void Draw(DaisyPatch, int, int); void Draw(DaisyPatch, int, int);
void DrawTile(DaisyPatch, int, int, int, int); void DrawTile(DaisyPatch, int, int, int, int);
void SetBlank(); void SetBlank();
void SetXShift(int);
void SetYShift(int);
void AdjustXShift(int);
void AdjustYShift(int);
}; };
#endif // CASCADE_GRAPHICS_SPRITE_H_ #endif // CASCADE_GRAPHICS_SPRITE_H_