2017-07-18 16:46:21 +00:00
|
|
|
/*
|
|
|
|
1010! Klooni, a free customizable puzzle game for Android and Desktop
|
|
|
|
Copyright (C) 2017 Lonami Exo | LonamiWebs
|
|
|
|
|
|
|
|
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 io.github.lonamiwebs.klooni;
|
|
|
|
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
|
|
import com.badlogic.gdx.audio.Sound;
|
2017-09-09 16:51:33 +00:00
|
|
|
import com.badlogic.gdx.files.FileHandle;
|
2017-07-18 16:46:21 +00:00
|
|
|
import com.badlogic.gdx.math.MathUtils;
|
|
|
|
import com.badlogic.gdx.math.Vector2;
|
|
|
|
|
|
|
|
import io.github.lonamiwebs.klooni.effects.EvaporateEffect;
|
2017-09-10 09:15:34 +00:00
|
|
|
import io.github.lonamiwebs.klooni.effects.ExplodeEffect;
|
2017-07-18 16:46:21 +00:00
|
|
|
import io.github.lonamiwebs.klooni.effects.IEffect;
|
2017-09-09 16:39:33 +00:00
|
|
|
import io.github.lonamiwebs.klooni.effects.SpinEffect;
|
2017-07-18 16:46:21 +00:00
|
|
|
import io.github.lonamiwebs.klooni.effects.VanishEffect;
|
|
|
|
import io.github.lonamiwebs.klooni.effects.WaterdropEffect;
|
|
|
|
import io.github.lonamiwebs.klooni.game.Cell;
|
|
|
|
|
|
|
|
public class Effect {
|
|
|
|
|
|
|
|
//region Members
|
|
|
|
|
|
|
|
private final int effectId;
|
|
|
|
private final Sound effectSound;
|
2017-07-19 11:32:33 +00:00
|
|
|
public final String name;
|
|
|
|
public final int price;
|
2017-07-18 16:46:21 +00:00
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Constructor
|
|
|
|
|
|
|
|
// This method will load the sound "sound/effect_{effectName}.mp3"
|
|
|
|
public Effect(final String effectName) {
|
2017-09-09 16:51:33 +00:00
|
|
|
this(effectName, effectNameToInt(effectName));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Effect(final String effectName, final int id) {
|
2017-07-19 11:32:33 +00:00
|
|
|
name = effectName;
|
2017-09-09 16:51:33 +00:00
|
|
|
effectId = id;
|
|
|
|
|
|
|
|
FileHandle soundFile = Gdx.files.internal("sound/effect_" + name + ".mp3");
|
|
|
|
if (!soundFile.exists())
|
|
|
|
soundFile = Gdx.files.internal("sound/effect_vanish.mp3");
|
|
|
|
|
|
|
|
effectSound = Gdx.audio.newSound(soundFile);
|
2017-07-19 11:32:33 +00:00
|
|
|
price = effectId == 0 ? 0 : 200; // TODO For now they're all 200 coins except the first
|
2017-07-18 16:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Public methods
|
|
|
|
|
|
|
|
public void playSound() {
|
|
|
|
effectSound.play(MathUtils.random(0.7f, 1f), MathUtils.random(0.8f, 1.2f), 0);
|
|
|
|
}
|
|
|
|
|
2017-07-19 11:32:33 +00:00
|
|
|
public String getDisplay() {
|
|
|
|
// TODO For now, uppercase the first letter
|
|
|
|
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
|
|
}
|
|
|
|
|
2017-07-18 16:46:21 +00:00
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Static methods
|
|
|
|
|
|
|
|
public static Effect[] getEffects() {
|
2017-09-09 16:51:33 +00:00
|
|
|
int id = 0;
|
2017-07-18 16:46:21 +00:00
|
|
|
return new Effect[] {
|
2017-09-09 16:51:33 +00:00
|
|
|
new Effect("vanish", id++),
|
|
|
|
new Effect("waterdrop", id++),
|
|
|
|
new Effect("evaporate", id++),
|
2017-09-10 09:15:34 +00:00
|
|
|
new Effect("spin", id++),
|
|
|
|
new Effect("explode", id++)
|
2017-07-18 16:46:21 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Name <-> ID <-> IEffect
|
|
|
|
|
|
|
|
// Effects used when clearing a row
|
|
|
|
public IEffect create(final Cell deadCell, final Vector2 culprit) {
|
|
|
|
final IEffect effect;
|
|
|
|
switch (effectId) {
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
effect = new VanishEffect();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
effect = new WaterdropEffect();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
effect = new EvaporateEffect();
|
|
|
|
break;
|
2017-09-09 16:39:33 +00:00
|
|
|
case 3:
|
|
|
|
effect = new SpinEffect();
|
|
|
|
break;
|
2017-09-10 09:15:34 +00:00
|
|
|
case 4:
|
|
|
|
effect = new ExplodeEffect();
|
|
|
|
break;
|
2017-07-18 16:46:21 +00:00
|
|
|
}
|
|
|
|
effect.setInfo(deadCell, culprit);
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int effectNameToInt(final String name) {
|
|
|
|
// String comparision is more expensive compared to a single integer one,
|
|
|
|
// and when creating instances of a lot of effects it's better if we can
|
|
|
|
// save some processor cycles.
|
2017-09-09 16:40:43 +00:00
|
|
|
final Effect[] effects = getEffects();
|
|
|
|
for (int i = 0; i != effects.length; ++i)
|
|
|
|
if (effects[i].name.equals(name))
|
|
|
|
return i;
|
2017-07-18 16:46:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Disposal
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
effectSound.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
}
|