Add amt sprite to all items where value != 0

This commit is contained in:
Linus Probert 2019-03-04 16:06:13 +01:00
parent 959fae1730
commit 68f44090ed
1 changed files with 28 additions and 26 deletions

View File

@ -79,27 +79,6 @@ pickup_dagger(Item *item, Player *player)
gui_log("You collect a dagger"); gui_log("You collect a dagger");
} }
static Item *
create_item(const char *path0, const char *path1, SDL_Rect clip, void (*cb)(Item*, Player*))
{
Item *item;
item = item_create();
Texture *t0 = texturecache_add(path0);
Texture *t1 = NULL;
if (path1)
t1 = texturecache_add(path1);
item->sprite = sprite_create();
sprite_set_texture(item->sprite, t0, 0);
sprite_set_texture(item->sprite, t1, 1);
item->sprite->dim = GAME_DIMENSION;
item->sprite->clip = clip;
item->effect = cb;
return item;
}
static Sprite * static Sprite *
create_number_subsprite(SDL_Color fg, create_number_subsprite(SDL_Color fg,
SDL_Color outline, SDL_Color outline,
@ -121,6 +100,27 @@ create_number_subsprite(SDL_Color fg,
return sprite; return sprite;
} }
static Item *
create_item(const char *path0, const char *path1, SDL_Rect clip, void (*cb)(Item*, Player*))
{
Item *item;
item = item_create();
Texture *t0 = texturecache_add(path0);
Texture *t1 = NULL;
if (path1)
t1 = texturecache_add(path1);
item->sprite = sprite_create();
sprite_set_texture(item->sprite, t0, 0);
sprite_set_texture(item->sprite, t1, 1);
item->sprite->dim = GAME_DIMENSION;
item->sprite->clip = clip;
item->effect = cb;
return item;
}
static Item * static Item *
create_priced_item(double price, create_priced_item(double price,
const char *path0, const char *path0,
@ -134,11 +134,6 @@ create_priced_item(double price,
Sprite *priceSprite = create_number_subsprite(C_YELLOW, C_BLACK, "$%.0f", item->price); Sprite *priceSprite = create_number_subsprite(C_YELLOW, C_BLACK, "$%.0f", item->price);
linkedlist_append(&item->subsprites, priceSprite); linkedlist_append(&item->subsprites, priceSprite);
Sprite *valueSprite = create_number_subsprite(C_BLUE, C_BLACK, "$.1f", item->value);
valueSprite->offset.x = item->sprite->dim.width - valueSprite->dim.width;
valueSprite->offset.y = item->sprite->dim.height - valueSprite->dim.height;
linkedlist_append(&item->subsprites, valueSprite);
return item; return item;
} }
@ -247,6 +242,13 @@ item_builder_build_item(ItemKey key, int level)
break; break;
} }
if (item->value != 1) {
Sprite *valueSprite = create_number_subsprite(C_BLUE, C_BLACK, "%.1f", item->value);
valueSprite->offset.x = item->sprite->dim.width - valueSprite->dim.width;
valueSprite->offset.y = item->sprite->dim.height - valueSprite->dim.height;
linkedlist_append(&item->subsprites, valueSprite);
}
return item; return item;
} }