v0.3.0: some refactoring to item sprites to better use an item as a parameter

This commit is contained in:
Evan Debenham
2015-05-11 20:14:13 -04:00
parent 097852207d
commit 0a78b2dc28
6 changed files with 23 additions and 13 deletions
@@ -59,7 +59,13 @@ public class ItemSprite extends MovieClip {
}
public ItemSprite( Item item ) {
this( item.image(), item.glowing() );
super(Assets.ITEMS);
if (film == null) {
film = new TextureFilm( texture, SIZE, SIZE );
}
view (item);
}
public ItemSprite( int image, Glowing glowing ) {
@@ -69,21 +75,21 @@ public class ItemSprite extends MovieClip {
film = new TextureFilm( texture, SIZE, SIZE );
}
view( image, glowing );
view(image, glowing);
}
public void originToCenter() {
origin.set(SIZE / 2 );
origin.set(SIZE / 2);
}
public void link() {
link( heap );
link(heap);
}
public void link( Heap heap ) {
this.heap = heap;
view( heap.image(), heap.glowing() );
place( heap.pos );
place(heap.pos);
}
@Override
@@ -119,7 +125,7 @@ public class ItemSprite extends MovieClip {
dropInterval = DROP_INTERVAL;
speed.set( 0, -100 );
acc.set( 0, -speed.y / DROP_INTERVAL * 2 );
acc.set(0, -speed.y / DROP_INTERVAL * 2);
if (visible && heap != null && heap.peek() instanceof Gold) {
CellEmitter.center( heap.pos ).burst( Speck.factory( Speck.COIN ), 5 );
@@ -137,11 +143,15 @@ public class ItemSprite extends MovieClip {
float py = y;
drop();
place( from );
place(from);
speed.offset( (px-x) / DROP_INTERVAL, (py-y) / DROP_INTERVAL );
speed.offset((px - x) / DROP_INTERVAL, (py - y) / DROP_INTERVAL);
}
}
public ItemSprite view(Item item){
return view(item.image(), item.glowing());
}
public ItemSprite view( int image, Glowing glowing ) {
frame( film.get( image ) );
@@ -140,7 +140,7 @@ public class ItemSlot extends Button {
active = true;
icon.visible = topLeft.visible = topRight.visible = bottomRight.visible = true;
icon.view( item.image(), item.glowing() );
icon.view( item );
topLeft.text( item.status() );
@@ -341,7 +341,7 @@ public class Toolbar extends Component {
}
public void reset( Item item, float dstX, float dstY ) {
view( item.image(), item.glowing() );
view( item );
active =
visible =
@@ -45,7 +45,7 @@ public class IconTitle extends Component {
public IconTitle( Item item ) {
this(
new ItemSprite( item.image(), item.glowing() ),
new ItemSprite( item ),
Utils.capitalize( item.toString() ) );
}
@@ -41,7 +41,7 @@ public class WndItem extends Window {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) );
titlebar.icon( new ItemSprite( item ) );
titlebar.label( Utils.capitalize( item.toString() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
@@ -205,7 +205,7 @@ public class WndTradeItem extends Window {
// Title
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) );
titlebar.icon( new ItemSprite( item ) );
titlebar.label( forSale ?
Utils.format( TXT_SALE, item.toString(), price( item ) ) :
Utils.capitalize( item.toString() ) );