v0.5.0: improved shadows, added perspective to item sprites
This commit is contained in:
parent
479c689196
commit
f54540d7a4
|
@ -66,6 +66,16 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
private static final float MOVE_INTERVAL = 0.1f;
|
||||
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 {
|
||||
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 );
|
||||
turnTo( ch.pos, Random.Int( Dungeon.level.length() ) );
|
||||
renderShadow = true;
|
||||
|
||||
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;
|
||||
|
||||
@Override
|
||||
protected void updateMatrix() {
|
||||
super.updateMatrix();
|
||||
shadowMatrix = Matrix.clone(matrix);
|
||||
Matrix.translate(shadowMatrix, -width()/13.333f, height()*0.7625f);
|
||||
Matrix.scale(shadowMatrix, 1.15f, 0.25f);
|
||||
Matrix.translate(shadowMatrix,
|
||||
(width() * (1f - shadowWidth)) / 2f,
|
||||
(height() * (1f - shadowHeight)) + shadowOffset);
|
||||
Matrix.scale(shadowMatrix, shadowWidth, shadowHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -464,13 +476,14 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
if (texture == null || (!dirty && buffer == null))
|
||||
return;
|
||||
|
||||
if (renderShadow) {
|
||||
if (dirty) {
|
||||
verticesBuffer.position( 0 );
|
||||
verticesBuffer.put( vertices );
|
||||
verticesBuffer.position(0);
|
||||
verticesBuffer.put(vertices);
|
||||
if (buffer == null)
|
||||
buffer = new Vertexbuffer( verticesBuffer );
|
||||
buffer = new Vertexbuffer(verticesBuffer);
|
||||
else
|
||||
buffer.updateVertices( verticesBuffer );
|
||||
buffer.updateVertices(verticesBuffer);
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
|
@ -478,16 +491,17 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
|
||||
texture.bind();
|
||||
|
||||
script.camera( camera() );
|
||||
script.camera(camera());
|
||||
|
||||
updateMatrix();
|
||||
|
||||
script.uModel.valueM4( shadowMatrix );
|
||||
script.uModel.valueM4(shadowMatrix);
|
||||
script.lighting(
|
||||
0, 0, 0, am*.5f,
|
||||
0, 0, 0, aa*.5f );
|
||||
0, 0, 0, am * .6f,
|
||||
0, 0, 0, aa * .6f);
|
||||
|
||||
script.drawQuad( buffer );
|
||||
script.drawQuad(buffer);
|
||||
}
|
||||
|
||||
super.draw();
|
||||
|
||||
|
|
|
@ -33,8 +33,11 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.watabou.gltextures.TextureCache;
|
||||
import com.watabou.glwrap.Matrix;
|
||||
import com.watabou.glwrap.Vertexbuffer;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.MovieClip;
|
||||
import com.watabou.noosa.NoosaScript;
|
||||
import com.watabou.noosa.TextureFilm;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.particles.Emitter;
|
||||
|
@ -58,6 +61,16 @@ public class ItemSprite extends MovieClip {
|
|||
|
||||
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() {
|
||||
this( ItemSpriteSheet.SOMETHING, null );
|
||||
}
|
||||
|
@ -85,6 +98,7 @@ public class ItemSprite extends MovieClip {
|
|||
public void link( Heap heap ) {
|
||||
this.heap = heap;
|
||||
view( heap.image(), heap.glowing() );
|
||||
renderShadow = true;
|
||||
place(heap.pos);
|
||||
}
|
||||
|
||||
|
@ -195,17 +209,69 @@ public class ItemSprite extends MovieClip {
|
|||
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
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
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 ((dropInterval -= Game.elapsed) <= 0){
|
||||
|
||||
speed.set(0);
|
||||
acc.set(0);
|
||||
shadowOffset = 0.25f;
|
||||
place(heap.pos);
|
||||
|
||||
if (visible) {
|
||||
boolean water = Level.water[heap.pos];
|
||||
|
@ -222,6 +288,7 @@ public class ItemSprite extends MovieClip {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (visible && glowing != null) {
|
||||
if (glowUp && (phase += Game.elapsed) > glowing.period) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user