Glitch effect (sorta, will prob modify later)
This commit is contained in:
parent
a39246546a
commit
0be7645aba
2 changed files with 129 additions and 0 deletions
|
@ -32,6 +32,7 @@ import java.util.Map;
|
|||
|
||||
import dev.lonami.klooni.effects.EvaporateEffectFactory;
|
||||
import dev.lonami.klooni.effects.ExplodeEffectFactory;
|
||||
import dev.lonami.klooni.effects.GlitchEffectFactory;
|
||||
import dev.lonami.klooni.effects.SpinEffectFactory;
|
||||
import dev.lonami.klooni.effects.VanishEffectFactory;
|
||||
import dev.lonami.klooni.effects.WaterdropEffectFactory;
|
||||
|
@ -54,6 +55,7 @@ public class Klooni extends Game {
|
|||
new EvaporateEffectFactory(),
|
||||
new SpinEffectFactory(),
|
||||
new ExplodeEffectFactory(),
|
||||
new GlitchEffectFactory()
|
||||
};
|
||||
|
||||
private Map<String, Sound> effectSounds;
|
||||
|
|
127
core/src/dev/lonami/klooni/effects/GlitchEffectFactory.java
Normal file
127
core/src/dev/lonami/klooni/effects/GlitchEffectFactory.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
1010! Klooni, a free customizable puzzle game for Android and Desktop
|
||||
Copyright (C) 2024 RustyStriker @ rustystriker.dev
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package dev.lonami.klooni.effects;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
|
||||
import dev.lonami.klooni.game.Cell;
|
||||
import dev.lonami.klooni.interfaces.IEffect;
|
||||
import dev.lonami.klooni.interfaces.IEffectFactory;
|
||||
|
||||
|
||||
public class GlitchEffectFactory implements IEffectFactory {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "glitch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay() {
|
||||
return "Glitch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrice() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEffect create(Cell deadCell, Vector2 culprit) {
|
||||
IEffect effect = new GlitchEffect();
|
||||
effect.setInfo(deadCell, culprit);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
private class GlitchEffect implements IEffect {
|
||||
private Cell cell;
|
||||
|
||||
private Color color;
|
||||
private float lifetime;
|
||||
private final float LIFETIME = 1.0f;
|
||||
|
||||
|
||||
GlitchEffect() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInfo(Cell deadCell, Vector2 culprit) {
|
||||
cell = deadCell;
|
||||
|
||||
color = cell.getColorCopy();
|
||||
lifetime = 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch) {
|
||||
lifetime += Gdx.graphics.getDeltaTime();
|
||||
|
||||
|
||||
float yScale = Interpolation.exp10.apply(1, 0, lifetime / LIFETIME);
|
||||
final Matrix4 effect = batch.getTransformMatrix();
|
||||
final Matrix4 original = effect.cpy();
|
||||
|
||||
float xScale = lifetime / LIFETIME < 0.5f ?
|
||||
1.0f :
|
||||
Interpolation.exp10Out.apply(1f, 0f, lifetime / LIFETIME);
|
||||
|
||||
effect.translate(cell.pos.x + cell.size * 0.5f, cell.pos.y + cell.size * 0.5f, 0f);
|
||||
float size = yScale * cell.size;
|
||||
effect.scale(xScale, yScale, 1.0f);
|
||||
effect.translate(-xScale * cell.size * 0.5f, -size * 0.5f, 0f);
|
||||
|
||||
batch.setTransformMatrix(effect);
|
||||
|
||||
Cell.draw(
|
||||
new Color(color.r, 0f, 0f, 1f),
|
||||
batch,
|
||||
-0.2f * cell.size,
|
||||
0f,
|
||||
cell.size
|
||||
);
|
||||
Cell.draw(
|
||||
new Color(0f, color.g, 0f, 1f),
|
||||
batch,
|
||||
0.08f * cell.size,
|
||||
0.08f * cell.size,
|
||||
cell.size
|
||||
);
|
||||
Cell.draw(
|
||||
new Color(0f, 0f, color.b, 1f),
|
||||
batch,
|
||||
0.08f * cell.size,
|
||||
-0.08f * cell.size,
|
||||
cell.size
|
||||
);
|
||||
Cell.draw(color, batch, 0f, 0f, cell.size);
|
||||
batch.setTransformMatrix(original);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return lifetime > LIFETIME;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue