parent
486c1bb641
commit
959fae1730
|
@ -100,23 +100,45 @@ create_item(const char *path0, const char *path1, SDL_Rect clip, void (*cb)(Item
|
|||
return item;
|
||||
}
|
||||
|
||||
static Sprite *
|
||||
create_number_subsprite(SDL_Color fg,
|
||||
SDL_Color outline,
|
||||
const char *format,
|
||||
double value)
|
||||
{
|
||||
Sprite *sprite = sprite_create();
|
||||
sprite_load_text_texture(sprite, "GUI/SDS_8x8.ttf", 0, 8, 1);
|
||||
char priceLabel[10];
|
||||
m_sprintf(priceLabel, 10, format, value);
|
||||
texture_load_from_text(sprite->textures[0],
|
||||
priceLabel,
|
||||
fg,
|
||||
outline,
|
||||
builder->renderer);
|
||||
|
||||
sprite->dim = sprite->textures[0]->dim;
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
static Item *
|
||||
create_priced_item(double price, const char *path0, const char *path1, SDL_Rect clip, void (*cb)(Item *, Player*))
|
||||
create_priced_item(double price,
|
||||
const char *path0,
|
||||
const char *path1,
|
||||
SDL_Rect clip,
|
||||
void (*cb)(Item *, Player*))
|
||||
{
|
||||
Item *item = create_item(path0, path1, clip, cb);
|
||||
item->price = price;
|
||||
Sprite *priceSprite = sprite_create();
|
||||
sprite_load_text_texture(priceSprite, "GUI/SDS_8x8.ttf", 0, 8, 1);
|
||||
char priceLabel[10];
|
||||
m_sprintf(priceLabel, 10, "$%.0f", item->price);
|
||||
texture_load_from_text(priceSprite->textures[0],
|
||||
priceLabel,
|
||||
C_YELLOW,
|
||||
C_BLACK,
|
||||
builder->renderer);
|
||||
|
||||
priceSprite->dim = priceSprite->textures[0]->dim;
|
||||
Sprite *priceSprite = create_number_subsprite(C_YELLOW, C_BLACK, "$%.0f", item->price);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,3 +109,9 @@ position_to_tile_pos(const Position *p)
|
|||
p->y - (p->y % TILE_DIMENSION)
|
||||
};
|
||||
}
|
||||
|
||||
Position
|
||||
position_add(const Position *a, const Position *b)
|
||||
{
|
||||
return POS(a->x + b->x, a->y + b->y);
|
||||
}
|
||||
|
|
|
@ -71,4 +71,10 @@ position_in_roommatrix(const Position*);
|
|||
Position
|
||||
position_to_tile_pos(const Position*);
|
||||
|
||||
/*
|
||||
* Add two positions
|
||||
*/
|
||||
Position
|
||||
position_add(const Position*, const Position*);
|
||||
|
||||
#endif // POSITION_H_
|
||||
|
|
|
@ -30,7 +30,8 @@ sprite_create_default(void)
|
|||
s->textures[1] = NULL;
|
||||
s->clip = (SDL_Rect) { 0, 0, 0, 0 };
|
||||
s->destroyTextures = false;
|
||||
s->pos = (Position) { 0, 0 };
|
||||
s->pos = POS(0, 0);
|
||||
s->offset = POS(0, 0);
|
||||
s->dim = DEFAULT_DIMENSION;
|
||||
s->angle = 0;
|
||||
s->rotationPoint = (SDL_Point) { 0, 0 };
|
||||
|
@ -169,6 +170,8 @@ sprite_render(Sprite *s, Camera *cam)
|
|||
else
|
||||
cameraPos = s->pos;
|
||||
|
||||
cameraPos = position_add(&cameraPos, &s->offset);
|
||||
|
||||
SDL_Rect box = {
|
||||
cameraPos.x, cameraPos.y, s->dim.width, s->dim.height
|
||||
};
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef struct Sprite {
|
|||
SDL_Rect clip;
|
||||
bool destroyTextures;
|
||||
Position pos;
|
||||
Position offset;
|
||||
Dimension dim;
|
||||
double angle;
|
||||
SDL_Point rotationPoint;
|
||||
|
|
Loading…
Reference in New Issue