v3.0.0: new sprite state logic, now only processes fx in display thread
This commit is contained in:
@@ -303,7 +303,6 @@ public class GameScene extends PixelScene {
|
|||||||
hero.place( Dungeon.hero.pos );
|
hero.place( Dungeon.hero.pos );
|
||||||
hero.updateArmor();
|
hero.updateArmor();
|
||||||
mobs.add( hero );
|
mobs.add( hero );
|
||||||
Dungeon.hero.updateSpriteState();
|
|
||||||
|
|
||||||
for (Mob mob : Dungeon.level.mobs) {
|
for (Mob mob : Dungeon.level.mobs) {
|
||||||
addMobSprite( mob );
|
addMobSprite( mob );
|
||||||
|
|||||||
+229
-198
@@ -58,6 +58,7 @@ import com.watabou.utils.PointF;
|
|||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
|
||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip.Listener {
|
public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip.Listener {
|
||||||
|
|
||||||
@@ -83,9 +84,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||||||
protected float shadowOffset = 0.25f;
|
protected float shadowOffset = 0.25f;
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED, HEALING, SHIELDED, HEARTS, GLOWING
|
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED, HEALING, SHIELDED, HEARTS, GLOWING, AURA
|
||||||
}
|
}
|
||||||
private int stunStates = 0;
|
|
||||||
|
|
||||||
protected Animation idle;
|
protected Animation idle;
|
||||||
protected Animation run;
|
protected Animation run;
|
||||||
@@ -357,179 +357,200 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||||||
ra = ba = ga = 1f;
|
ra = ba = ga = 1f;
|
||||||
flashTime = FLASH_INTERVAL;
|
flashTime = FLASH_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final HashSet<State> stateAdditions = new HashSet<>();
|
||||||
|
|
||||||
public void add( State state ) {
|
public void add( State state ) {
|
||||||
synchronized (State.class) {
|
synchronized (State.class) {
|
||||||
switch (state) {
|
stateAdditions.add(state);
|
||||||
case BURNING:
|
|
||||||
if (burning != null) burning.on = false;
|
|
||||||
burning = emitter();
|
|
||||||
burning.pour(FlameParticle.FACTORY, 0.06f);
|
|
||||||
if (visible) {
|
|
||||||
Sample.INSTANCE.play(Assets.Sounds.BURNING);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LEVITATING:
|
|
||||||
if (levitation != null) levitation.on = false;
|
|
||||||
levitation = emitter();
|
|
||||||
levitation.pour(Speck.factory(Speck.JET), 0.02f);
|
|
||||||
break;
|
|
||||||
case INVISIBLE:
|
|
||||||
if (invisible != null) invisible.killAndErase();
|
|
||||||
invisible = new AlphaTweener(this, 0.4f, 0.4f);
|
|
||||||
if (parent != null) {
|
|
||||||
parent.add(invisible);
|
|
||||||
} else
|
|
||||||
alpha(0.4f);
|
|
||||||
break;
|
|
||||||
case PARALYSED:
|
|
||||||
paused = true;
|
|
||||||
break;
|
|
||||||
case FROZEN:
|
|
||||||
if (iceBlock != null) iceBlock.killAndErase();
|
|
||||||
iceBlock = IceBlock.freeze(this);
|
|
||||||
break;
|
|
||||||
case ILLUMINATED:
|
|
||||||
if (light != null) light.putOut();
|
|
||||||
GameScene.effect(light = new TorchHalo(this));
|
|
||||||
break;
|
|
||||||
case CHILLED:
|
|
||||||
if (chilled != null) chilled.on = false;
|
|
||||||
chilled = emitter();
|
|
||||||
chilled.pour(SnowParticle.FACTORY, 0.1f);
|
|
||||||
break;
|
|
||||||
case DARKENED:
|
|
||||||
if (darkBlock != null) darkBlock.killAndErase();
|
|
||||||
darkBlock = DarkBlock.darken(this);
|
|
||||||
break;
|
|
||||||
case MARKED:
|
|
||||||
if (marked != null) marked.on = false;
|
|
||||||
marked = emitter();
|
|
||||||
marked.pour(ShadowParticle.UP, 0.1f);
|
|
||||||
break;
|
|
||||||
case HEALING:
|
|
||||||
if (healing != null) healing.on = false;
|
|
||||||
healing = emitter();
|
|
||||||
healing.pour(Speck.factory(Speck.HEALING), 0.5f);
|
|
||||||
break;
|
|
||||||
case SHIELDED:
|
|
||||||
if (shield != null) shield.killAndErase();
|
|
||||||
GameScene.effect(shield = new ShieldHalo(this));
|
|
||||||
break;
|
|
||||||
case HEARTS:
|
|
||||||
if (hearts != null) hearts.on = false;
|
|
||||||
hearts = emitter();
|
|
||||||
hearts.pour(Speck.factory(Speck.HEART), 0.5f);
|
|
||||||
break;
|
|
||||||
case GLOWING:
|
|
||||||
if (glowBlock != null) glowBlock.killAndErase();
|
|
||||||
glowBlock = GlowBlock.lighten(this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int auraColor = 0;
|
||||||
|
|
||||||
|
//Aura needs color data too
|
||||||
|
public void aura( int color ){
|
||||||
|
add(State.AURA);
|
||||||
|
auraColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public void remove( State state ) {
|
private synchronized void processStateAddition( State state ) {
|
||||||
synchronized (State.class) {
|
switch (state) {
|
||||||
switch (state) {
|
case BURNING:
|
||||||
case BURNING:
|
if (burning != null) burning.on = false;
|
||||||
if (burning != null) {
|
burning = emitter();
|
||||||
burning.on = false;
|
burning.pour(FlameParticle.FACTORY, 0.06f);
|
||||||
burning = null;
|
if (visible) {
|
||||||
}
|
Sample.INSTANCE.play(Assets.Sounds.BURNING);
|
||||||
break;
|
}
|
||||||
case LEVITATING:
|
break;
|
||||||
if (levitation != null) {
|
case LEVITATING:
|
||||||
levitation.on = false;
|
if (levitation != null) levitation.on = false;
|
||||||
levitation = null;
|
levitation = emitter();
|
||||||
}
|
levitation.pour(Speck.factory(Speck.JET), 0.02f);
|
||||||
break;
|
break;
|
||||||
case INVISIBLE:
|
case INVISIBLE:
|
||||||
if (invisible != null) {
|
if (invisible != null) invisible.killAndErase();
|
||||||
invisible.killAndErase();
|
invisible = new AlphaTweener(this, 0.4f, 0.4f);
|
||||||
invisible = null;
|
if (parent != null) {
|
||||||
}
|
parent.add(invisible);
|
||||||
alpha(1f);
|
} else
|
||||||
break;
|
alpha(0.4f);
|
||||||
case PARALYSED:
|
break;
|
||||||
paused = false;
|
case PARALYSED:
|
||||||
break;
|
paused = true;
|
||||||
case FROZEN:
|
break;
|
||||||
if (iceBlock != null) {
|
case FROZEN:
|
||||||
iceBlock.melt();
|
if (iceBlock != null) iceBlock.killAndErase();
|
||||||
iceBlock = null;
|
iceBlock = IceBlock.freeze(this);
|
||||||
}
|
break;
|
||||||
break;
|
case ILLUMINATED:
|
||||||
case ILLUMINATED:
|
if (light != null) light.putOut();
|
||||||
if (light != null) {
|
GameScene.effect(light = new TorchHalo(this));
|
||||||
light.putOut();
|
break;
|
||||||
light = null;
|
case CHILLED:
|
||||||
}
|
if (chilled != null) chilled.on = false;
|
||||||
break;
|
chilled = emitter();
|
||||||
case CHILLED:
|
chilled.pour(SnowParticle.FACTORY, 0.1f);
|
||||||
if (chilled != null) {
|
break;
|
||||||
chilled.on = false;
|
case DARKENED:
|
||||||
chilled = null;
|
if (darkBlock != null) darkBlock.killAndErase();
|
||||||
}
|
darkBlock = DarkBlock.darken(this);
|
||||||
break;
|
break;
|
||||||
case DARKENED:
|
case MARKED:
|
||||||
if (darkBlock != null) {
|
if (marked != null) marked.on = false;
|
||||||
darkBlock.lighten();
|
marked = emitter();
|
||||||
darkBlock = null;
|
marked.pour(ShadowParticle.UP, 0.1f);
|
||||||
}
|
break;
|
||||||
break;
|
case HEALING:
|
||||||
case MARKED:
|
if (healing != null) healing.on = false;
|
||||||
if (marked != null) {
|
healing = emitter();
|
||||||
marked.on = false;
|
healing.pour(Speck.factory(Speck.HEALING), 0.5f);
|
||||||
marked = null;
|
break;
|
||||||
}
|
case SHIELDED:
|
||||||
break;
|
if (shield != null) shield.killAndErase();
|
||||||
case HEALING:
|
GameScene.effect(shield = new ShieldHalo(this));
|
||||||
if (healing != null) {
|
break;
|
||||||
healing.on = false;
|
case HEARTS:
|
||||||
healing = null;
|
if (hearts != null) hearts.on = false;
|
||||||
}
|
hearts = emitter();
|
||||||
break;
|
hearts.pour(Speck.factory(Speck.HEART), 0.5f);
|
||||||
case SHIELDED:
|
break;
|
||||||
if (shield != null) {
|
case GLOWING:
|
||||||
shield.putOut();
|
if (glowBlock != null) glowBlock.killAndErase();
|
||||||
}
|
glowBlock = GlowBlock.lighten(this);
|
||||||
break;
|
break;
|
||||||
case HEARTS:
|
case AURA:
|
||||||
if (hearts != null) {
|
if (aura != null) aura.killAndErase();
|
||||||
hearts.on = false;
|
float size = Math.max(width(), height());
|
||||||
hearts = null;
|
size = Math.max(size+4, 16);
|
||||||
}
|
aura = new Flare(5, size);
|
||||||
break;
|
aura.angularSpeed = 90;
|
||||||
case GLOWING:
|
aura.color(auraColor, true);
|
||||||
if (glowBlock != null){
|
aura.visible = visible;
|
||||||
glowBlock.darken();
|
|
||||||
glowBlock = null;
|
if (parent != null) {
|
||||||
}
|
aura.show(this, 0);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void aura( int color ){
|
private final HashSet<State> stateRemovals = new HashSet<>();
|
||||||
if (aura != null){
|
|
||||||
aura.killAndErase();
|
|
||||||
}
|
|
||||||
float size = Math.max(width(), height());
|
|
||||||
size = Math.max(size+4, 16);
|
|
||||||
aura = new Flare(5, size);
|
|
||||||
aura.angularSpeed = 90;
|
|
||||||
aura.color(color, true);
|
|
||||||
aura.visible = visible;
|
|
||||||
|
|
||||||
if (parent != null) {
|
public void remove( State state ) {
|
||||||
aura.show(this, 0);
|
synchronized (State.class) {
|
||||||
|
stateRemovals.add(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAura(){
|
public void clearAura(){
|
||||||
if (aura != null){
|
remove(State.AURA);
|
||||||
aura.killAndErase();
|
}
|
||||||
aura = null;
|
|
||||||
|
private synchronized void processStateRemoval( State state ) {
|
||||||
|
switch (state) {
|
||||||
|
case BURNING:
|
||||||
|
if (burning != null) {
|
||||||
|
burning.on = false;
|
||||||
|
burning = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LEVITATING:
|
||||||
|
if (levitation != null) {
|
||||||
|
levitation.on = false;
|
||||||
|
levitation = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INVISIBLE:
|
||||||
|
if (invisible != null) {
|
||||||
|
invisible.killAndErase();
|
||||||
|
invisible = null;
|
||||||
|
}
|
||||||
|
alpha(1f);
|
||||||
|
break;
|
||||||
|
case PARALYSED:
|
||||||
|
paused = false;
|
||||||
|
break;
|
||||||
|
case FROZEN:
|
||||||
|
if (iceBlock != null) {
|
||||||
|
iceBlock.melt();
|
||||||
|
iceBlock = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ILLUMINATED:
|
||||||
|
if (light != null) {
|
||||||
|
light.putOut();
|
||||||
|
light = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CHILLED:
|
||||||
|
if (chilled != null) {
|
||||||
|
chilled.on = false;
|
||||||
|
chilled = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DARKENED:
|
||||||
|
if (darkBlock != null) {
|
||||||
|
darkBlock.lighten();
|
||||||
|
darkBlock = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MARKED:
|
||||||
|
if (marked != null) {
|
||||||
|
marked.on = false;
|
||||||
|
marked = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HEALING:
|
||||||
|
if (healing != null) {
|
||||||
|
healing.on = false;
|
||||||
|
healing = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SHIELDED:
|
||||||
|
if (shield != null) {
|
||||||
|
shield.putOut();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HEARTS:
|
||||||
|
if (hearts != null) {
|
||||||
|
hearts.on = false;
|
||||||
|
hearts = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GLOWING:
|
||||||
|
if (glowBlock != null){
|
||||||
|
glowBlock.darken();
|
||||||
|
glowBlock = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AURA:
|
||||||
|
if (aura != null){
|
||||||
|
aura.killAndErase();
|
||||||
|
aura = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,45 +568,55 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (State.class) {
|
synchronized (State.class) {
|
||||||
if (burning != null) {
|
for (State s : stateAdditions) {
|
||||||
burning.visible = visible;
|
processStateAddition(s);
|
||||||
}
|
}
|
||||||
if (levitation != null) {
|
stateAdditions.clear();
|
||||||
levitation.visible = visible;
|
for (State s : stateRemovals) {
|
||||||
}
|
processStateRemoval(s);
|
||||||
if (iceBlock != null) {
|
|
||||||
iceBlock.visible = visible;
|
|
||||||
}
|
|
||||||
if (light != null) {
|
|
||||||
light.visible = visible;
|
|
||||||
}
|
|
||||||
if (chilled != null) {
|
|
||||||
chilled.visible = visible;
|
|
||||||
}
|
|
||||||
if (darkBlock != null) {
|
|
||||||
darkBlock.visible = visible;
|
|
||||||
}
|
|
||||||
if (marked != null) {
|
|
||||||
marked.visible = visible;
|
|
||||||
}
|
|
||||||
if (healing != null) {
|
|
||||||
healing.visible = visible;
|
|
||||||
}
|
|
||||||
if (hearts != null) {
|
|
||||||
hearts.visible = visible;
|
|
||||||
}
|
|
||||||
//shield fx updates its own visibility
|
|
||||||
if (aura != null) {
|
|
||||||
if (aura.parent == null) {
|
|
||||||
aura.show(this, 0);
|
|
||||||
}
|
|
||||||
aura.visible = visible;
|
|
||||||
aura.point(center());
|
|
||||||
}
|
|
||||||
if (glowBlock != null){
|
|
||||||
glowBlock.visible =visible;
|
|
||||||
}
|
}
|
||||||
|
stateRemovals.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (burning != null) {
|
||||||
|
burning.visible = visible;
|
||||||
|
}
|
||||||
|
if (levitation != null) {
|
||||||
|
levitation.visible = visible;
|
||||||
|
}
|
||||||
|
if (iceBlock != null) {
|
||||||
|
iceBlock.visible = visible;
|
||||||
|
}
|
||||||
|
if (light != null) {
|
||||||
|
light.visible = visible;
|
||||||
|
}
|
||||||
|
if (chilled != null) {
|
||||||
|
chilled.visible = visible;
|
||||||
|
}
|
||||||
|
if (darkBlock != null) {
|
||||||
|
darkBlock.visible = visible;
|
||||||
|
}
|
||||||
|
if (marked != null) {
|
||||||
|
marked.visible = visible;
|
||||||
|
}
|
||||||
|
if (healing != null) {
|
||||||
|
healing.visible = visible;
|
||||||
|
}
|
||||||
|
if (hearts != null) {
|
||||||
|
hearts.visible = visible;
|
||||||
|
}
|
||||||
|
//shield fx updates its own visibility
|
||||||
|
if (aura != null) {
|
||||||
|
if (aura.parent == null) {
|
||||||
|
aura.show(this, 0);
|
||||||
|
}
|
||||||
|
aura.visible = visible;
|
||||||
|
aura.point(center());
|
||||||
|
}
|
||||||
|
if (glowBlock != null){
|
||||||
|
glowBlock.visible =visible;
|
||||||
|
}
|
||||||
|
|
||||||
if (sleeping) {
|
if (sleeping) {
|
||||||
showSleep();
|
showSleep();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user