v0.5.0: improved shadows, added perspective to item sprites
This commit is contained in:
parent
479c689196
commit
f54540d7a4
|
@ -65,7 +65,17 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
|
|
||||||
private static final float MOVE_INTERVAL = 0.1f;
|
private static final float MOVE_INTERVAL = 0.1f;
|
||||||
private static final float FLASH_INTERVAL = 0.05f;
|
private static final float FLASH_INTERVAL = 0.05f;
|
||||||
|
|
||||||
|
//the amount the sprite is raised from flat when viewed in a raised perspective
|
||||||
|
protected float perspectiveRaise = 0.4f;
|
||||||
|
|
||||||
|
//the width and height of the shadow are a percentage of sprite size
|
||||||
|
//offset is the number of pixels the shadow is moved down or up (handy for some animations)
|
||||||
|
protected boolean renderShadow = false;
|
||||||
|
protected float shadowWidth = 1.2f;
|
||||||
|
protected float shadowHeight = 0.25f;
|
||||||
|
protected float shadowOffset = 0.5f;
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED
|
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED
|
||||||
}
|
}
|
||||||
|
@ -116,6 +126,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
|
|
||||||
place( ch.pos );
|
place( ch.pos );
|
||||||
turnTo( ch.pos, Random.Int( Dungeon.level.length() ) );
|
turnTo( ch.pos, Random.Int( Dungeon.level.length() ) );
|
||||||
|
renderShadow = true;
|
||||||
|
|
||||||
ch.updateSpriteState();
|
ch.updateSpriteState();
|
||||||
}
|
}
|
||||||
|
@ -448,15 +459,16 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME shadows are really sloppily implemented here, there is surely a neater way to do this.
|
|
||||||
private float[] shadowMatrix;
|
private float[] shadowMatrix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateMatrix() {
|
protected void updateMatrix() {
|
||||||
super.updateMatrix();
|
super.updateMatrix();
|
||||||
shadowMatrix = Matrix.clone(matrix);
|
shadowMatrix = Matrix.clone(matrix);
|
||||||
Matrix.translate(shadowMatrix, -width()/13.333f, height()*0.7625f);
|
Matrix.translate(shadowMatrix,
|
||||||
Matrix.scale(shadowMatrix, 1.15f, 0.25f);
|
(width() * (1f - shadowWidth)) / 2f,
|
||||||
|
(height() * (1f - shadowHeight)) + shadowOffset);
|
||||||
|
Matrix.scale(shadowMatrix, shadowWidth, shadowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -464,31 +476,33 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
if (texture == null || (!dirty && buffer == null))
|
if (texture == null || (!dirty && buffer == null))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (dirty) {
|
if (renderShadow) {
|
||||||
verticesBuffer.position( 0 );
|
if (dirty) {
|
||||||
verticesBuffer.put( vertices );
|
verticesBuffer.position(0);
|
||||||
if (buffer == null)
|
verticesBuffer.put(vertices);
|
||||||
buffer = new Vertexbuffer( verticesBuffer );
|
if (buffer == null)
|
||||||
else
|
buffer = new Vertexbuffer(verticesBuffer);
|
||||||
buffer.updateVertices( verticesBuffer );
|
else
|
||||||
dirty = false;
|
buffer.updateVertices(verticesBuffer);
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NoosaScript script = script();
|
||||||
|
|
||||||
|
texture.bind();
|
||||||
|
|
||||||
|
script.camera(camera());
|
||||||
|
|
||||||
|
updateMatrix();
|
||||||
|
|
||||||
|
script.uModel.valueM4(shadowMatrix);
|
||||||
|
script.lighting(
|
||||||
|
0, 0, 0, am * .6f,
|
||||||
|
0, 0, 0, aa * .6f);
|
||||||
|
|
||||||
|
script.drawQuad(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
NoosaScript script = script();
|
|
||||||
|
|
||||||
texture.bind();
|
|
||||||
|
|
||||||
script.camera( camera() );
|
|
||||||
|
|
||||||
updateMatrix();
|
|
||||||
|
|
||||||
script.uModel.valueM4( shadowMatrix );
|
|
||||||
script.lighting(
|
|
||||||
0, 0, 0, am*.5f,
|
|
||||||
0, 0, 0, aa*.5f );
|
|
||||||
|
|
||||||
script.drawQuad( buffer );
|
|
||||||
|
|
||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,11 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
|
import com.watabou.glwrap.Matrix;
|
||||||
|
import com.watabou.glwrap.Vertexbuffer;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.MovieClip;
|
import com.watabou.noosa.MovieClip;
|
||||||
|
import com.watabou.noosa.NoosaScript;
|
||||||
import com.watabou.noosa.TextureFilm;
|
import com.watabou.noosa.TextureFilm;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.noosa.particles.Emitter;
|
import com.watabou.noosa.particles.Emitter;
|
||||||
|
@ -57,6 +60,16 @@ public class ItemSprite extends MovieClip {
|
||||||
private boolean glowUp;
|
private boolean glowUp;
|
||||||
|
|
||||||
private float dropInterval;
|
private float dropInterval;
|
||||||
|
|
||||||
|
//the amount the sprite is raised from flat when viewed in a raised perspective
|
||||||
|
protected float perspectiveRaise = 0.333f;
|
||||||
|
|
||||||
|
//the width and height of the shadow are a percentage of sprite size
|
||||||
|
//offset is the number of pixels the shadow is moved down or up (handy for some animations)
|
||||||
|
protected boolean renderShadow = false;
|
||||||
|
protected float shadowWidth = 1f;
|
||||||
|
protected float shadowHeight = 0.25f;
|
||||||
|
protected float shadowOffset = 0.5f;
|
||||||
|
|
||||||
public ItemSprite() {
|
public ItemSprite() {
|
||||||
this( ItemSpriteSheet.SOMETHING, null );
|
this( ItemSpriteSheet.SOMETHING, null );
|
||||||
|
@ -85,6 +98,7 @@ public class ItemSprite extends MovieClip {
|
||||||
public void link( Heap heap ) {
|
public void link( Heap heap ) {
|
||||||
this.heap = heap;
|
this.heap = heap;
|
||||||
view( heap.image(), heap.glowing() );
|
view( heap.image(), heap.glowing() );
|
||||||
|
renderShadow = true;
|
||||||
place(heap.pos);
|
place(heap.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,30 +209,83 @@ public class ItemSprite extends MovieClip {
|
||||||
emitter = null;
|
emitter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float[] shadowMatrix;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateMatrix() {
|
||||||
|
super.updateMatrix();
|
||||||
|
shadowMatrix = Matrix.clone(matrix);
|
||||||
|
Matrix.translate(shadowMatrix,
|
||||||
|
(width() * (1f - shadowWidth)) / 2f,
|
||||||
|
(height() * (1f - shadowHeight)) + shadowOffset);
|
||||||
|
Matrix.scale(shadowMatrix, shadowWidth, shadowHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw() {
|
||||||
|
if (texture == null || (!dirty && buffer == null))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (renderShadow) {
|
||||||
|
if (dirty) {
|
||||||
|
verticesBuffer.position(0);
|
||||||
|
verticesBuffer.put(vertices);
|
||||||
|
if (buffer == null)
|
||||||
|
buffer = new Vertexbuffer(verticesBuffer);
|
||||||
|
else
|
||||||
|
buffer.updateVertices(verticesBuffer);
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NoosaScript script = script();
|
||||||
|
|
||||||
|
texture.bind();
|
||||||
|
|
||||||
|
script.camera(camera());
|
||||||
|
|
||||||
|
updateMatrix();
|
||||||
|
|
||||||
|
script.uModel.valueM4(shadowMatrix);
|
||||||
|
script.lighting(
|
||||||
|
0, 0, 0, am * .6f,
|
||||||
|
0, 0, 0, aa * .6f);
|
||||||
|
|
||||||
|
script.drawQuad(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.draw();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
visible = (heap == null || heap.seen);
|
visible = (heap == null || heap.seen);
|
||||||
|
|
||||||
if (dropInterval > 0 && (dropInterval -= Game.elapsed) <= 0) {
|
if (dropInterval > 0){
|
||||||
|
shadowOffset -= speed.y * Game.elapsed * 0.8f;
|
||||||
speed.set( 0 );
|
|
||||||
acc.set( 0 );
|
|
||||||
place( heap.pos );
|
|
||||||
|
|
||||||
if (visible) {
|
if ((dropInterval -= Game.elapsed) <= 0){
|
||||||
boolean water = Level.water[heap.pos];
|
|
||||||
|
|
||||||
if (water) {
|
speed.set(0);
|
||||||
GameScene.ripple(heap.pos);
|
acc.set(0);
|
||||||
} else {
|
shadowOffset = 0.25f;
|
||||||
int cell = Dungeon.level.map[heap.pos];
|
place(heap.pos);
|
||||||
water = (cell == Terrain.WELL || cell == Terrain.ALCHEMY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(heap.peek() instanceof Gold)) {
|
if (visible) {
|
||||||
Sample.INSTANCE.play(water ? Assets.SND_WATER : Assets.SND_STEP, 0.8f, 0.8f, 1.2f);
|
boolean water = Level.water[heap.pos];
|
||||||
|
|
||||||
|
if (water) {
|
||||||
|
GameScene.ripple(heap.pos);
|
||||||
|
} else {
|
||||||
|
int cell = Dungeon.level.map[heap.pos];
|
||||||
|
water = (cell == Terrain.WELL || cell == Terrain.ALCHEMY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(heap.peek() instanceof Gold)) {
|
||||||
|
Sample.INSTANCE.play(water ? Assets.SND_WATER : Assets.SND_STEP, 0.8f, 0.8f, 1.2f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user