2014-07-27 13:39:07 +00:00
|
|
|
/*
|
|
|
|
* Pixel Dungeon
|
2015-06-12 20:44:04 +00:00
|
|
|
* Copyright (C) 2012-2015 Oleg Dolya
|
|
|
|
*
|
|
|
|
* Shattered Pixel Dungeon
|
|
|
|
* Copyright (C) 2014-2015 Evan Debenham
|
2014-07-27 13:39:07 +00:00
|
|
|
*
|
|
|
|
* 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/>
|
|
|
|
*/
|
2014-08-03 18:46:22 +00:00
|
|
|
package com.shatteredpixel.shatteredpixeldungeon.effects;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
import javax.microedition.khronos.opengles.GL10;
|
|
|
|
|
|
|
|
import android.opengl.GLES20;
|
|
|
|
|
|
|
|
import com.watabou.noosa.Game;
|
|
|
|
import com.watabou.noosa.Image;
|
|
|
|
import com.watabou.noosa.audio.Sample;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.utils.PointF;
|
|
|
|
|
2015-04-10 16:04:44 +00:00
|
|
|
public class Beam extends Image {
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
private static final double A = 180 / Math.PI;
|
|
|
|
|
2015-04-10 16:04:44 +00:00
|
|
|
private float duration;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
private float timeLeft;
|
2015-04-10 16:04:44 +00:00
|
|
|
|
|
|
|
private Beam(PointF s, PointF e, Effects.Type asset, float duration) {
|
|
|
|
super( Effects.get( asset ) );
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
origin.set( 0, height / 2 );
|
|
|
|
|
|
|
|
x = s.x - origin.x;
|
|
|
|
y = s.y - origin.y;
|
|
|
|
|
|
|
|
float dx = e.x - s.x;
|
|
|
|
float dy = e.y - s.y;
|
|
|
|
angle = (float)(Math.atan2( dy, dx ) * A);
|
|
|
|
scale.x = (float)Math.sqrt( dx * dx + dy * dy ) / width;
|
|
|
|
|
|
|
|
Sample.INSTANCE.play( Assets.SND_RAY );
|
|
|
|
|
2015-04-10 16:04:44 +00:00
|
|
|
timeLeft = this.duration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class DeathRay extends Beam{
|
|
|
|
public DeathRay(PointF s, PointF e){
|
|
|
|
super(s, e, Effects.Type.DEATH_RAY, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class LightRay extends Beam{
|
|
|
|
public LightRay(PointF s, PointF e){
|
|
|
|
super(s, e, Effects.Type.LIGHT_RAY, 1f);
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
2015-05-14 06:25:47 +00:00
|
|
|
|
|
|
|
public static class HealthRay extends Beam{
|
|
|
|
public HealthRay(PointF s, PointF e){
|
|
|
|
super(s, e, Effects.Type.HEALTH_RAY, 0.75f);
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
|
|
|
|
2015-04-10 16:04:44 +00:00
|
|
|
float p = timeLeft / duration;
|
2014-07-27 13:39:07 +00:00
|
|
|
alpha( p );
|
|
|
|
scale.set( scale.x, p );
|
|
|
|
|
|
|
|
if ((timeLeft -= Game.elapsed) <= 0) {
|
|
|
|
killAndErase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw() {
|
|
|
|
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE );
|
|
|
|
super.draw();
|
|
|
|
GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
}
|
|
|
|
}
|