| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "game/icon.h"
- const Icon *get_icon(char *name)
- {
- if (strcmp(name, "earth") == 0)
- {
- return &I_icon_earth;
- }
- if (strcmp(name, "home") == 0)
- {
- return &I_icon_home;
- }
- if (strcmp(name, "info") == 0)
- {
- return &I_icon_info;
- }
- if (strcmp(name, "man") == 0)
- {
- return &I_icon_man;
- }
- if (strcmp(name, "plant") == 0)
- {
- return &I_icon_plant;
- }
- if (strcmp(name, "tree") == 0)
- {
- return &I_icon_tree;
- }
- if (strcmp(name, "woman") == 0)
- {
- return &I_icon_woman;
- }
- return NULL;
- }
- // Icon entity description
- static void icon_collision(Entity *self, Entity *other, GameManager *manager, void *context)
- {
- UNUSED(manager);
- UNUSED(self);
- IconContext *icon = (IconContext *)context;
- UNUSED(icon);
- if (entity_description_get(other) == &player_desc)
- {
- PlayerContext *player = (PlayerContext *)entity_context_get(other);
- if (player)
- {
- Vector pos = entity_pos_get(other);
- // Bounce the player back by 3 units opposite their last movement direction
- pos.x -= player->dx * 3;
- pos.y -= player->dy * 3;
- entity_pos_set(other, pos);
- }
- }
- }
- static void icon_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
- {
- UNUSED(manager);
- IconContext *icon_ctx = (IconContext *)context;
- Vector pos = entity_pos_get(self);
- canvas_draw_icon(canvas, pos.x - camera_x - 8, pos.y - camera_y - 8, icon_ctx->icon);
- }
- static void icon_start(Entity *self, GameManager *manager, void *context)
- {
- UNUSED(manager);
- UNUSED(context);
- // Just add the collision rectangle for 16x16 icon
- entity_collider_add_rect(self, 16, 16);
- }
- const EntityDescription icon_desc = {
- .start = icon_start,
- .stop = NULL,
- .update = NULL,
- .render = icon_render,
- .collision = icon_collision,
- .event = NULL,
- .context_size = sizeof(IconContext),
- };
|