Completes buyable items

This commit is contained in:
Linus Probert 2019-02-28 20:37:19 +01:00
parent 16d9035941
commit 7b47c6a6bf
4 changed files with 16 additions and 5 deletions

View File

@ -46,8 +46,13 @@ item_render(Item *item, Camera *cam)
sprite_render(item->sprite, cam);
LinkedList *subsprites = item->subsprites;
while (subsprites)
sprite_render(linkedlist_pop(&subsprites), cam);
while (subsprites != NULL) {
Sprite *sprite = subsprites->data;
sprite->pos = item->sprite->pos;
sprite->pos.x + 15 - sprite->dim.width / 2;
sprite_render(sprite, cam);
subsprites = subsprites->next;
}
}
void
@ -75,7 +80,7 @@ item_collected(Item *item, Player *player)
if (item->price) {
player->gold -= item->price;
char costLabel[10];
m_sprintf(costLabel, 10, "-%d", item->price);
m_sprintf(costLabel, 10, "-$%.0f", item->price);
actiontextbuilder_create_text(costLabel, C_YELLOW, &player->sprite->pos);
}

View File

@ -108,14 +108,14 @@ create_priced_item(double price, const char *path0, const char *path1, SDL_Rect
Sprite *priceSprite = sprite_create();
sprite_load_text_texture(priceSprite, "GUI/SDS_8x8.ttf", 0, 8, 1);
char priceLabel[10];
m_sprintf(priceLabel, 10, "%d", item->price);
m_sprintf(priceLabel, 10, "$%.0f", item->price);
texture_load_from_text(priceSprite->textures[0],
priceLabel,
C_YELLOW,
C_BLACK,
builder->renderer);
priceSprite->pos = item->sprite->pos;
priceSprite->dim = priceSprite->textures[0]->dim;
linkedlist_append(&item->subsprites, priceSprite);
return item;
}

View File

@ -516,6 +516,7 @@ player_create(class_t class, Camera *cam)
player->animationTimer = _timer_create();
player->swordAnimation = animation_create(5);
player->equipment.hasArtifacts = false;
player->stateData.shopOwnerKiller = false;
build_sword_animation(player, cam->renderer);

View File

@ -62,6 +62,10 @@ typedef struct PlayerEquipment {
bool hasArtifacts;
} PlayerEquipment;
typedef struct PlayerStateData {
bool shopOwnerKiller;
} PlayerStateData;
typedef struct Player {
Sprite *sprite;
Stats stats;
@ -78,6 +82,7 @@ typedef struct Player {
Timer *animationTimer;
Animation *swordAnimation;
PlayerEquipment equipment;
PlayerStateData stateData;
} Player;
Player*