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.updateArmor();
|
||||
mobs.add( hero );
|
||||
Dungeon.hero.updateSpriteState();
|
||||
|
||||
for (Mob mob : Dungeon.level.mobs) {
|
||||
addMobSprite( mob );
|
||||
|
||||
+55
-24
@@ -58,6 +58,7 @@ import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.util.HashSet;
|
||||
|
||||
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;
|
||||
|
||||
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 run;
|
||||
@@ -358,8 +358,23 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||
flashTime = FLASH_INTERVAL;
|
||||
}
|
||||
|
||||
private final HashSet<State> stateAdditions = new HashSet<>();
|
||||
|
||||
public void add( State state ) {
|
||||
synchronized (State.class) {
|
||||
stateAdditions.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
private int auraColor = 0;
|
||||
|
||||
//Aura needs color data too
|
||||
public void aura( int color ){
|
||||
add(State.AURA);
|
||||
auraColor = color;
|
||||
}
|
||||
|
||||
private synchronized void processStateAddition( State state ) {
|
||||
switch (state) {
|
||||
case BURNING:
|
||||
if (burning != null) burning.on = false;
|
||||
@@ -425,12 +440,35 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||
if (glowBlock != null) glowBlock.killAndErase();
|
||||
glowBlock = GlowBlock.lighten(this);
|
||||
break;
|
||||
case AURA:
|
||||
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(auraColor, true);
|
||||
aura.visible = visible;
|
||||
|
||||
if (parent != null) {
|
||||
aura.show(this, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private final HashSet<State> stateRemovals = new HashSet<>();
|
||||
|
||||
public void remove( State state ) {
|
||||
synchronized (State.class) {
|
||||
stateRemovals.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAura(){
|
||||
remove(State.AURA);
|
||||
}
|
||||
|
||||
private synchronized void processStateRemoval( State state ) {
|
||||
switch (state) {
|
||||
case BURNING:
|
||||
if (burning != null) {
|
||||
@@ -506,31 +544,14 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||
glowBlock.darken();
|
||||
glowBlock = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void aura( int color ){
|
||||
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) {
|
||||
aura.show(this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAura(){
|
||||
break;
|
||||
case AURA:
|
||||
if (aura != null){
|
||||
aura.killAndErase();
|
||||
aura = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -547,6 +568,16 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||
}
|
||||
|
||||
synchronized (State.class) {
|
||||
for (State s : stateAdditions) {
|
||||
processStateAddition(s);
|
||||
}
|
||||
stateAdditions.clear();
|
||||
for (State s : stateRemovals) {
|
||||
processStateRemoval(s);
|
||||
}
|
||||
stateRemovals.clear();
|
||||
}
|
||||
|
||||
if (burning != null) {
|
||||
burning.visible = visible;
|
||||
}
|
||||
@@ -585,7 +616,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||
if (glowBlock != null){
|
||||
glowBlock.visible =visible;
|
||||
}
|
||||
}
|
||||
|
||||
if (sleeping) {
|
||||
showSleep();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user