mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-29 17:35:33 +00:00
Sprite shifting support
This commit is contained in:
parent
94c5b276bb
commit
8106e4ae70
@ -57,9 +57,6 @@ void Droplet::AnimationInc() {
|
||||
count = 0;
|
||||
}
|
||||
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) {
|
||||
@ -69,3 +66,7 @@ void Droplet::SetAnimationRate(int rate) {
|
||||
int Droplet::GetAnimationCount() {
|
||||
return animation_count;
|
||||
}
|
||||
|
||||
bool Droplet::NeedUpdate() {
|
||||
return count % animation_rate == 0;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
void AnimationInc();
|
||||
void SetAnimationRate(int);
|
||||
int GetAnimationCount();
|
||||
bool NeedUpdate();
|
||||
};
|
||||
|
||||
#endif // CASCADE_DROPLETS_DROPLET_H_
|
||||
|
@ -16,6 +16,12 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
|
||||
num_waves, Parameter::LINEAR);
|
||||
ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0,
|
||||
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() {
|
||||
@ -49,15 +55,12 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
|
||||
}
|
||||
|
||||
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,
|
||||
WaveToString(wavectrl.Process()));
|
||||
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
|
||||
if(NeedUpdate()) {
|
||||
wave->AdjustXShift(1);
|
||||
}
|
||||
DrawName("VCO");
|
||||
AnimationInc();
|
||||
}
|
||||
|
@ -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_
|
||||
|
Loading…
x
Reference in New Issue
Block a user