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); sprite_render(item->sprite, cam);
LinkedList *subsprites = item->subsprites; LinkedList *subsprites = item->subsprites;
while (subsprites) while (subsprites != NULL) {
sprite_render(linkedlist_pop(&subsprites), cam); 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 void
@ -75,7 +80,7 @@ item_collected(Item *item, Player *player)
if (item->price) { if (item->price) {
player->gold -= item->price; player->gold -= item->price;
char costLabel[10]; 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); 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 *priceSprite = sprite_create();
sprite_load_text_texture(priceSprite, "GUI/SDS_8x8.ttf", 0, 8, 1); sprite_load_text_texture(priceSprite, "GUI/SDS_8x8.ttf", 0, 8, 1);
char priceLabel[10]; char priceLabel[10];
m_sprintf(priceLabel, 10, "%d", item->price); m_sprintf(priceLabel, 10, "$%.0f", item->price);
texture_load_from_text(priceSprite->textures[0], texture_load_from_text(priceSprite->textures[0],
priceLabel, priceLabel,
C_YELLOW, C_YELLOW,
C_BLACK, C_BLACK,
builder->renderer); builder->renderer);
priceSprite->pos = item->sprite->pos; priceSprite->dim = priceSprite->textures[0]->dim;
linkedlist_append(&item->subsprites, priceSprite); linkedlist_append(&item->subsprites, priceSprite);
return item; return item;
} }

View File

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

View File

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